本文介绍了线程“main"中的异常java.lang.NoClassDefFoundError: junit/textui/ResultPrinter 更新到 Yosemite 后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将我的系统从 Mavericks (OSX) 更新到了 Yosemite.我曾经能够右键单击测试并运行它.现在我得到了例外

I recently updated my system from Mavericks (OSX) to Yosemite. I use to be able to right click on a test and run it. Now I get the exception

/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin/java -ea -Didea.launcher.port=7541 "-Didea.launcher.bin.path=/Applications/Android Studio.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/Android Studio.app/Contents/lib/idea_rt.jar:/Applications/Android Studio.app/Contents/plugins/junit/lib/junit-rt.jar:/Users/michael.cameron/Code/Android/sdk/platforms/android-21/android.jar:/Users/michael.cameron/Code/Android/sdk/platforms/android-21/data/res:/Users/michael.cameron/Code/Android/darxstudios/TheChefsCodex/app/build/intermediates/classes/debug:/Users/michael.cameron/Code/Android/darxstudios/TheChefsCodex/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.3/classes.jar:/Users/michael.cameron/Code/Android/darxstudios/TheChefsCodex/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.3/res:/Users/michael.cameron/Code/Android/darxstudios/TheChefsCodex/app/libs/ParseCrashReporting-1.8.0.jar:/Users/michael.cameron/Code/Android/sdk/extras/android/m2repository/com/android/support/support-annotations/21.0.3/support-annotations-21.0.3.jar:/Users/michael.cameron/Code/Android/darxstudios/TheChefsCodex/app/build/intermediates/exploded-aar/com.android.support/support-v4/21.0.3/res:/Users/michael.cameron/Code/Android/darxstudios/TheChefsCodex/app/build/intermediates/exploded-aar/com.android.support/support-v4/21.0.3/classes.jar:/Users/michael.cameron/Code/Android/darxstudios/TheChefsCodex/app/build/intermediates/exploded-aar/com.android.support/support-v4/21.0.3/libs/internal_impl-21.0.3.jar:/Users/michael.cameron/Code/Android/darxstudios/TheChefsCodex/app/libs/Parse-1.8.0.jar:/Users/michael.cameron/.gradle/caches/modules-2/files-2.1/com.parse.bolts/bolts-android/1.1.4/129874135e6081269ace2312092031558865de12/bolts-android-1.1.4.jar:/Users/michael.cameron/Code/Android/darxstudios/TheChefsCodex/app/libs/bolts-android-1.1.4.jar" com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 com.darxstudios.thechefscodex.ApplicationTest
Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:191)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)
Caused by: java.lang.ClassNotFoundException: junit.textui.ResultPrinter
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 3 more

这也可能与当我点击 Dock 中打开的 Android Studio 图标时出现错误 no JVM was found 但我可以通过终端打开它没问题.

it may also be related to when i tap the open Android Studio icon in my Dock i get the error no JVM was found but i can open it via Terminal no problem.

这与一个全新的 android studio 项目相同,默认 applicationTest 尝试运行.

This is the same as a brand new android studio project with the default applicationTest trying to run.

推荐答案

那么两件事

首先,如果您尝试在 Yosemite 升级时打开 Android Studio 并显示未找到 JVM",则您需要为 osx 安装 java 6 此处 因为 Android 需要 java 1.6 而不是 java 1.6+.

First, if you try to open Android Studio on Yosemite upgrade and it says "No JVM found" you need to install the java 6 for osx here as Android requires java 1.6 and not java 1.6+.

第二,我发现的异常是因为它试图运行 JUnit,就好像我想通过 Java 标准控制台而不是通过 Android 运行一样.

Second, The Exception I found was caused because it was trying to run JUnit as if I wanted to run through java standard console instead of with Android.

不要使用带有黑色箭头的 Java 测试,使用 Android 测试中的单元测试并删除 JUnit 配置的所有用途.

Do not use the Java test that contains a black with arrows, use the unit tests within a Android Tests and delete all uses of the JUnit configuration.

您的配置应该如下所示,然后您可以右键单击单个测试并像平常一样运行它们.

Your configuration should look like this, then you can right click on single tests and run them like normal.

这篇关于线程“main"中的异常java.lang.NoClassDefFoundError: junit/textui/ResultPrinter 更新到 Yosemite 后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 06:25