Reputation: 1
So I am getting this error when I try to run this short piece of code. The error is :
cannot find symbol
g.Init();
^
symbol: method Init()
location: variable g of type Game
1 error
Ok so I initially thought that I did not have the proper imports so I inserted import java.util.*;
but i still got the same error. Do I have to define the init function for it to run? Or is they some other import that i need to call. I think the problem lies more with the init();
but i could be wrong. Therefore, if anyone can offer me a tip or help me out on this I would appreciate it.
import java.util.*;
public class Game {
public static void main( String[] args ) {
System.out.println( "Hello world!" );
Game g = new Game();
g.Init();
}
}
Upvotes: 0
Views: 1024
Reputation: 59
For above program, you should define one method with the name Init(), and should define the functioanilty inside that, As answered by aoi222.
And main thing no need to import any predefined packages untill required.
Thanks, @rs
Upvotes: 0
Reputation: 733
Yes, the problem is that your Game class does not have an Init() function defined. I'm not quite sure what you're trying to do with Init(), but you don't actually need it to run your program.
public class Game {
public static void main( String[] args ) {
System.out.println( "Hello world!" );
}
}
Or
public class Game {
public static void main( String[] args ) {
Game g = new Game();
g.Init();
}
public void Init()
{
System.out.println("Hello world!");
}
}
Should work, it depends on how you want to structure your program.
Upvotes: 3