开发者

Error in executing

I am interested in sending tweets using Java program.I wrote the following prgram.It doen't show any error in compiling.But while executing it shows

"Exception in thread "main" java.lang.NoClassDefFoundError: hi
Caused by: j开发者_JAVA技巧ava.lang.ClassNotFoundException: hi
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: hi.  Program will exit."

This is my code..

package twitter;
//import java.lang.object;
import net.unto.twitter.*;
import net.unto.twitter.TwitterProtos.Status;
public class hi
{
  public static void main(String args[])
  {

    Api api = Api.builder().username("usename").password("password").build();
    api.updateStatus("This is a test message.").build().post();

  }
}

Can anybody help me ..Pls


Class named hi is within the package twitter.

Include the package name while executing the class.

Try this :

java -cp .:hello_twitter/java-twitter.jar twitter.hi


This error shows that you didn't start the application correctly. Could be a typical classpath problem, because you need a java library plus your own clode. Try this on a console/terminal:

(1) navigate to the root folder of you application (./twitter/hi.class should be a valid file from your actual path)

(2) execute the application with:

java -cp .;path/to/twitter/lib/twitterlib.jar twitter.hi

(replace path/to/twitter/lib/twitterlib.jar with the real path and lib name)


So, back to the basics:

You have class named twitter.hi, which needs to be stored in the file ./twitter/hi.java.

Then you must compile the java file to a file ./twitter/hi.class

When this is done, run the application with

java -cp .:hello_twitter/java-twitter.jar twitter.hi
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜