I am using the ADT version 21 plugin for Eclipse, and I am programming for the Android 4.2 platform. I originally wrote a Java client-server application, and I want to use some of the classes that I wrote in it for an Android application that I am writing right now. I tried exporting the Java class files to a JAR file and putting the JAR file in the libs directory in my Android application, but when I tried to run the application on my Nexus 4, a NoClassDefFoundError is thrown. I searched SO for some answers and tried a few suggestions such as including the JAR file in the Order and Export tab in the Properties window (and putting it at the top of the list), but I'm stuck. Eclipse compiles my Android application fine, but I am unable to run my application on my device.
I know this question has been asked before, and several users have experienced this same issue. I welcome all suggestions. (I just started learning about Android application development.) Thanks!
EDIT: I just noticed these lines in the Console output. Any ideas?
[2012-11-24 01:26:26 - HomePage] Dx bad class file magic (cafebabe) or version (0033.0000)
...while parsing org/nihongo/common/db/Commands.class
...while processing org/nihongo/common/db/Commands.class
EDIT: I think it could be the fact that I am using Java 7 instead of Java 6. See here.
NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available during compile time.
This error is also generated when you make an app that uses the Google API (such as Maps) but run it on a device that targets the Android API.
I switched my compiler from Java 7 to Java 6 in the client-server application. I exported the class that I wanted to a JAR file, and I included it in my Android application, and it looks like it works now!
So I guess only Java 6 is supported even on Android 4.2.
Related
I'm trying to develop an app that uses Bluetooth technology, so I need javax.bluetooth & javax.obex & javax.microedition packages. I've downloaded it but I don't know how to properly place it and where so the Java can see it while compilation. How do I integrate it?
It depends on what tool you're using to create your jar. For example: Maven, Eclipse or IntelliJ. Usually you can find an answer that is relevant to your build method by simply googling it.
However, if you want to permenantly add them to your JDK, you'll have to paste them in your JDK's integrated jre into the following folder: \jre\lib\ext
For me that would be:
C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext
As you can see, I added RXTX (a serial comm library) to mine and I can now use it in my code.
I've built a simple java console app that prints "Hello World", and I'm trying to make it's .class/.jar bytecode run in an Android emulator (Nox). For that, I've transfered the .jar and .class files from the app to the emulator via Google Drive, and tried to use two java emulating Android apps so far: Java Manager and J2ME Loader.
In Java Manager, I got the following error while trying to run the .class file:
Failed to dexing Class
And in J2ME I got the following error while tring to run the .jar file:
Broken manifest
Does anyone has any idea of how to fix those errors in any of those two java emulators for Android? I'm not finding another app in Play Store.
Android can neither execute Java (J2SE class files) nor J2ME code. It has it's own format which bases on Java, however the compiler infrastructure is different from J2SE. There may be emulators allowing to execute J2SE or J2ME code, however I would not rely on such products as the support is usually incomplete.
Therefore you need the Android SDK (and/or the development IDE "Android Studio") for creating Android Apps.
When you have created an Android App (apk file) you can deploy and run it an and Android device or the emulator you have mentioned.
I have a code snippet that is part of my eclipse plugin. When testing it in a runtime eclipse version (That means it is not packed into a jar afaik) it runs just fine.
However if I pack my plugin into a jar and then run the respective code snippet it results in a complete crash of eclipse without any error logs (I'm assuming that it even crashes the JVM).
I'm running this on Linux Mint.
According to this post the Desktop API is broken in older Java versions but it should be fixed in Java 8.
Has anyone an idea why this is still happening?
Although this is not an answer to the question why the Desktop API breaks down when used inside a jar file, I want to point out an alternative that I have found (thanks to #Holger) for my case (working with the eclipse APIs):
You can simply use PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(<YourURL>); in order to open the given URL in the system's default browser.
I've my JavaFX app that calls some JNI code, uses a preloader jar and is compiled using jdk 1.7.
Now when I run jar on another computer with JRE7, by:
Double clicking jar: it starts but cannot load the JNI code containing libraries and therefore gets stuck.
Running jar via terminal using "java -jar ": App runs completely normal!
Now if I install jdk on this machine,
it runs fine even with double click!
Can somebody tell me what is difference in these 3 cases?
Try to add logging to your program, so that you can figure out why your JAR file doesn't execute properly.
You should look into if your manifest file is correct - there is a classpath in there you might want to take a look at.
This may have something to do with the fact that JavaFX is not fully released with Java 1.7, but included more as a developer preview.
Also, JavaFX packaging and deployment is a little different than standard Java. There is a new utility called 'javafxpackager' that should be used when packaging JavaFX applications. Check out the documentation here: http://docs.oracle.com/javafx/2/deployment/jfxpub-deployment.htm
I'm trying to write a simple java applet program, but it seems that I'm missing the javax.servlet.* class definitions.
Using:
apple snow
eclipse Java EE ide
Do I need to add a specific JAR file to my project and if so, which one?
I have Macports installed in case something from the ports might be helpful.
This is all result of misconceptions (Applets have nothing to do with the actual problem) and ignorance about Eclipse (if offers builtin ways to seamlessly integrate and link the one and the other, the Java EE variant has already a Tomcat plugin, you just have to integrate the server and associate it with the web project).
In the future you should be more precise and detailed about the problem (and thus not telling like "...it seems that..."). Post the relevant code snippet which caused the problem. Post the actual error message (with stacktrace, if any). Post the steps to accomplish to reproduce the problem. Also see: How To Ask Questions The Smart Way.
I've answered several times before how to get started with Eclipse+Tomcat+Servlets, you may find it useful as well:
Question about installing Java EE locally?
Tomcat servlet problem - class not found
CLASSPATH, Java Buld Path (eclipse), and WEB-INF\LIB : what to use, when, and why?
Thank for all of your helpful comments.
I installed tomcat 6 and it contains the missing jar in order to compile the project.
Nice plug-in to load tomcat applications :
Sysdeo Eclipse Tomcat Launcher plugin - http://www.eclipsetotale.com/tomcatPlugin.html
Using Netbeans i was able to properly compile tomcat applications just by creating a new java web application. for now i'll stick to netbeans, it also has a nice gui for connecting to the server and seeing the installed applications and their status.