• Post Reply Bookmark Topic Watch Topic
  • New Topic

class doesnt have a main method ?  RSS feed

 
Manda Putra
Greenhorn
Posts: 10
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I want to show "Welcome to taman" text, but why when i run the program its always says
class "pepohonan.Pepohonan" doesnt have main method



so what should i change?
 
Junilu Lacar
Sheriff
Posts: 11476
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If Java complains that your program doesn't have a main() method, then it's logical that you need to provide one, right?

The main() method is a program's entry point when you issue the command "java YourProgramName" - this is the method that Java will look for to start everything off. If it can't find a main() method then it won't know what to do with your program so it complains.

The main() method's signature needs to be like this: 

 
Manda Putra
Greenhorn
Posts: 10
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what should i write in  main() to show "Welcome to taman?"

Junilu Lacar wrote:If Java complains that your program doesn't have a main() method, then it's logical that you need to provide one, right?

The main() method is a program's entry point when you issue the command "java YourProgramName" - this is the method that Java will look for to start everything off. If it can't find a main() method then it won't know what to do with your program so it complains.

The main() method's signature needs to be like this: 

 
Junilu Lacar
Sheriff
Posts: 11476
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the simplest thing that you could do is just to write a simple System.out.println() statement in there:

But then, you wouldn't be using any of the code you already wrote. To do that, you would have to use new to create an instance of your Pepohonan class then call the method that does what you want to do. Your menampilkan method still has something wrong with it though. Look up the documentation for System.out.printf() to see why it won't work the way you are using it right now.

you should go over the Java Tutorials first to learn more about how main() and objects work.  Is this school work?
 
Junilu Lacar
Sheriff
Posts: 11476
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and Selamat Datang di CodeRanch!

(or is it "ke CodeRanch"? - Saya tahu sikit saja. Been over 18 years since I've had to speak Bahasa)
 
Manda Putra
Greenhorn
Posts: 10
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, now i know how its works. Terimakasih! but it isnt a school work
Junilu Lacar wrote:and Selamat Datang di CodeRanch!

(or is it "ke CodeRanch"? - Saya tahu sikit saja. Been over 18 years since I've had to speak Bahasa)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!