inMutable cannot be resolved or is not a field

2019-08-07 07:46发布

问题:

I'm getting an error message stating "inMutable cannot be resolved or is not a field" and I believe this is because this was introduced in API 11 and I was previously using API 8.

I've upgraded my manifest to use minSDK 19, and updated my build path to include the external JAR for SDK 19, cleaned the project and I'm not sure what else I can do at this point in order to resolve this issue.

Source:

private Bitmap getThumb(String s)
{
    //Bitmap bmp = Bitmap.createBitmap(150, 150, Bitmap.Config.RGB_565);
    BitmapFactory.Options opt = new BitmapFactory.Options();
     opt.inMutable = true;
     Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.sqwhite, opt);

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.animoto.android"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="19" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".DraggableGridViewSampleActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

回答1:

Make sure your project's build SDK to API level is 11 or higher.

In Eclipse/ADT you can do this in Properties -> Android -> Project Build Target or editing project.properties. After changing it, clean and rebuild.

From comments:

I right clicked on the project and click properties > java build path > libraries > I clicked add external JAR and selected and added c:\sdk\platform-tools\android-19 in project.properties I have 8

The build SDK takes precedence over project libs. BitmapFactory.Options resolves to your android-8 SDK and in there there's no inMutable field.



回答2:

Make sure that the following two changes are done:

  1. The minimum API should be at least 11 in the Android manifest file
  2. The correct API should be linked to your project, as @laalto demonstrated hour

You should have something like this in your Manifest file:

<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="19"/>

You should always target the latest API, and have the latest API linked to the project, and set the minimum as I have included to whatever your true minimum is. If you do this, you can selectively use new features in the API if available.