Import into Eclipse causes error on every line - java

I have Eclipse on my Windows 8 laptop and on a Windows 7 PC at University. I made some projects at the University and tried to import them at home and there is an error on every single line. It tells me everything cannot be resolved to a type but, as you can see, when I start writing the project from scratch (the second half of the image) I have no such problems.
I apologise, I am new to Eclipse and wonder if anyone can offer any advice. Someone recommended modifying the buildpath settings, I tried to fiddle but could not resolve the problem.

What you are missing are the default Libraries in your project
Try this:
right-click on the EventHandlingDemo Project -> Build Path -> Add Libraries
then select the "JRE System Library" -> Next -> Finish
that should do it!

Related

Error exists after project being imported in eclipse

I was working on a Java project on my laptop and then I decided to move it to my PC.
The project was totally ok and had no errors when I was working on it on my laptop but after I imported it to eclipse on my PC eclipse, it has errors; mostly "Cannot be resolved".
This means the problem is with eclipse and not my code.
I have no idea how to fix this and I'm in a bit of hurry.
Here's a screen shot from my errors
I found out that the problem is with some imports. Libraries do exist but eclipse doesn't import them. What should I do now?
This happens a lot after copying Eclipse projects (or after updating the local code from a repository), the following steps usually solve the Problem for me and my team:
Select the Project -> Rightclick -> Refresh
Go to Project -> "Clean..."

Eclipse: "The import java.io cannot be resolved"

I have several Android projects in Eclipse, and all is fine, except one (a library) that can not resolve any imports.
The java.io imports do resolve fine in other Android projects in the same workspace, and previously (I haven't used it for over a year) this library worked fine, too.
Any ideas?
Check two things
Eclipse preferences
Check your Eclipse preferences: Java -> Installed JREs
The one that you're using should be marked and it should be a JDK not just a JRE.
Project build path
Also check your project's build path: Right click on the project -> Properties -> Java Build Path
Check in the libraries folder whether the JRE System Library is present and ...
If not add it using Add library -> JRE System Library and then
select the correct one (from an installed JDK).
I am using Maven an this is what I did to re-solve -->
Right click on project
Maven -> Update Project. Make sure you choose 'Force update of Snapshots/Releases'.
Also check the 'clean project', 'update project conf from pom' and 'refresh workspace resource options' and click ok.
The following worked for me:
Close the project and reopen it.
OR
Clean the project ( = rebuilds the buildpath and thereby reconfigures the JDK libraries).
I was missing the JRE Systems Library in my Project Tree.
And navigating to Projects' Build Path and 'Add(ing) Library' worked!
I just ran into this problem with Eclipse 2022-6 and java-17-openjdk-amd64. I just appeared during editing in another file, the same code had worked before.
For me, all settings were correct and none of the above tricks worked. What I then did was completely removing the import command import java.io.Closeable;, saving the file, adding the same import command back at the same place, and saving again. The error disappeared.

R.java Missing in Android Project in NetBeans

I'm doing this for a project in AP Computer Science.
Basics:
Mac OS X 10.5.8
NetBeans 7.0
Android SDK 3.0 (Level 11)
So I'm trying out some of the Android API Demos in NetBeans (I prefer it over Eclipse) and I'm using samples\android-11\ApiDemos\ for the source. The R.java file is not generating and "package R does not exist". I've looked at other answers, and they say to Clean and Build the Project, but that option is grayed out in NetBeans (so are just the "Clean" and "Build" options). Any ideas on what I should try before I switch to Eclipse? I also have a computer running Windows 7 if I need to change the OS. Thanks!
Right-click your project and hit build. It will generate the missing R class for you. At least it did for me in Netbeans 7.1
Just right-click on the project, select the "Update broken project" command, then "Build" is not gray no longer. Build it, OK!!
The right-click menu command
I had the same problem, but all I did was a "Clean and Build", and then the R file was created by Netbeans (running 7.1).
I had to run netbeans as administrator on my Windows 7 pc before it could build the R file. If you're saving the project to somewhere "secured", make sure that Netbeans gets all the neccessary rights to read/write/edit that location
Get Android plugin for NetBeans and then you will be able to open these project and play with them. The project home page is http://www.nbandroid.org/
Some initial steps may be needed. Set up SDK location in Tools | Options | Misc | Android. Then check that your project has some build target set in (select project, r-click and go to project properties). Once the build target is set plugin will (re-)generate build script and required .properties files. You'll be able to run build then.
-Radim
Several things could be going on, but what happens to most people is:
an error makes R not build
R is unknown, they try to fix the error by importing packages
There is now a "import R.id" or something in the java files
...
Loss
Also, it could just be point one, that a problem with the setup (manifest broken, wrong project props, or something like that) make R not generate, and then you won't have R.
But really, I've seen some examples of people doing point 3.
I had the same problem and it was due to the package of R not being the same as the one for Main. I just moved Main to the same package as R and everything is fine after I hit Build.
In my case adb was missing.After installing adb everything worked fine.
You can just right-click the project and choose build from the context menu.
(This works for me. I am using NetBeans 8.1)

Error: Unable to open class file R.java [duplicate]

This question already has answers here:
Developing for Android in Eclipse: R.java not regenerating
(64 answers)
Closed 9 years ago.
Did a fresh install of Eclipse, JDK and android-sdk.
I am currently receiving this error when creating a new project
[2010-09-26 16:07:56 - Test] ERROR: Unable to open class file C:\workspace\Test\gen\com\example\test\R.java: No such file or directory
What's the reason for this and how do I fix it?
Eclipse Helios 32 bit
java version "1.6.0_21"
Android sdk API 8
P.S. I'm new to Android development.
EDIT: I tried most of your solutions, but nothing worked. So I started using my friend's install of Eclipse Ganymede.
I have had same issue, all what I needed to do, was create project and restart eclipse.
//Edit: Complete collapsing of "Package" tree works as well.
This is a mighty annoying error.
It happens 100% of the time when I create a new android project.
What seems to work for me is to just delete the file (which DOES exist and is accessible by my user), then hit build, and it will regenerate it and stop moaning.
It's clearly a bug as there are too many people getting it simply by filling in the boxes in the new project dialog (like me) without even modifying any code!
Have a look at your console. It is an aapt aborted error. Since aapt is the tool that auto-generates R.java, therefore, R.java was not getting generated.
Since R.java is a auto-generated file that stores information about your drawables you should rebuild your project. Before that have a look at your layout xml files and check them for errors.
Notice that Project -> Build All should be selected. Also try to run your project.
Removing Read Only attribute on Eclipse workspace directory and Project->Clean->Build Project
did the trick for me. I then clicked on the project directory from within Eclipse and did a F5 (Refresh) . R.java was generated in the gen folder.
I had a similar error on the creation of new projects myself. After messing around I tried moving the R.Java file into the same location as my projects java file (the src file). Eclipse then saw I removed the R.Java file from its location and created another and that seemed to clean up the error.....I dont know if it was because eclipse rebuilt the file and then saw it or what but that seemed to work for now.
After creating the Project, Right click the Project Folder within the Project Explorer on the Left Tab of Eclipse.
Click on Source->Format.
The Console will say:
[2010-11-24 11:57:42 - YourProject] R.java was modified manually! Reverting to generated version!
Then you're good to go. Try running your Project and it will compile.
Check your imports. If this has sneaked in, then delete it.
import android.R;
Had a almost identical issue with Eclipse Helios 64 bit on Linux, but I had the "1.6.0" API selected like you. The bizarre thing was I could type;
cat <the path it was moaning about>
in a console it would display correctly.
I created a new AVD which used Android 2.1, the issue magically vanished. Perhaps it's a bug in Android SDK or Eclipse?
Right click on your project name in package explorer. Then click 'Validate'. It will be fine.
Here is how to fix it:
Go to your "workspace" folder and make sure it's not "read-only"
Eclipse Menu > Projects > clean
Had the same issue.I was able to solve it by doing the following:
go to Window/Preferences/Java/Build Path
select 'Folders' and change the output folder to 'gen' (this is where Android looks for the generated java files,but the default in eclipse is 'bin').
restart Eclipse
Windows 7,Eclipse 3.5.2
Configure buildpath.. check android , it worked, of course i followed one of the posts mentioned above window, preferences, java, java build path and selected project,
then created a project, and tried to build same error, then i checked build path and saw android is unchecked, checked it and build again, it works!
I had this exact same problem with no helpful errors. finally, I tried deleting my debug keystore and it worked:
rm ~/.android/debug.keystore
I had seen people mention that, but I figured it wasn't my problem because I wasn't getting any errors relating to the debug keystore. I found the answer here:
"Debug certificate expired" error in Eclipse Android plugins
apparently the debug keystore is only valid for one year.
I would say that once you have created your project and you've mention the R.class error --> just restart the Eclipse IDE and everything will be fine ;)
1.-Open Eclipse
2.-Open Window/Preference
3.-Expand JAVA option
4.-Select Build Path
5.-Check the option "Projec"t and uncheck "folder" options
6.-Click on OK
7.-Restart eclipse IDE
Let's go to code !!
This problem can be solved by merely cleaning and rebuilding the project. How ever there is a link to the latest version of Eclipse for Android.
**Eclipse Java EE IDE for Web Developers.
Build id: 20100218-1602
(c) Copyright Eclipse contributors and others 2005, 2009. All rights reserved.
Visit http://www.eclipse.org/webtools**
Here is a link to Android Tutorial with Eclipse
http://developer.android.com/resources/tutorials/hello-world.html
In mac,
I select Project>Clean
after that, i unchecked Build Automatically
then i run the project and it works :)
Windows 7 64bit, run eclipse as administrator, solved the problem for me.
In my case there was no gen folder after pressing clear...
To solve it, i created a new gen file, then when to Build Path => Configure Path, and pressed ok.
All went smooth after that :-)
Following steps are done as solutions:
1. Collapse the project tree structure
2. Go to the workspace and remove the readonly permission of the workspace.
3. right click "default.properties" and go to properties and uncheck the readonly permission in eclipse.( this is done when the workspace shows build error even though there are no compilation issues)

How to get IntelliJ From making annoying blue popups?

On Mac OSX running the latest JDK, my IntelliJ 9.0.3 pops up these incredibly annoying and persistent windows:
This stuff compiles and runs fine, the JDK is definitely operational on this machine. It should be a java.util.string, not some other apache string.
what is this supposed to be, and how do i get rid of it? Thanks!
Found it!
In intellij idea 14, go to
settings -> editor -> general -> auto import, and untick 'show import popup', under the java/kotlin/xml/... section.
That will fix it.
My guess is that you have not configured the Java SDK that your project is using.
File -> Project Structure -> Project -> Project SDK, choose one, make sure it doesn't show in red.
You can ignore certain packages & classes from the import-popup.
See the answer here: Limiting IntelliJ IDEA import suggestions on completion

Categories