maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Java setup (https://talk.maemo.org/showthread.php?t=25030)

dunff2k 2008-11-17 17:19

Java setup
 
Hey there!

I'm having a problem executing a java program on the tablet. I've following the guide on the maemo site, so installed cacao and the gnu classpath.

I have the following simple code

Code:

public class Main
{
        public static void main(String[] args) {
                System.out.println("Hello Jalimo");
        }
}

I compile this, transfer ONLY Main.class over to my device and find this in the filesystem. Then I tap:

Code:

cacao Main
then an exception is thrown without printing out the "hello jalimo":

Code:

Exception in thread "main" java.lang.NoClassDefFoundError:
Main (wrong name:test810.Main)
...

Anybody got any ideas what's up? where could this "wrong name" be? I can run the packaged jalimo-console-example fine so jalimo does work.

pixelseventy2 2008-11-17 19:35

Re: Java setup
 
what is the name of the class file you are executing? In java the class name must match the file name, ie a file with a class called Bob must be called Bob.class. Also, if you try and run "cacao folder/Main" it is going to look for a java class with the declaration "package folder" at the top.

shanti 2008-11-17 19:45

Re: Java setup
 
Hello. You need to point your classpath and then always write current folder:
for example, if I use glibj.jar, then
export CLASSPATH=/usr/share/classpath/glibj.zip:.
cacao -cp /usr/share/classpath/glibj.zip:. Main

dunff2k 2008-11-18 11:39

Re: Java setup
 
@pixelseventy2 - The name of the class file is Main.class so that matches the actual class name. The class is in the default package I guess (in that I didn't explicitly put it in one)

@shanti - Below is what I entered, the current directory /home/user/MyDocs/.documents is where the class file resides.

Code:

/home/user/MyDocs/.documents # export CLASSPATH=/home/user/MyDocs/.documents/Main.class:.

/home/user/MyDocs/.documents # cacao -cp /home/user/MyDocs/.documents/Main.class:. Main

...and I get the same result. Any other ideas what could be happening? is the path you mention significant?

hbr 2008-11-18 12:51

Re: Java setup
 
Hi dunff2k,

Did you by accident provide a line like
Quote:

package test810;
in the beginning of the java file? If yes, try to remove that line and re-compile. If the class is in a package, you would have to put the class file into a folder with the package name and call the file with
Quote:

cacao test810.Main
with you being in the folder holding the folder 'test810'.

Good luck,
Helmuth

dunff2k 2008-11-18 13:48

Re: Java setup
 
@hbr - You're right but in a new version of the class file I copied to the device that is no longer the case, yet the error still refers to test810.Main. The file executes fine from the command line on my windows machine using:

Code:

java Main
..when I am currently in the same directory as Main.class (no sign of test810). could there be some pointer somewhere still looking at this package?

So now I'm left wondering what this means
Code:

export CLASSPATH=/usr/share/classpath/glibj.zip:.
cacao -cp /usr/share/classpath/glibj.zip:. Main

What is glibj.zip? What does the classpath point to? and what directory should I be in to execute the cacao command.

Thanks for your patience with this...

shanti 2008-11-18 16:30

Re: Java setup
 
Quote:

Originally Posted by dunff2k (Post 242857)
What is glibj.zip? What does the classpath point to? and what directory should I be in to execute the cacao command.

I assumed, that you compiled (javac) in current directory. And run program in current directory. For example, you copy your Main.class in ~/myjava/Main.class. Then you make "cd ~/myjava/". Then you make:
export CLASSPATH=/usr/share/classpath/glibj.zip:.
cacao -cp /usr/share/classpath/glibj.zip:. Main

glibj.zip is package with classes, that are necessary for realtime running java program. In Sun's java or OpenJDK its rt.zip. In Jalimo installation, as I remember it must be glibj.zip. Have you this file?
Meanwhile, there is java compiler for Maemo. Try Google "maemo jikes"

dunff2k 2008-11-18 17:08

Re: Java setup
 
OK I seem to have got non GUI java apps working thanks for your input , I can only assume I had too many files of the same name hanging around and was confused.

Now I'm trying to get a GUI based one working as in the SimpleSwtSample on the jalimo site. And running the suggested code on the site gives me a problem.

Code:

cacao -cp /usr/share/java/swt-gtk.jar SimpleSwtSample
Where SimpleSwtSample is a class file in the current directory (along with one other that is generated). And swt-gtk.jar actually exists at the path suggested.

The error message I get is:

Code:

SimpleSwtSample not found in java.lang.classloader$1{urls=[file:/usr/share/java/swt-gtk.jar], parent = null}
Which makes sense because I didn't put that class file in swt-gtk.jar which I presume holds the GUI libraries?

Any ideas what it requires of me?

shanti 2008-11-18 19:57

Re: Java setup
 
It seems, you forgot one:
cacao -cp /usr/share/java/swt-gtk.jar:. SimpleSwtSample

You need always point your current dir in classpath- ":.".

dunff2k 2008-11-18 21:44

Re: Java setup
 
Hey thanks again for the response...

That advances things but upon selecting enter I'm greeted with lots of screens of the same error:

Code:

dumping the current stack trace.  We received a SIGSEGV and
tried to handle it but we were unable to find java method at PC=0x401020c8

with the final word being:

Code:

segmentation fault
ouch. Doesn't seem to much info on what this means, any ideas?

shanti 2008-11-18 23:43

Re: Java setup
 
Quote:

Originally Posted by dunff2k (Post 242958)
Doesn't seem to much info on what this means, any ideas?

Can you run Sample SWT Example from Jalimo site? You need to install that .deb from site (http://jalimo.evolvis.org/repository...le-install.php).

dunff2k 2008-11-19 08:25

Re: Java setup
 
yeah works fine

shanti 2008-11-20 11:28

Re: Java setup
 
Never saw that error. Can you type command line that you used and full stack trace?

dunff2k 2008-11-24 12:17

Re: Java setup
 
@shanti - The command I used was:

Code:

cacao -cp /usr/share/java/swt-gtk.jar:. SimpleSwtSample
I've explored this more and it seems the code does begin to execute, I know this by inserting print statements at strategic positions. However the segmentation error occurs after this line in the SimpleSwtSample:

Code:

final Shell shell = new Shell(display);
I should add the example compiles and runs fine on my windows PC. Also when I go Control Panel -> About product it says the os is: maemo based os2008 version 2.2007.51-3. Shouldn't this be 4.0 for chinook?

Anymore insight? I'm going to try on a different device...

dunff2k 2008-11-24 15:25

Re: Java setup
 
guys problem solved...

Once I updated my version of maemo through the nokia software updater all was resolved.

Thanks to all, special thanks @ shanti!

niv 2008-12-24 17:28

Re: Java setup
 
how may I compile my .java to .class on maemo?
is it jikes?
installing jalimo-console-example doesnt add the compiler to my device
Niv


All times are GMT. The time now is 22:04.

vBulletin® Version 3.8.8