java.lang.NoClassDefFoundError: javax/microedition/io/Connector
mstocum
Posts: 120
Okay, I'm sure I'm doing something silly here. I'm trying to do some simple HTTP GET requests using docs from http://docs.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/io/HttpConnection.html as an example. Everything compiles cleanly, but when I actually go to try to grab a URL, I'm getting java.lang.NoClassDefFoundError: javax/microedition/io/Connector on the console. I'm guessing I need do something special to make the javax.microedition classes visible to the module, but I have zero clue what that is. Anyone out there able to provide any insights?
Thanks.
Thanks.
0
Comments
Is AMX really selling a development platform in 2014 which doesn't have native support for HTTP?
Check this post ( http://www.amxforums.com/showthread.php?7060-AMXTools&p=53652#post53652 ) for some AMX code that does most of the easy stuff already.
But in my experience that doesn't mean you can actually get it to work..
(Which tells you how long ago I gave up on duet)
I guess what I really want to know is if there is any way to do actual HTTP calls in AMX.
ETA I am using 4.x firmware.
I don't suppose you could point to any directions to walk a newb through setting up the project to use the new jars? I've also been poking at apache commons httpclient (the old 3.x branch, since the 4.x branch seems to require some stuff that Eclipse can't find), but no matter what I do, when I add the JAR, Eclipse won't include it in the bundle. I'm sure I'm doing something wrong there too.
To actually use the 4.x.x Java classes is a pain in the butt. You have to get the "Master-v4_x_x_jar_files.zip" from Hotfix firmware on ActiveEcho. Then you have to manually replace all the jar files in your Java build path and manually rebuild your Duet Manifest file (probably the hardest part of the process).
You might want to try taking your Master back to 3.x firmware and see if it runs, because I don't think that package is available on the Master running 4.x because 4.x Java is based on Standard Edition, not Micro Edition.
and then inside my service routine I do something like this:
The copy() routine is my own, and basically just does a thread safe copy.
After you create a new project, right click on the project in the Package Explorer, select Properties from the menu, then Java Build Path in the dialog, and then the Libraries Tab. Remove the jars in the 3.x.x column and add the ones in the 4.x.x column. Then you have to manually edit your "manifest.duetmf" file with at least the following sections. More import packages and file dependencies maybe required depending on the packages you are using.
Import-Package:
File-Dependencies:
I need to request that zip file from AMX Tech Support though, correct?
Thanks everyone for all of your help.
I have had a lot of trouble getting jars into Duet module jars, I always have to play with it to get it to work. I have never found a good way to do it. You might try adding it as a File Dependency in the duet Manifest File, but that won't make it part of the Duet Jar, when you go to load the System from Netlinx Studio it will ask you for the location of that Jar file.
Thanks, I was able to get something working based off of your code. I should at least be able to do what I need to do with that.
Now to figure out how to include a 3rd party JAR in my project and have it actually work...
Also, if you're wanting a simple way to do HTTP with current firmware have a look inside the RMS SDK, you'll find a nicely packed up Apache commons HTTP library and its associated dependancies.
Well that's a clever idea...
I can get it to work by adding all of the org.apache.commons packages to the Import Packages section of the manifest.duetmf, but looking in the RmsNetLinx adapter JAR, it's not doing that. It mentions several org.apache.commons.lang packages, but nothing about httpclient. Is there an easier way to do this other than the boil the ocean approach I'm taking?
Boil away.
You can use HTTPUrlConnection for this, this comes with duet.
However I have moved to using apache http core library... More stable!
http://hc.apache.org/httpcomponents-core-ga/
Does version 4.x work on Duet? I've been able to get the 3.1 version packaged with RMS to work.
Yes, I am currently using 4.3. Only the "core" library works though on jdk1.4.
Question the 999th. What is the proper way to create a JAR of your own code? I tried following your advice in the linked thread, but it's not generating the Export-Package: line, and I don't quite want to try generating it by hand. I think the lack of that line is keeping the Duet Manifest editor from seeing the contents of the JAR in the import packages section.
NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available at compile time. After you compile your code, you end up with .class files for each class in your program. These binary files are the bytecode that Java interprets to execute your program. The NoClassDefFoundError indicates that the classloader (in this case java.net.URLClassLoader), which is responsible for dynamically loading classes, cannot find the .class file for the class that you’re trying to use.
NoClassDefFoundError can occur for multiple reasons like