Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6564357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:57:23+00:00 2026-05-25T13:57:23+00:00

I have just started learning java, and know only a small amount of code,

  • 0

I have just started learning java, and know only a small amount of code, however this is still a simple program. It is more of a prank program, but mostly just to test if I can make a jar file.

Here is the code:

import java.awt.*;  
import java.awt.event.*;  
import java.lang.*;  
import java.util.Random;  
public class randommouse {  
    public static void main(String[] args) {  
        for (int i=1; i<1000; i++) {  
            Random rand = new Random();  
            int w = rand.nextInt(1024) + 1;  
            int h = rand.nextInt(768) + 1;  
            int t = rand.nextInt(2000) + 1;  
            try {  
                Robot r = new Robot();  
                r.mouseMove(w,h);  
                Thread.sleep(t);  
            } catch (AWTException e) {}  
            catch (InterruptedException e) {}  
            catch (NullPointerException e) {}  
        }  
    }  
}  

I save this to file called randommouse.java,
then compile it using

javac randommouse.java  

This works and when I run it using

java randommouse 

it works fine also.

So then I try to create a jar file. I use the command

jar cvf randommouse.jar randommouse.class 

and it works. Afterwards I double click the jar file and it comes up with an error Java Exception.
So then I run it in the cmd with

java -jar randommouse.jar

and get this error

F:\Java>java -jar randommouse.jar
Exception in thread "main" java.lang.NullPointerException
        at sun.launcher.LauncherHelper.getMainClassFromJar(LauncherHelper.java:3
99)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:463)

F:\Java>

Do I need to put in an argument, and if so where do I put that in and how?

Thank you in advance
Sam

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:57:24+00:00Added an answer on May 25, 2026 at 1:57 pm

    From the JDK doc:

    In order for this option to work, the manifest of the JAR file must
    contain a line of the form

    Main-Class: classname
    

    Here, classname
    identifies the class having the public static void main(String[] args)
    method that serves as your application’s starting point. See the Jar
    tool reference page and the Jar trail of the Java Tutorial for
    information about working with Jar files and Jar-file manifests.

    When you use this option, the JAR file is the source of all user
    classes, and other user class path settings are ignored.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, this is my code (just started learning java): Queue<String> qe =
G'Day Programmers, I am from Java background however I have just started learning C++
i just started learning swings. And thought of trying out a simple program, but
I have just started learning java and i have about 8 months time. My
I just recently started learning Java. I have a question which is more about
I've only started learning Java about 3 months ago and this is my first
I am just starting out learning Java, GAE etc. I have started a project
I've just started learning Java and have come across a little quirk I'm not
I have just started learning Android and thought of a simple project to help
Java script has many falsy values as I started learning. I have a program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.