• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception handling  RSS feed

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to compile the following code in one file



I put the Bello class out of the main but now I am having issue to reference Bello class from the static main!

How to solve this ? Thank you!
 
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matt Road wrote:I put the Bello class out of the main but now I am having issue to reference Bello class from the static main!

How to solve this ? Thank you!


That depends on what the issue is. Would you care to describe it? That would be far more user-friendly than waiting for people to download your code and see what happens when you compile it. Or run it. Wherever the issue comes from.
 
Matt Road
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compile problem

Test.java:23:19: error: non-static variable this cannot be referenced from a static context

and

Test.java:25:14: error: cannot find symbol
} catch( BadException se) {
 
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put your other classes outside of class Test. Putting them inside Test like that makes them instance members of class Test. I think it would get too confusing to explain to you.

 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, names are case sensitive in Java. You can't do Bello ola = new bello();

It has to be Bello ola = new Bello(); (constructor name should be exactly the same as how it is declared in the class definition)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!