Error on my applet
Author |
Message |
Spartan_117
|
Posted: Fri Jul 08, 2005 12:14 pm Post subject: Error on my applet |
|
|
I get this error:
Exception in thread "main" java.lang.NoSuchMethodError: main
What does this mean?
Im using NetBeans IDE 3.6 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Spartan_117
|
Posted: Sat Jul 09, 2005 8:49 am Post subject: (No subject) |
|
|
Ok now i kno why my applet wont work. When i open the HTML file (in Mozilla or IE) it plays the music but none of the graphics show up. When i run it in Ready to Program, im guessing it "forces" the graphics to run and thats why its flickering. But on any other IDE it gives me that error:
Exception in thread "main" java.lang.NoSuchMethodError: main
It gave me this error in JCreator and NetBeans. Does anyone know why this is happening???? |
|
|
|
|
|
Aziz
|
Posted: Sat Jul 09, 2005 9:37 am Post subject: (No subject) |
|
|
Oh, see, this isn't the same error. In RTP, i beleive at least, if you don't have a main method, it adds a dummy one. Now, all other IDEs force you to actually program properly and you either need to have a main method in your class, which means all other methods must be static as well, or have another driver class (with a main method) I don't know about applets, i think the need a paint (Graphics g) but i dont work with applets much, however, with an application, say you have your main program (that does all the nifty stuff):
Java: |
public class MyClass
{
public MyClass
{
~Contructor
}
~the rest of the program
}
|
then you're driver class would be like so:
Java: |
public class MyClassApp
{
public static void main (String[] args )
{
MyClass class = new MyClass ();
}
}
|
when you run MyClassApp, it loads up the "main" method, and then creates a new MyClass object, and calls its constructor, which does the rest |
|
|
|
|
|
rizzix
|
Posted: Sat Jul 09, 2005 1:16 pm Post subject: (No subject) |
|
|
or just switch to Eclipse |
|
|
|
|
|
Spartan_117
|
Posted: Sun Jul 10, 2005 2:13 pm Post subject: (No subject) |
|
|
hmm, interesting, ill try it but i dont think i need it in applets. I think i need the init and paint method, both of them which i have.
And ive tried Eclipse, and its kinda confusing and not exactly my type of IDE, atleast from my first experience. |
|
|
|
|
|
Spartan_117
|
Posted: Sun Jul 10, 2005 2:21 pm Post subject: (No subject) |
|
|
Hey Aziz, back again and im still getting the error, i did wut u told me to do. I hav a seperate class which makes a new object of my Applet class. I also hav a constructor in the Applet, but it does nothing. |
|
|
|
|
|
1of42
|
Posted: Sun Jul 10, 2005 2:26 pm Post subject: (No subject) |
|
|
Did you put everything in the pain or draw method in the applet? This is the method that the virtual machine calls to paint(draw) your applet. You don't actually need a main method for an applet - just make sure you extend Applet, and have a void pain(Graphics g) or draw method.
If you're making a game or some such thing, you can implement Runnable and use the run method to run the applet instead. |
|
|
|
|
|
Spartan_117
|
Posted: Sun Jul 10, 2005 2:40 pm Post subject: (No subject) |
|
|
I do hav extends Applet and a void paint (Graphics g). Im also using the void start method as my main loop. Its real wierd because i took the HelloWorld simple example:
import java.applet.*;
import java.awt.*;
/**
* The HelloWorld class implements an applet that
* simply displays "Hello World!".
*/
public class HelloWorld extends Applet {
public void paint(Graphics g) {
// Display "Hello World!"
g.drawString("Hello world!", 50, 25);
}
}
This gave me this error too! :
Exception in thread "main" java.lang.NoSuchMethodError: main
I found this example on the java site:
http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html |
|
|
|
|
|
Sponsor Sponsor
|
|
|
1of42
|
Posted: Sun Jul 10, 2005 5:50 pm Post subject: (No subject) |
|
|
here's the answer: you cannot run this like you run a normal java app. using the run command in most IDEs (and using the java commandline command) will result in the JVM looking for the main method, which obviously you don't have.
you have to create a webpage with the applet embedded in it, and veiw it through that. alternatively, you can use the java applet view, which should reside in the bin of your jsdk installation.
I embedded the HelloWorld applet into a webpage and viewed it, and it worked. |
|
|
|
|
|
Spartan_117
|
Posted: Sun Jul 17, 2005 5:08 pm Post subject: (No subject) |
|
|
Oh i c, well the Hello World Works, but my mario game still wont work.. it wont load up the graphics but it plays the Music. The only place it loads the graphics is on RTP when i run it. But even then it flickers a lot. I hav my source code attached so if anyone knows applets i'd appreciate the help. |
|
|
|
|
|
|
|