the type of out is erroneous - java

I'm working on a java project in Netbeans 8.2. And suddenly, I started receiving errors whenever I type :
System.out.println();
System.err.println();
Error shows : The type of out is erroneous ( same goes for err)
Also, when I tried
import java.io.PrintStream
an Error shows that PrintStream doesnt exist in package IO.
What should I do to resolve this problem ? and is there any replacements for System.out.println()

Same error occurred to me as well, but it was when I would copy-paste some code and some lines would throw such error, I found out that deleting cache can fix error. First close netbeans, and go to cache folder.
Cache folder is located in C:\Users\"YOUR USERNAME"\AppData\Local\NetBeans\Cache\
But you can also copy address from netbeans, go to help -> about and you will see Cache directory
Inside Cache folder you will find another folder which name is version of netbeans, in your case it should be 8.2, just rename this folder to something different because you want to keep it for case something bad happens, then run netbeans and it should create new folder called 8.2, if everything is working properly you can now remove renamed folder and continue with your work.

Related

How can I get stdlib.jar to work in IntelliJ IDEA?

I​ had used the IntelliJ IDEA installer provided in the booksite for Computer Science: An Interdisciplinary Approach and I had no problem to use the library. However, I noticed that installation had screwed my Git bash display settings, so I uninstalled everything.
Later, I installed the latest version of IntelliJ (2021.3.3), from the JetBrains website and apparently all the previous settings were overwritten, since I could no longer use the library. So, I downgraded back to the version provided in the booksite, however, I still can't use the Std library.
I've tried adding the versions of the library .jar files that I found:
On the Standard Libraries Princeton's webpage
On the Jar Download website
On this post from Stack Overflow
In the .jar file from the hello.zip file I found on this other Princeton webpage
Together and independently to the module and libraries, via IntelliJ IDEA, following the paths: "File > Project settings > Modules > + > JARs or directories" and "File > Project settings > Libraries > + > Java" , respectively, and choosing the corresponding directory/file, with no luck, since I've got the "cannot find symbol" error message:
Barnsley.java:16: error: cannot find symbol
StdDraw.setScale(-0.1, 1.1); // leave a 10% border
^
symbol: variable StdDraw
location: class Barnsley
For literally every single mention of the Std libraries in the code. I​ also tried editing the environment system variables and created a variable named "CLASSPATH" and linked it to the Stdlib.jar file and then, to the .lift folder that came with the hello.zip file, from the first week assignment. Again, no luck, because I kept getting the same error message.
Next up, I typed:
javac -cp stdlib.jar Barnsley.java
In the command line, and although that command itself didn't lead to any error message, when I tried to run the program, typing:
java -cp stdlib.jar Barnsley 10000
This error message showed up:
Error: Could not find or load main class Barnsley
Caused by: java.lang.ClassNotFoundException: Barnsley
I also vainly tried copying and pasting every .java file from Standard libraries webpage to the same directory where I keep the program files.
I know some (maybe lots of people) have asked the same or a similar question before, either here or in other forums, but I've been googling and looking for a solution for three days now and, as you can see, none of the reported solutions that I've found have been of help to me, that's why I decided to ask again, on my own.
Thank you for reading my post and/or for any help you can provide.
PS.: The Barnsley.java file in the error messages corresponds to the one provided in the 5th section of this webpage from the booksite.
[Edit - April 7th, 2022]:
I tried to follow #CrazyCoder advice, so I created a folder named "src", extracted all the files from the stdlib.jar file that came with the hello.zip file into src and also moved Barnsley.java to that folder. Next, Next, I tried to follow the instructions from the webpage he mentioned, as shown in the following screenshot:
And somehow, got the same error message when compiling:
I don't know what went wrong :C Any assistance would be highly appreciated.
[Edit - Later on April 7th, 2022]:
Something weird happened. I downloaded the file provided by #CrazyCorder and there was a warning about Amazon Corretto not being installed, that I decided to ignore.
I tried to run the program from the command line, with no luck, because I got the same error message as always. So, I noticed that there was no JDK assigned to the SDK slot in the Project structure, and I chose to use JDK 18 (following the path "File > Project structure > Project"), which is the one that I had previously installed on my computer, but that didn't really change a thing.
Lastly, I tried to run it from the IDE and that's when it finally worked!!! So, thank you, #CrazyCoder :D I still don't know why it doesn't work from the command line, though...
I also vainly tried copying and pasting every .java file from Standard libraries webpage to the same directory where I keep the program files.
This works just fine, you need to place all the .java files from the stdlib.jar into the sources root directory (marked in blue in the project view). Barnsley.java needs to be in the same directory.
The jar with .class files will not work in the dependencies/classpath as you cannot import classes from the default package in Java.
It was an extremely poor choice to keep the classes in the default package and it's the fault of the creators of this library/course. This simple oversight has caused major headaches over the years.

How can I clean up my eclipse project after deleting a .java whose .class file still seems to be somewhere?

So, I deleted a couple of .java files from within eclipse because I didn't need them anymore. However for some reason another class still uses them and compiles without a problem. When I go to the declaration of the constructor of one of the deleted classes a .class file opens of that class even though I thought they got deleted by eclipse when I deleted their .java files.
I have tried to clean the project and I tried to find the .class file using the system file explorer in the folders that are listed in
project > properties > resource > linked resources. However I couldn't find them.
Now, since I deleted those files/classes there should be a compile time error wherever they are used but everything compiles without an error, even using the code that should've gotten deleted. A colleague that recently joined the project does receive compile time errors, since he doesn't have those class files. And I want to get them too, so I can fix the code where the classes were used. Of course he could show me the lines of code that are affected but if this happens again he would probably be affected as well as he would have the class files by then.
Try doing the following
Go to project > properties > Java Build path >Source
under that you can find Default Output Folder section, simply delete the classes folder under that location with in your project.
Try cleaning the project.
Or
Simply close the eclipse and reopen it again, sometime this would work for me.
Hope it resolves your problem
If you just deleted the sources, they binaries would still be there. So open the Navigator View and go to the project in question. Look for the bin directory and delete the appropriate class files. Otherwise, delete the project itself.
You should also ensure that no other programs depend on those class files.
I found the problem. Someone built a .jar file I didn't know of which contained a lot of old code.
I found it by right clicking the constructor and selecting
references>project

The project was not built due to "Could not delete '/Help/build/classes/exportFile'.".

When I imported my project in Eclipse Oxygen, it gave the below error.
"The project was not built due to "Could not delete '/Help/build/classes/exportFile'.". Fix the problem, then try refreshing this project and building it since it may be inconsistent"
Googled and got that to delete the contents of the bin folder and clean the project. But there's no bin folder. Tried cleaning, still the same error. What else can be done
You found a solution yourself, but here are some more informations about this error.
First, you said, your search brought up answers where deleting the bin-directory manually solves this but you don't have this directory. Reason for that is that you configured your project to write classes to the classes-directory (bin is the default).
The "cannot delete" message appears mainly on Windows systems if there is another process keeping a lock on the directory or files within. The classic reason for that is that you currently run the application or that you have an Explorer window open that shows the content of this directory. Closing the application/Explorer window normally solves the problem. Sometimes the lock keeps staying. A way to find the culprit is using Sysinternal's ProcessExplorer. It allows you to search for it by using Find->Find handle or DLL. The result can be clicked on and you can even forcefully close that entry, releasing the lock (some programs don't like that but I never had any problems doing that).
But sometimes it's actually necessary to reboot the system if you can't get rid off the lock otherwise.

Eclipse console error link sending me to wrong project

I have a web site project in Eclipse and I needed to copy it and rename it for a new client. So I had my tortisesvn export the site to a new directory and changed the project name in the .project file and imported it into the same workspace in Eclipse. It seems to be running ok but now when I get errors in the console window the links that should take me to the line of the error take me to the file in the original project not the new one. Anybody know what I can do to fix this?
EDIT: In case anyone asks. I'm sure it's using the correct file when running the site and the error number is on the correct line. I put an intentional divide by 0 error in my code to test this and I get the expected error in the console window on the line that the error is on but it still sends me to the same file name but in the other project.
I found this one with some more searching: Eclipse opens wrong source file on exception
It seems if I remove the other project from the server in tomcat it goes to the correct spot. What a pain.

Eclipse run old version of program

I have a problem while runing my application in eclipse. I make some edits like this:
String res = "newvalue";
System.out.println(res);
But when I run the application I still receive "oldvalue" in output. After this I tried to delete main() function - and I run application and I see "oldvalue" in output again.
Maybe it's some cache in JVM, or smth. else?
UPD:
It's 15:35 on my clock now. But in /bin folder I see .class files with 14:33 timestamp. I change source files (.java), press ctrl+f11 in eclipse and files in /bin folder are still 14:33 ...
UPD2:
After cleaning the project I receive the following problem:
The project was not built due to "Could not write file: D:\projects\NelderMead\bin\ru.". Fix the problem, then try refreshing this project and building it since it may be inconsistent
SOLUTION
The problem was that eclipse can't write file to the folder with spaces and UTF chars in it's name. So, I copy project to the new clean workspace and it runs without problems! Thx all for help detecting the problem!
You're executing an older class files, the reason could be
a compile error somewhere else (see problems view)
or your changed accidentally the source path so that the new source no longer gets compiled.
Try to clean the project and make sure the new classes are compiled to your output folder.
The JVM doesn't have a cache for class files.
First, make sure the file is saved (there is no asterisk next to the file name in the tab). Usually files are saved automatically, but you could choose not to save files and never ask by mistake, the first time Eclipse pops up this dialog.
Then see what's going on in the Problems view. You might see something like project cannot be built due to the following reason. It may be because of compilation errors in the dependent projects.

Categories