When I start a new Android project in the Eclipse/ADT bundle, I get 2 errors in the code..
The 2 warning messages are as follows:
The import android.app.ActionBar is never used
The import android.os.Build is never used
Both of them are in MainActivity.java
This is very odd because it happens as soon as I create a new project!
Can anyone please help me solve this problem?
These are not errors, but warnings. Chances are that these classes (ActionBar and Build) are introduced by the "New Project" wizard which generates code from a generic template. These classes may be useful when you proceed with your project. In case you do not need them, simply remove the import statements.
android.app.ActionBar works on 3.0 level 11 API,
You can do two things to resolve this error,
go to the line and remove the import statement,
or
press Ctrl + Shift + O (the letter O and not zero).
It automatically organizes the imports and fixes them.
Related
I have been using Eclipse for about 6 months now, and I noticed that I rarely can import someone else's project into Eclipse. I get so many errors in many files. For example, I tried to import a friend's project that I know works just fine, but I get a lot of "R" errors, like Eclipse can't recognize "R" as a field, and then other weird ones like ActionBarActivity is not recognized or an entire imports like android.support.v4.app.Fragment that visually are in the library but are not being recognized by Eclipse as being there, and I check them and they are definitely marked "Is library" and added properly to the project. Anyone know why this is or how to fix? It's frustrating because to learn, sometimes you need to see someone else's app run first, then look at their code, but you can't. Thanks in advance.
My usual way of importing a project is to do File -> Import -> General -> Existing Projects into Workspace. Also, I have tried cleaning the project, but it doesn't work.
try this File -> Import -> Android -> Existing Android Code into WorkSpace ->then browse-> select your project->make sure the checkBox"copy the project into workSpace" is marked
Check your Build Path. In the Android Section, try using some other API level click on Apply and after your project finishes with the building workspace, again revert back to the original API and click on OK.
Also check for any Build Path errors.
So thanks to the help of everyone of this post, and others on another post, the problem was finally fixed and took several steps.
Turns out that the ActionBarActivity error had a quick fix (hover over it, you get quick fix options) of importing the appcompat_v7 library. I never chose that before, because I thought it was already installed, hence the conflict with android-support-v4.jar (meaning there were doubles of that library), but I chose to import it anyway and that error went away.
But I discovered that android-support-v4.jar was actually a component of appcompat_v7, so that was causing the "Jar mismatch!" error in the console. So I deleted android-support-v4.jar from the libs folder, and the jar mismatch went away.
Lastly, my layout files were all not being recognized, even though I knew the variable names were all correct. So the error was from when I tried to refresh my imports in the very beginning of the problem (using shift+command+O), thinking it was an import problem (which it was), but at that time, refreshing did nothing. BUT... Eclipse took away import com.laurengariepy.android.gridimagesearch.R; and replaced it with android.R;, which is what was causing all the layout errors. So once I put that com.laurengariepy.android.gridimagesearch.R; back, then all errors went away.
So the take-away to this story, is be careful with Eclipse version 22.6. The auto-import of the appcompat_v7 library will cause a lot of trouble when you try to import other people's projects, because they were likely not created in an IDE with appcompat_v7 already there.
Yesterday I have created a simple android application using eclipse (ADT bundle) and when I run it, it works fine. Today, when I try to open it, it shows errors
Your project contains error(s), please fix it before running it
, and
cannot resolved variable.
After I go through my android application project, I found out that, all the import statement were gone. So I manually key in all the import statement and it works fine. This is second time I have encountered this kind of problem.Does anyone know why when I close the project and reopen it on next day, all the import statements are missing?
That shouldn't be the case usually. You can try the auto import of the library needed instead of manually inserting the library one by one by ctrl+shift+O. Another common problem is that you included the library but it still cannot reference it correctly. Something like cannot reference R.id.xxx, that can be solved by making sure that you don't have import android.R in your code.
Hope that helps :)
I have an Android project in Eclipse that previously had one library imported, zbar. And now something peculiar happened when I added a second library, one which I put together myself. At first, the project wouldn't build because of android-support-v4 mismatch. So I updated the minSDK of my application project to reflect the one in my library. That seems to have worked.
Next, I wanted to make use of my new library, so I created an object of a type defined inside it, and thus had to import the code. What happened next was Eclipse started to complain about one of the imports to zbar.
import net.sourceforge.zbar.Symbol;
And what i don't understand is, it says "The import net cannot be resolved", and only the word "net" is underlined in red. As if it didn't see the period following "net". What's going on here?
I have tried removing the library and then adding it, as well as changing the minSDK version back. Nothing has worked so far.
edit: I think removing the android-support-v4 from my custom library solved this.
I'm a beginner of Android Application development need to practice by examples and samples given in the book "Beginning with Android" by Wei Meng Lee, but whenever I try to follow those steps I come across a few errors unable to clean them. The Error seems like this:
" setContentView(R.layout.activity_main);" Don't know what type of error is it. In my computer I've installed SDK API level 16 that is for Android 4.1 What to do? Please guide me through appropriate answer.
Remove import
import android.R;
Than clean build your project also check xml layout file name in
setContentView(R.layout.activity_main);
than it'swork fine.
You should get the latest version of eclipse. Its now Eclipse Juno.
And check your import.
Remove
import android.R;
Instead put
import android.packagename.R;
We are new to Android and we are trying to develop a new application. We installed all the basic setup of Android. We tried to run the Android Sample projects in Eclipse. But while to compile the following lines and a few other lines that uses the variable 'R' throws up an error.
setContentView(R.layout.activity_main);
'R cannot be resolved to a variable'. I do not understand what is causing the error. Anyone help me out in this issue.
check that the import for R class is not
import com.android.R;
and you should make it
import yourpackagename.R;
then recompile
Please try to clean the project, and try compiling again.
If not solved, refer to R cannot be resolved - Android error
If you have 64 bit Linux platform without ia32 libraries, then this problem could also occur. It took me quite some time to pin this one down, seeing that the problem is not clearly linked with the inability to execute 32 bit code.
Just make the import part import com.android.R.layout instead of com.android.R
In my case i forgot to re-install the SDK. When you re-install your operating system, you should re-extract (re-install) your SDK Zip file.
Also check that you have your android libraries mapped correctly in the settings for Eclipse (if you are using eclipse to develop).
Check if your resorce name (for example template.xml) has ONLY small caps letters.
import com.packagename.R* will worl
Change import to
import yourpackagename.R;
If error is still there then
go to gen folder->packagename->R.java
and remove error line some times it gave error on drawable files.
setContentView(R.layout.activity_main)
Change the SDK and delete the project and create new ... it will definitely work!