3 Replies - 3087 Views - Last Post: 08 November 2010 - 06:43 PM Rate Topic: -----

#1 mvalor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 16-November 08

Java Application Random numbers w/Display

Posted 05 November 2010 - 08:50 PM

OK,
Here I am again that might be just another obvios answer to a question.
I am making a random number to display using JOption,

Here is my code:
/**
 *ITSE 2317 ASSIGNMENT# 2 PROJECT 1 PAGE 102
 * CREATING RANDOM NUMBERS
 * @author mvalor
 */
package randomnumber;


import java.util.Random;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;

public class Randomnumber {
  
public static void main(String[]args){

String input= JOptionPane.showInputDialog("Enter a number");
 Random generator = new Random();
int number = Integer.parseInt(input);
int randomNumber = generator.nextInt(number);

JOptionPane.showMessageDialog(null, "The Random number is: " +
            new DecimalFormat("0.#").format(randomNumber));

System.exit(0);
}//end main
}//end random




so far the errors show as follows:

run:
java.lang.NoClassDefFoundError: randomnumber/Main
Caused by: java.lang.ClassNotFoundException: randomnumber.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: randomnumber.Main. Program will exit.
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 6 seconds)


Can someone tell me what am I doing wrong? What am I missing? Do I have to make a new file in the poject?

Mike

Is This A Good Question/Topic? 0
  • +

Replies To: Java Application Random numbers w/Display

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4187
  • View blog
  • Posts: 11,847
  • Joined: 18-April 07

Re: Java Application Random numbers w/Display

Posted 05 November 2010 - 09:50 PM

There needs to be a space between "String[]" and "args". Because it sees them together without a space, it is not matching the exact definition of public static void main(String[] args) or public static void main(String args[]) if you prefer that version. It sees the two parts as one parameter and thinks that main is a different method signature. Since it is different it is saying "Hey, where is main, I can't find the version with String[] args... all I see is a method call main with what looks like a parameter called String[]args"

:)

This post has been edited by Martyr2: 05 November 2010 - 09:52 PM

Was This Post Helpful? 0
  • +
  • -

#3 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 971
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Java Application Random numbers w/Display

Posted 05 November 2010 - 10:03 PM

I don't think that matters. Testing:

public class LoopTest {
    public static void main(String[]args) {
    }
}



produces:

Quote

run:
BUILD SUCCESSFUL (total time: 0 seconds)


I'm more interested in the "java.lang.NoClassDefFoundError: randomnumber/Main". The posted code has "Randomnumber" as the class not "Main".
Was This Post Helpful? 0
  • +
  • -

#4 mvalor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 16-November 08

Re: Java Application Random numbers w/Display

Posted 08 November 2010 - 06:43 PM

You are right about the space. After fixing it it ran perfectly.
It pays to pay attention to detail.

Many thanks!

Mike
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1