Why i can not run HelloJava as an application?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Why i can not run HelloJava as an application?

chenmgm
I copyed the code from http://pivot.apache.org/tutorials/hello-world.html to my eclipse

But i could not run it successfully as an application

And the console show me:

java.lang.ClassNotFoundException: org/apache/pivot/tutorials/HelloJava
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.apache.pivot.wtk.DesktopApplicationContext.main(DesktopApplicationContext.java:601)
        at org.apache.pivot.wtk.DesktopApplicationContext.main(DesktopApplicationContext.java:870)
        at org.apache.pivot.tutorials.HelloJava.main(HelloJava.java:56)

my code is:

package org.apache.pivot.tutorials;
 
import java.awt.Color;
import java.awt.Font;
 
import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.Application;
import org.apache.pivot.wtk.DesktopApplicationContext;
import org.apache.pivot.wtk.Display;
import org.apache.pivot.wtk.HorizontalAlignment;
import org.apache.pivot.wtk.Label;
import org.apache.pivot.wtk.VerticalAlignment;
import org.apache.pivot.wtk.Window;
 
public class HelloJava implements Application {
    private Window window = null;
 
    @Override
    public void startup(Display display, Map<String, String> properties) {
        window = new Window();
 
        Label label = new Label();
        label.setText("Hello World!");
        label.getStyles().put("font", new Font("Arial", Font.BOLD, 24));
        label.getStyles().put("color", Color.RED);
        label.getStyles().put("horizontalAlignment",
            HorizontalAlignment.CENTER);
        label.getStyles().put("verticalAlignment",
            VerticalAlignment.CENTER);
 
        window.setContent(label);
        window.setTitle("Hello World!");
        window.setMaximized(true);
 
        window.open(display);
    }
 
    @Override
    public boolean shutdown(boolean optional) {
        if (window != null) {
            window.close();
        }
 
        return false;
    }
 
    @Override
    public void suspend() {
    }
 
    @Override
    public void resume() {
    }
   
    public static void main(String[] args) {
        DesktopApplicationContext.main(HelloJava.class, args);
    }
}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Why i can not run HelloJava as an application?

Roger and Beth Whitcomb
What directory was the code in?  Java conventions require the path to the class file to match the package designation (org.apache.pivot.tutorials). And you would need "." in your CLASSPATH too.

~Roger Whitcomb
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Why i can not run HelloJava as an application?

chenmgm
I think the code was in right place



“And you would need "." in your CLASSPATH too. ”

What "." and What CLASSPATH?

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Why i can not run HelloJava as an application?

Roger Whitcomb-2
Okay, I see.  You will need to make hierarchy of directories, like this:
src
+-----org
        +-----apache
                +-----pivot
                        +-----tutorials

And put your code there.  Then in the command window where you are compiling a building your application, you would need to do:
> javac org\apache\pivot\tutorials\HelloJava.java
> java org.apache.pivot.tutorials.HelloJava

And hopefully you have set your CLASSPATH environment variable to point to the Pivot .jar files ....  From your screenshot, you probably would need to do something like this (just one time when you open the command window) (and I'm assuming this is Windows -- slightly different instructions apply for Linux or OSX):
> set CLASSPATH=.;\test\pivot202\lib\pivot-core-2.0.2.jar;\test\pivot202\lib\pivot-wtk-2.0.2.jar;\test\pivot202\lib\pivot-wtk-terra-2.0.2.jar

HTH,
~Roger Whitcomb


-----Original Message-----
From: chenmgm [mailto:[hidden email]]
Sent: Saturday, June 15, 2013 4:22 PM
To: [hidden email]
Subject: Re: Why i can not run HelloJava as an application?

I think the code was in right place

<http://apache-pivot-users.399431.n3.nabble.com/file/n4022619/QQ%E6%88%AA%E5%9B%BE20130616071556.jpg>

“And you would need "." in your CLASSPATH too. ”

What "." and What CLASSPATH?





--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Why-i-can-not-run-HelloJava-as-an-application-tp4022617p4022619.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
Loading...