Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoClassDefFoundError on Android

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!

like image 742
PKlumpp Avatar asked May 13 '14 17:05

PKlumpp


People also ask

How do I overcome Java Lang NoClassDefFoundError?

You can fix NoClassDefFoundError error by checking following: Check the exception stack trace to know exactly which class throw the error and which is the class not found by java.

Can we handle NoClassDefFoundError?

It is thrown by the Java Runtime System when the class definition is not found at run time. Developers can handle an exception using a try and catch block or any other method for preventing the program from crashing. The program will crash whenever NoClassDefFoundError will occur.

What causes NoClassDefFoundError?

NoClassDefFoundError is a common error in Java that occurs if a ClassLoader cannot find a particular class in the classpath while trying to load it. The Exception in thread "main" suggests that this error has occurred in the main thread, the thread which is responsible for running the Java application.


2 Answers

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.

like image 124
Jon Skeet Avatar answered Oct 14 '22 15:10

Jon Skeet


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 :)

like image 1
fantasitcalbeast Avatar answered Oct 14 '22 16:10

fantasitcalbeast