"The import net cannot be resolved" - android

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.

Related

android.support.v7.app.AppCompatActivity vs android.support.v4.app.ActivityCompat

It seems like a very common issue. I'm trying to import and run an Android app in latest Eclipse (neon), but I get the common error of The import android.support.v7.app.AppCompatActivity cannot be resolved. I've downloaded the library project android-support-v7-appcompat from somewhere, and linked it to the project properties. But the errors still here. I see v4 ActivityCompat is not throwing any errors, but the v7 AppCompatActivity shows error, which seems strange. How should I fix it? I am using Android API 23.
I already have the support libraries of SDK installed. But when I add the .jar libraries (which are just two, one for source, one for javadoc), still nothing happens.
import android.support.v4.app.ActivityCompat; --> This is ok
import android.support.v7.app.AppCompatActivity; --> This shows error!
I see v4 ActivityCompat is not throwing any errors, but the v7 AppCompatActivity shows error, which seems strange.
Not especially. The random files you grabbed from some random place do not have this class, apparently. AppCompatActivity was added sometime after appcompat-v7 was published as a library, as a long-term replacement for the former ActionBarActivity. Presumably, the random files you grabbed from some random place pre-date this change.
How should I fix it?
Switch to an AAR-aware build system and an IDE that supports it. Then, depend upon the appcompat-v7 AAR, which is the only way that appcompat-v7 is being distributed at the present time.
Or, do not use appcompat-v7 (or pretty much anything else from the Android Support Library, as most, if not all, of the packages are distributed as AARs, not JARs).

Android Studio sudden appearance of unresolved symbols after pulling from Git

I am new to Android development so I apologize for anything I forget to clarify. I am working on a group project in Android studio, checked out from Git. I previously was able to build the project fine, but after a recent pull I suddenly have many compilation errors coming from the package
projectname\tess two\jni\com_googlecode_tesseract_android\src\java\com\google
It seems that I have a big mess of unresolved symbols, like "cannot resolve symbol (piccolo2d, Color, event, swing), which appear at import statements like these at the top of my classes underneath this project
import org.piccolo2d.*;
import java.awt.Color;
import java.awt.event.*;
import javax.swing.Timer;
I am wondering what might cause these unresolved symbols. I have tried deleting the project and re-pulling it from Git, re-building the project, etc.
Any help or direction would be great, I realize I did not give a lot of context, mostly because I myself am confused at where these problems could suddenly come from.
Anything related to awt or swing will inevitably fail; those toolkits are not available on Android. Someone or something is accidentally importing symbols from the wrong place. It's probably android.graphics.Color you want instead of java.awt.Color, etc.
I suspect that if you delete those imports, and then select Optimize Imports from the Code menu in Android Studio, the correct symbols will be imported.

Errors when importing someone else's projects - Android/Eclipse

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.

Import statements are missing in android eclipse and throws "project contains error(s), please fix it before running it" error

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 :)

Android ADT Eclipse: com.android.common and com.android.ex imports could not be resolved

I'm trying to build Google's open-source Calendar app for Android (source here: https://github.com/android/platform_packages_apps_calendar), so that I may pick apart its code a little bit. When I import the freshly-cloned project into eclipse, I get a bunch of ____ cannot be resolved to a type errors. Looking closely at the types that aren't resolved, the root cause seems to be:
The import com.android.common cannot be resolved
The import com.android.ex cannot be resolved
I've been googling and I can't seem to figure out what's going on? I must be missing some library? I have everything in the Android SDK Manager installed, even the optional libraries. I've tried cleaning and fixing build path properties, etc. The errors remain.
Anyone have any idea what I can do to get this thing to compile?
I have managed to add almost all the required dependencies and now i got an almost-running version.
Kindly, check it out from here
You can also check the last commit, it contains all what i did to get this running version.
Have a nice day :)

Categories

Resources