android-support-v4.jar isn't importing correct

2019-02-04 09:30发布

I'm trying to get an app to compile that uses the android-support-v4.jar and the Fragmentation classes it contains, but I keep getting messages whenever I try to compile that there are errors in the code. All of the errors have to do with different Fragmentation classes that are in the .JAR. I have tried ctrl-clicking the project folder and then selecting Android Tools -> Add Compatibility Library and I keep getting this error:

[2011-12-20 11:55:31 - Android Compatibility JAR not found:]
/Applications/eclipse/Eclipse.app/Contents/MacOS/v4/android-support-v4.jar

Why would it be looking for the .JAR in Eclipse's Package Contents? I've gone into the project properties and went to the Java Build Path, and imported the .JAR from the MainActivity/libs folder, that didn't work, and then I tried to import it from my SDK directory, and that didn't work. I've fixed the project properties and cleaned and built it countless times, I've restarted Eclipse, my computer, re-downloaded and installed Eclipse, the Android SDK's and ADT and still nothing. I am completely stumped.


Edit


I've gone through the build path and imported the .JAR from both the MainActivity/libs and my SDK directory. For the hell of it I added the .JAR in the directory that keeps appearing in the errors and that hasn't worked. What's making Eclipse look for it in it's Application Package Contents?


Update


So after tinkering the project contents aren't showing any errors but the MainActivity folder still says that there is one and I still can't compile.

Like nyah:

enter image description here


Revision


So I think the question may be "Why is Eclipse looking for the .JAR in the Eclipse Application's package contents instead of the libs directory of the project or the Android SDK directory that I used to import it as an external .JAR?"


Update #2


I am only getting one error now after tinkering, it's on this method:

@Override
public MenuItem setOnActionExpandListener(OnActionExpandListener onActionExpandListener) {
    // Noop
    return this;
}

The Quick Fix says that I should delete the @Override annotation but that method must override a super class method.

These are the errors that it shows:

Multiple markers at this line
- The method setOnActionExpandListener(MenuItem.OnActionExpandListener) of type SimpleMenuItem must override a superclass method
- implements android.view.MenuItem.setOnActionExpandListener

12条回答
贪生不怕死
2楼-- · 2019-02-04 10:23

Something similar happened to me. At the top of MainActivity.java I had the next imports giving errors:

import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

In each of the lines on the left they had the light bulb making some suggestions. If you click on it, one of the options will be "Fix project setup". You then will be able to choose between several options for fixing the imports, you should choose the one that specifies the android-support-v4.jar.

查看更多
beautiful°
3楼-- · 2019-02-04 10:26

Looks like it is looking for jar here :/Applications/eclipse/Eclipse.app/Contents/MacOS/v4/android-support-v4.jar

android-support-v4.jar is found in <sdk>/extras/android/compatibility/v4

Please make sure you add this as an external jar in the java build path

查看更多
乱世女痞
4楼-- · 2019-02-04 10:27

Do you try not to do Android Tools -> Add Compatibility Library, and only add the jar in java build path library?.

I use this jar library of this way and it works without any problem.

查看更多
干净又极端
5楼-- · 2019-02-04 10:34

I had the same problem running in Ubuntu. Go to Tools->Options. Check Force https://... to http:// Open Android SDK Manager. Check Extras->Android Support Library.

查看更多
何必那么认真
6楼-- · 2019-02-04 10:34

I had the same problem.

Under the project properties:Java Build Path:Order and Export tab, the box next to android-support-v4.jar wasn't checked. I checked the box, and the error went away.

查看更多
▲ chillily
7楼-- · 2019-02-04 10:34

Solution: Make sure that you enter the same API for "Target SDK" and "Compile with" during Android project creation (or in the Manifest file once created).

查看更多
登录 后发表回答