NoClassDefFoundError on Android

狂风中的少年 提交于 2021-02-07 23:37:12

问题


I have no idea what I am doing wrong.

I want to create a path variable in my Android project, but everytime I get a NoClassDefFoundError.

test = test + ".turns"; //This is a simple String
List<String> turnlist = new ArrayList<String>();
Path testfile = (Path) Paths.get(test);

Logcat:

05-13 19:08:51.996: E/AndroidRuntime(23437): FATAL EXCEPTION: Thread-1108
05-13 19:08:51.996: E/AndroidRuntime(23437): Process: com.example.voicerecorder, PID: 23437
05-13 19:08:51.996: E/AndroidRuntime(23437): java.lang.NoClassDefFoundError: java.nio.file.Paths
05-13 19:08:51.996: E/AndroidRuntime(23437): at com.example.voicerecorder.activities.RecordActivity$TestLoader.run(RecordActivity.java:201)

I have no idea what I am doing wrong.

EDIT

I will never again put my desktop jre into my android classpath! I will never again put my desktop jre into my android classpath! I will never again put my desktop jre into my android classpath! I will never again put my desktop jre into my android classpath! I will never again put my desktop jre into my android classpath! I will never again put my desktop jre into my android classpath! I will never again put my desktop jre into my android classpath! I will never again put my desktop jre into my android classpath! I will never again put my desktop jre into my android classpath! I will never again put my desktop jre into my android classpath!


回答1:


You're trying to use java.nio.file.Paths, which doesn't exist in Android as far as I can see. (Only some parts of the Java 7 API are supported.)

It's not clear what path you're looking for, or what you're going to do with the result, but consider using File.

Edit, now that we know a bit more: You should not put your desktop JRE jar files in the classpath for an Android project. That's just asking for trouble. Without doing that, you'd have correctly got a compile-time error.




回答2:


java.nio.file.Paths is part of the J7 API. Whereas Android (I believe) is built on J6. So, as such you'll be unable to use such classes. The File class is more than capable usually :)



来源:https://stackoverflow.com/questions/23638181/noclassdeffounderror-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!