Hi, my simple program is not working. I created the package with the Student file within by using javac -d . Student.java after compiling it. Then, the ThisDemo class does not compile. I did some debugging and found issues, but still getting the exact same errors.
Just to reiterate- Student.java compiled fine, then I made test1 package with Student inside of it. After that, well, nothing works.
EDIT for console error:
The student not having main when being run was my mistake since it has no main, and the I forgot brackets for ThisDemo after args- but the other errors baffle me.
Please don't edit posts like that; it makes it appear that Norm was mistaken.
The error message you showed proves that the package structure isn't the problem. It is that the constructor you are calling has package‑private (=default) access; it is only accessible from the main() method if you give it public access.
Please only use _ in identifiers in,
1: Package names, as described in the Java™ Tutorials, and
My professor put up code that purposefully is wrong, so there are errors I am still working with. I forgot a constructor must be declared as public, but after putting the public access modifier, I Still get this after saving, deleting the package and recompiling it-
Your file locations are wrong. Java package/directory rules require that the compiler should output file test1/Student.class Preferably the compile source would be file test1/Student.java.
Also, your error message comes from the fact (as Campbell said) that you did not declare the constructor for Student to be public, so it defaulted to package scope. One of Java's quirkier features.
Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.
William Golovlev wrote:Ok well I am not quite sure why this is an issue because I have made my file contain a public constructor..
Update: never was an issue with the code. For some reason I was compiling, and everytime I compiled it was not re-compiling the file in my package folder. Thought I was doing it right with "java -d . ThisDemo.java" but deleting all class files and recompiling worked. Thanks!