Sign in to follow this  
Multiverse

midlet not launching in emulator

Recommended Posts

Multiverse    151
Hi there guys, I'm hoping somebody may have an answer for me here, I'm quite new to mobile development, so excuse any mistakes! I'm using Eclipse, J2ME polish, WTK2.2, and Ant to build my game's .jar and .jad files for multiple handsets. I have a J3D implementation and a 2D implementation of my game which I am hoping to build from the same source using Polish's handy preprocessor directives. I've got it all set up, and when I do a build and run within Eclipse, the midlet runs the 3D implementation with no problems (like it should do). When I try an Ant build it spews out the jars and jads (Generic/midp1, Generic/midp2, Generic/multi) with no errors. The problem is, when i try to execute one of the .jad files created with the Ant build, the emulator pops up, shows the name of my game and the 'launch' option (set to the right soft key.), but nothing happens when I press 'launch'. It just seems to hang there since it doesn't quit the emulator, it just stays on that screen. This happens with all three of the builds created (midp1, midp2, multi). Has anyone come across this before? Obviously I'm doing something wrong. Does it sound like a setup problem? Or maybe I've made a mistake with the preprocessor directives (I've done that before)? Anything that points me in the right direction would be great!

Share this post


Link to post
Share on other sites
Thygrrr    418
Does the path to jad & jar contain any spaces, umlauts or other non-alphanumeric characters? Is it on a network share or network volume?

This caused us a lot of strange problems with some emulators.

Share this post


Link to post
Share on other sites
Multiverse    151
hmmm, actually they do contain non alphanumeric characters. I'll just do a quick test to see if that sorts it out...

No that hasn't fixed it :(

its not on a network share/volume, its all coming from my PC, although the source code is checked out from a CVS, but since I've 'got' all the files on my computer, and these are the ones being built, I wouldn't have thought that would be an issue (although with my current experience with mobile games development, nothing can be ruled out!)

Oh, some more information, when I run one of the jars on a handset rather than in the emulator, it seems to try and start but then crashes/quits.

(I'm currently struggling with the debugger in Eclipse to try and work it out, its rather alien to me.)

Share this post


Link to post
Share on other sites
trojanman    394
Are you using any device/carrier specific APIs? That could be your problem.

Also, if you can create a bat file to run your builds from, or run it from the command line you can see the console output. The output will tell you if the build is just crashing on startup or not running at all.

Share this post


Link to post
Share on other sites
Hesterumpe    178
Can't really tell from your post if you have gotten something to work previously, but one problem I had when starting with midlets was that I made a main-loop like on a PC:

void run() {
while(true) {
// do stuff
// paint stuff
}
}

But in the midlet it should be (this is assuming you have made a new thread for your app, which seems to be the way to go)

void run() {
while(true) {
// do stuff
// paint stuff
Thread.sleep(50); // 50 or whatever...
}
}

I quess because the mobile doesn't have a proper thread scheduler, so you have to yield manually.

Share this post


Link to post
Share on other sites
Multiverse    151
Thanks for the reply Hesterumpe, I've set up my midlet with the thread sleep so i don't think thats the problem, but thanks anyway!

Well I think I've dug up a big clue which hopefully should allow you guys help me. :)

When I try running the Jar directly (by double clicking it), or the Jad from the command line, I get a different error for each case, but they look like their trying to tell me the same thing:

Double click the jar:
"Failed to load main class manifest attribute from C:\path_to_my_jar"

Run the Jad from cmd:
"Exception in thread "Main" Java.lang.noClassDefFoundError: Game/jad"

Ive had a (very quick) look around and it seems to me like I need to specify the main class in the jars manifest file. I also get the feeling this only has to be done for MIDP1? MIDP2 doesn't need to specify the main-class attribute?

I'm going to keep looking for info, but don't be shy if you've got a golden nugget of info!

(EDIT: at this point I'd just like to reiterate that if i build and run from withing Eclipse the game runs in the emulator fine. I can also create a package from within Eclipse and the resulting jar will run on a mobile device. The problems occur when I try to do an Ant build using J2ME Polish to create multpile jars for different handsets)

Share this post


Link to post
Share on other sites
Greig Hamilton    181
Why don't you use a compare tool to compare the working version with the non working version?

It looks like you have a file reference which is pointing to the wrong place, In you ant version you may be putting files in different places or changing the contents of the jad file.

Greig

Share this post


Link to post
Share on other sites
Sneftel    1788
Are you sure it's hanging? Have your midlet do a println in the very first line of the init function. It could just not ever be drawing.

Share this post


Link to post
Share on other sites
Multiverse    151
Sorry for not replying sooner, I've been working on other things recently.

Quote:

maybe you have a problem with MIDlet-1 in your manifest.mf file - the class name is wrong or something. maybe post the manifest.mf


I've checked my Manfest file, and everything seems ok from what I can gather. My Midlet-1 attribute looks ok to me. Maybe you can help my understanding of it though. As far as I know, the Midlet-1 (midlet-2 etc) attributes should be in the following format:

Midlet-1: GAME_NAME, ICON, MAIN_CLASS

I assume that is right? I also assume that the GAME_NAME variable doesn't have to be the exact same name as the .jar file?
Anyway, as you requested, here is my manifest file:


Manifest-Version: 1.0
MIDlet-Name: Pool Game
MIDlet-Version: 1.0.0
MIDlet-Vendor: Test Company
MIDlet-1: PoolGame,/pool.png,PoolMidlet
MIDlet-Delete-Confirm: Delete?
Main-Class: PoolMidlet
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-2.0
Polish-Version: 1.2.4



My class that 'extands Midlet' is PoolMidlet, as you can probably gather. The Main-Class attribute isn't automatically added to the manifest file when I run an Ant build, I add it manually afterwards (I've read previously that this is one solution to the problem) but it makes no difference.

Quote:

Why don't you use a compare tool to compare the working version with the non working version?


By 'compare tool' do you mean a source control program where you can check differences between older/different versions of the same files? If you are then I am already using one. The 'working version' and the 'not-working version' are using exactly the same code, except for the code that Polish weaves at compile time and (i think) is only put into effect once the java files are compiled into .class files, which I have no way of comparing to the original .java files to find out what code was included/excluded by Polish.
Besides that, I'm not sure it's a code problem, I'm a lot more inclined to beleive it is a set up problem.

Quote:

Have your midlet do a println in the very first line of the init function


That (unless I'm not understanding) won't be much help I'm afraid, since when I try to run the .jar/.jad there is no console available, and the error occurs before the emulator has even started.


Thanks for all your suggestions guys, its given me a bit of hope, but unfortunately nothing has fixed the problem yet. I'm pretty sure its either a problem with my manifest file (which I'll look into some more) or a setup problem, in which case I might re-install everything and set up from scratch. I didnt set the Eclipse/Ant/WTK up in the first place so I don't know how it was done (or how it should be done)

Has anyone got any more potential solutions? Especially with regard to the Main-Class attribute in the manifest file?

Share this post


Link to post
Share on other sites
Greig Hamilton    181
Quote:
By 'compare tool' do you mean a source control program where you can check differences between older/different versions of the same files?


Kindof. You can compare more than the java files. You can also compare the jad and manifest files to see what the differences are between the working and non working one is. There has to be a difference somewhere in you directory structure, jad file, manifest of java/class files. With acompare tool eg Beyond Compare you can compare the directory structure and the contents of all your files.

Hopefully this will give you an idea on where the problem is.

Greig

Share this post


Link to post
Share on other sites
werekarg    193
the manifest seems alright. one more question: is your midlet class in a package? if so, you must prefix the class name with the package name (eg mypackage.PoolMidlet)

you dont need the Main-Class attribute in the manifest - the device wont care about it [wink]

Quote:

Run the Jad from cmd:
"Exception in thread "Main" Java.lang.noClassDefFoundError: Game/jad"


what is the command line that threw you this error?

Share this post


Link to post
Share on other sites
Multiverse    151
Hi again everyone, once again i apologise for my lack of replies.

Werekarg, my midlet class isn't in a package, in Eclipse it jsut shows that its in the 'default package'. I did notice somewhere in Eclipse that 'using the default package is not recommended' or something to that effect.

Could this be the source of my problems do you think?

Share this post


Link to post
Share on other sites
werekarg    193
definitely not. eclipse just gives a hint, and from java point of view, it is advisable for all classes to be in packages. but packages and j2me are not a good combination, due to jar size problems that may appear. i ran midlets both in the default package and in a named package and encountered no problems.

regarding the error "Java.lang.noClassDefFoundError": are you, by any chance, trying to launch the jad as "java.exe game.jad" ?

Share this post


Link to post
Share on other sites
Multiverse    151
That error does occur when I try to launch the jad as "java.exe game.jad"

If i simple type in the name of the .jad file (i.e. game.jad) the emulator launches but when I try to select the game in the emulator it just hangs there and does nothing.

Share this post


Link to post
Share on other sites
werekarg    193
java.exe does not know about jads. launching the jad by simply typing the name in the command line (or doubleclicking) doesnt give you too much choice for options (the emulator will use default settings, sometimes not good for your midlet).

you should try to launch the jad with the emulator using:

emulator.exe -descriptor game.jad -deviceFile blabla.props -Xheapsize:4M

deviceFile - you should have some *.props or *.properties files where your emulator is installed; if you're using the sun wtk emulator, you should use -Xdevice:devicename, and as "devicename" pass a device found in wtklib\devices

descriptor - if you're using sun wtk, you should use -Xdescriptor instead

make sure the jad and jar are in the same folder, make sure that in jad MIDlet-Jar-URL is correct.

hope this helps.

Share this post


Link to post
Share on other sites
Multiverse    151
First of all thanks for all the hints werekarg, i'll be sure to try them all out. Obviously I've been attacking this problem completely wrong. I've had a quick try with your helpful hints, and I'm getting some helpful output in the command window, so hopefully I can sort them out and get up and running properly! :P
(if your interested, i get the error "NullPointerException at com.sun.cldc.i18n.Helper.getStreamReader". which seems like thats been my problem all along. now i know the problem, I can start finding the solution!)

Isiahil, simply go to Project -> Build All (or press ctrl+b)

This will compile yor project. There may be some errors (look for a 'problems' tab at the bottom.) Make sure you get rid of all the errors before you try to run it (warnings don't matter so much, but its better not to have any)

[Edited by - Multiverse on April 3, 2006 4:42:44 AM]

Share this post


Link to post
Share on other sites
scorpN    122
Hi Multiverse

I had the exact same problem as you. I found the error to be that J2ME polish really does not like it if you yourself extend any of the J2ME GUI components directly and then attempt to build it with polish. My emulators/devices always crashed at startup whenever I had any classes that extended any of the J2ME base GUI components (e.g. Form, List etc.)

I solved this problem by removing all classes in my source that directly extended a J2ME GUI component and instead rather just wrapped my classes around the base GUI components to get the same functionality.

This made J2ME polish happy and the emulators/devices were able to run my app.

Hope this helps you!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this