1

did you change the Class name from the file to the new class name?

where it says

public class Try1 {

replace it with

public class NewClassNameHere {

you wrote in the class name when you made the class (if you are using netbeans or eclipse) or it is the name of the file (if you are using notepad, or another text editor)

if that doesn't fix it send me the code. maybe you have a small error that is correct, except misused.

Edited by sirlink99: n/a

0

i made sure i change the package and the class name to the file..

package Surprise;
 
 
import javax.swing.JOptionPane; 


public class Surprise {
 
    public static void main(String[] args){
        String[] messages = {"message1","mesage2","messag3","mesage4", "message5", "message6", "message7", 
        "message8", "message9","message10","message11"}; // stores messages
        JOptionPane.showMessageDialog(null,messages[getRandomIndex(messages.length)]); // prints out one of the messages
        System.exit(0);        
    }
    public static int getRandomIndex(int max){	// gets which message to print out
    	int messagePrintNumber = (int)(max*Math.random()); // generates a random number in the array
 
    	System.out.println("Messages " + (messagePrintNumber + 1)); // tells you which message it is printing. the +1 is to account for the array beginning at 0
 
    	return messagePrintNumber; // returns which message it should print out
    }
}

thank you soooo much..i really appreciate your help..

0

did that fix your error?

Also what would you like the application to look like (GUI)?

Edited by sirlink99: n/a

0

no it didn't..it still won't open the application...

i was thinking dark red background with white text and i wanted a different text?? is that what you'r asking??

0

It is. I don't know what you did. It works for me.

Make sure your class and package names are exact. Java is case sensitive.

0

its working fine in netbeans..when i run the project...it shows the message..but the Surprise.jar file is not working...i emailed myself the Surprise.jar file and opened it in a different computer...and it didn't open...i wanted to see how it would open up from his side..

0

I changed the look and feel to numbus. It has the least amount of sharp edges. I have changed the color of the text to white, the background to red, and the button to a purple. See if you like it. If not then change the colors

package Surprise;
 
 
import java.awt.Color; // needed to set the color
import javax.swing.JOptionPane; // needed to display the frame
import javax.swing.UIManager; // needed for look and feel
import javax.swing.UIManager.LookAndFeelInfo;// needed for look and feel


public class Surprise {
 
    public static void main(String[] args){
    	UIManager.put("control", Color.red); // changes background
    	UIManager.put("text", Color.white); // changes text
    	UIManager.put("nimbusBase", new Color (9445584)); // changes button
    	try { // attempts to set the look and feel
    	    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
    	        if ("Nimbus".equals(info.getName())) {
    	            UIManager.setLookAndFeel(info.getClassName()); // sets look and feel
    	            break;
    	        }
    	    }
    	} catch (Exception e) {
    	    // If Nimbus is not available, you can set the GUI to another look and feel.
    	}
        String[] messages = {"message1","mesage2","messag3","mesage4", "message5", "message6", "message7", 
        "message8", "message9","message10","message11"}; // stores messages
        JOptionPane.showMessageDialog(null,messages[getRandomIndex(messages.length)]); // prints out one of the messages
        System.exit(0);        
    }
    public static int getRandomIndex(int max){	// gets which message to print out
    	int messagePrintNumber = (int)(max*Math.random()); // generates a random number in the array
 
    	System.out.println("Messages " + (messagePrintNumber + 1)); // tells you which message it is printing. the +1 is to account for the array beginning at 0
 
    	return messagePrintNumber; // returns which message it should print out
    }
}

did you use the default exportation method of netbeans, or a third party program?

for eclipse it is file > export > Runnable Jar

I exported it and it works fine

Edited by sirlink99: n/a

0

actually none of the .jar file is working on my laptop...everything was working fine last night..i dont know what happened..

0
UIManager.put("nimbusBase", new Color (9445584));

is this statement referred to the "i" button??

and i ran the program again...and thats what i got


java.lang.NoClassDefFoundError: surprise/Surprise (wrong name: Surprise/Surprise)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:472)
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)


when we create a project...we have to make sure "Create Main Class" is checked and "Set as Main Project" is checked off right??? can this be the reason why the program is not executing?

Edited by lashbandi: n/a

0

It could be. I don't use netbeans, so I can't tell you for sure. And what is the i button. it changes the color of the OK button.

Edited by sirlink99: n/a

0

sorry..thats what i meant...

do you suggest that i uninstall netbeans and then install it again?

1

no I suggest you try to create another project, or package and try again. if that doesn't work then just use your original, or paste my current code into your original and then change the class name. You can change the name of the JAR file if you single click 2 times on the icon, or right click it and rename, or right click > properties and then change the name from there. the only way you can see the class files in the project are if you extract the jar file using winzip, or win rar or another archiver program.

0

so the class name can be something like "try1" for example..and then i can change the jar file to "Surprise" and it will still work?

0

wow...i wish i knew that before i deleted the original try 1 because the jar file was working fine until i deleted the whole try1 project..lol...

Creating a new project worked!!! =D Thank you sooooooo much..you have no idea how much i appreciate your help...your awesome..

1

You can just use the code I posted. All you would need to do is change the package and the name of the class and it should work.

My jar file works. it takes me a little while to load though.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.