java.lang.NoClassDefFoundError: javax/microedition/io/Connector
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:
try { FileToGet = new URL("http://example.com/file.txt"); URLConnection urlC = FileToGet.openConnection(); InputStream webInputStream = urlC.getInputStream(); FileOutputStream fileOutputStream = new FileOutputStream("/user/file.txt"); copy(webInputStream, fileOutputStream); webInputStream.close(); fileOutputStream.close(); } catch (MalformedURLException eURLProblem) { // TODO Malformed URL catch block }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...
Line 219 (21:20:37.109):: Loading 1 Duet Modules. Line 220 (21:20:40.026):: Device Access: DA.processNewDevice: {Device-Revision=1.0.0, Device-Category=other, Device-Make=LeBow, Physical-Device=0:0:0, objectClass=[Ljava.lang.String;@27620b, Device-SDKClass=com.amx.duet.devicesdk.Utility, Bundle-Version=1.0.0, Device-Model=HTTPTest Line 221 (21:20:40.026):: , Duet-Device=41000:1:0, service.id=10, Duet-Module=HTTPTest_dr1_0_0} Line 222 (21:20:40.073):: Device Access: loadDrivers: searching for 1 drivers Line 223 (21:20:40.073):: Device Access: isDriverActive: checking for active driver - /bundle/HTTPTest_dr1_0_0 Line 224 (21:20:40.073):: Device Access: isDriverActive: driver not active - /bundle/HTTPTest_dr1_0_0 Line 225 (21:20:40.307):: DA: installing dependency: file:doc:/bundle/commons-logging-1.1.1-AMX-01.jar Line 226 (21:20:43.006):: doc:/bundle/commons-logging-1.1.1-AMX-01.jar: dependency bundle matches flash file manifest Line 227 (21:20:43.006):: DA: installing dependency: file:doc:/bundle/commons-lang-2.5-AMX-01.jar Line 228 (21:20:46.485):: doc:/bundle/commons-lang-2.5-AMX-01.jar: dependency bundle matches flash file manifest Line 229 (21:20:46.485):: DA: installing dependency: file:doc:/bundle/commons-codec-1.4-AMX-01.jar Line 230 (21:20:49.309):: doc:/bundle/commons-codec-1.4-AMX-01.jar: dependency bundle matches flash file manifest Line 231 (21:20:49.309):: DA: installing dependency: file:doc:/bundle/commons-httpclient-3.1-AMX-01.jar Line 232 (21:20:50.557):: Memory Available = 10037384 <12336> Line 233 (21:20:52.803):: doc:/bundle/commons-httpclient-3.1-AMX-01.jar: dependency bundle matches flash file manifest Line 234 (21:20:55.346):: Device Access: DeviceAccess.loadDrivers - installing bundle for /bundle/HTTPTest_dr1_0_0 Line 235 (21:20:58.466):: /bundle/HTTPTest_dr1_0_0: bundle matches flash file manifest Line 236 (21:20:58.466):: Device Access: DeviceAccess.loadDrivers - starting bundle for /bundle/HTTPTest_dr1_0_0 Line 237 (21:21:01.025):: Device Access: DA.processNewDevice: {Device-Revision=1.0.0, Device-Category=other, Device-Make=LeBow, Duet-Model=HTTPTest, Physical-Device=0:0:0, Device-Service=com.amx.duet.routers.snapi.ISNAPIRouter, Device-SDKClass=com.amx.duet.devicesdk.Utility, object Line 238 (21:21:01.025):: Class=[Ljava.lang.String;@2925c0, Duet-Make=LeBow, Device-Channels=255, Bundle-Version=1.0.0, Device-Model=HTTPTest, Device-Levels=8, Duet-Revision=1.0.0, Duet-Device=41000:1:0, service.id=12} Line 239 (21:21:01.025):: Device Access: loadDrivers: searching for 1 drivers Line 240 (21:21:01.025):: Device Access: isDriverActive: checking for active driver - /lib/jars/duet/snapirouter Line 241 (21:21:01.040):: Device Access: isDriverActive: driver not active - /lib/jars/duet/snapirouter Line 242 (21:21:01.134):: Device Access: DeviceAccess.loadDrivers - installing bundle for /lib/jars/duet/snapirouter Line 243 (21:21:01.274):: /lib/jars/duet/snapirouter: bundle matches flash file manifest Line 244 (21:21:01.274):: Device Access: DeviceAccess.loadDrivers - starting bundle for /lib/jars/duet/snapirouter Line 245 (21:21:02.007):: SNAPIRouter: UtilityComponent loaded Line 246 (21:21:02.117):: SNAPIRouter: ModuleComponent loaded Line 247 (21:21:02.366):: CIpEvent::OnLine 41000:1:1 Line 248 (21:21:46.890):: ICSPTCPRx0: Duplicate messageID received Sys=1 Dev=32001 MsgID=286E Line 249 (21:21:54.237):: REINIT Called Line 250 (21:21:54.237):: java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpClient Line 251 (21:21:54.237):: $09at com.lebow.httptest.dr1_0_0.LebowHttptest.getViaCommons (LebowHttptest.java:95) Line 252 (21:21:54.237):: $09at com.lebow.httptest.dr1_0_0.LebowHttptest.reinitialize (LebowHttptest.java:70) Line 253 (21:21:54.237):: $09at com.amx.duet.routers.snapi.component.ModuleComponent.OnHandleDataEvent (Unknown Source, bco=568) Line 254 (21:21:54.237):: $09at com.amx.duet.routers.snapi.SNAPIRouter.OnHandleDataEvent (Unknown Source, bco=22) Line 255 (21:21:54.237):: $09at com.amx.duet.routers.snapi.SNAPIRouter.handleDataEvent (Unknown Source, bco=7) Line 256 (21:21:54.237):: $09at com.amx.duet.core.master.IcspNetLinxDevice.handleDataEvent (Unknown Source, bco=40) Line 257 (21:21:54.237):: $09at com.amx.duet.core.master.EventRouter.processEvent (Unknown Source, bco=772) Line 258 (21:21:54.237):: $09at com.amx.duet.core.master.EventRouter.run (Unknown Source, bco=1406) Line 259 (21:21:54.237):: $09at java.lang.Thread.run (Unknown Source, bco=16)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