线程“main”中的异常 java.lang.NoClassDefFoundError: junit/textui/ResultPrinter After update to Yosemite
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27890011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter After updating to Yosemite
提问by Darxval
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
我最近将我的系统从 Mavericks (OSX) 更新到了 Yosemite。我曾经能够右键单击测试并运行它。现在我得到了例外
/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.run(URLClassLoader.java:366)
at java.net.URLClassLoader.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
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.
这也可能与当我点击 Dock 中打开的 Android Studio 图标时出现错误 no JVM was found 但我可以通过终端打开它没问题。
This is the same as a brand new android studio project with the default applicationTest trying to run.
这与尝试运行默认 applicationTest 的全新 android studio 项目相同。
回答by Darxval
So two things
所以两件事
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 hereas Android requires java 1.6 and not java 1.6+.
首先,如果您尝试在 Yosemite 升级时打开 Android Studio 并显示“未找到 JVM”,您需要在此处为 osx 安装 java 6,因为 Android 需要 java 1.6 而不是 java 1.6+。
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.
其次,我发现的异常是因为它试图运行 JUnit,就好像我想通过 Java 标准控制台而不是通过 Android 运行一样。
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.
不要使用包含黑色带箭头的 Java 测试,使用 Android 测试中的单元测试并删除 JUnit 配置的所有使用。
Your configuration should look like this, then you can right click on single tests and run them like normal.
您的配置应该如下所示,然后您可以右键单击单个测试并像平常一样运行它们。
回答by Nimrod Dayan
As of the release of Android Studio 1.1.0 (on Feb 18 2015), it is now possible to run standard JUnit tests in Android Studio on local JVM for as long as the code under test isn't calling Android API. Please follow the instructions in this guidefor more info.
随着 Android Studio 1.1.0 的发布(2015 年 2 月 18 日),现在可以在本地 JVM 上的 Android Studio 中运行标准 JUnit 测试,只要被测代码不调用 Android API。请按照本指南中的说明获取更多信息。