I do not understant why i get that error http://imgur.com/HhdVmhu
I am following internet tutorials, and this is where i got stuck
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
I do not understant why i get that error http://imgur.com/HhdVmhu
I am following internet tutorials, and this is where i got stuck
What is the error? Please copy and paste the full stack trace instead of posting a screenshot.
What code are you running? Please copy and paste an MCVE instead of posting a screenshot.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
I do not know what a full stack trace is... but i will pot my code..
public class Program {
public static void main(String[] args) {
Persoana acces = new Persoana ();
}
}
this is in the default package
this is the class i created
package Program;
/**
*
* @author Administrator
*/
public class Persoana {
String name;
String surname;
int age;
}
i keep getting that error there. its like it is not finding that class file i created...
PS : started learning java 1 day ago...
What specific error are you getting?
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol: class Persoana
location: class Program
at Program.main(Program.java:14)
Java Result: 1
Are these classes in two separate files?
Is one of them in a package?
Have you imported the class you're trying to use?
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
I can't access imgur, which is why we ask you to copy/paste the text instead.
If the class you're using is in a different package than the class you're in, you either need to import it or use the fully qualified name (include the package info before the class).
Recommended reading: Using Package Members (The Java™ Tutorials > Learning the Java Language > Packages)
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
I just tired something... when i clicked File>new file> java class> next There is a Package tab. I didn't type anything in it, and it seems its working... In the tutorial i was following they were typing the name of the main file... I am confused
And an off topic question, its something that troubled me about java since i started looking into it , and now that i started learning classes troubles me more...
When i create a new project it comes with this line pre-configured
why is that ( public class NameOfProject { ) there?, does it have to be there?public class NameOfProject {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
}
}
I understand that public static void main has to be there because the program looks for the main and starts executing instructions from there.
I highly recommend you ditch the IDE and use the command line and a basic text editor until you understand the basics.
Your original problem was that you were trying to use the Persoana class inside your Program class. Since Persoana is inside a package, you have to import it to be able to use it.
Since you modified your code so Persoana is no longer inside a package, you no longer had to import it, and your code magically worked again.
It's not always a good idea to use the default package (no package). It's up to you though.
What happened when you tried to remove the part you're confused about?
You can't have a method outside of a class. So to have a main() method, you have to have a class. I highly recommend using a basic text editor and the command line until you understand basics like that.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
I understand. I use the IDE because the tutorial i am following uses it, and i understand better. If you know other tutorials that use text editor, i will use them. Thank you for the answers.
ps: i use this http://www.functionx.com/java/
Last edited by jeffpascal; June 23rd, 2014 at 02:28 PM.