Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
484 views
in Technique[技术] by (71.8m points)

java - Call requires API level 11(current min is 8) android.app.Activity#onCreateView

I am a newbie to android, and I am developing an android application. But my package line gives this error in MainActivity.java class. Could anyone please tell me the reason of this?. This is my class and the package line gives this error.

package com.example.eventgyaam;


import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity  {

int counter;

Button add,sub;
TextView display;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    counter = 0;
    add = (Button) findViewById(R.id.bAdd);
    sub = (Button) findViewById(R.id.bSub);
    display = (Button) findViewById(R.id.tvDisplay);
    add.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            counter++;
            display.setText("Your total is "+counter);
        }
    });
    sub.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            counter--;
            display.setText("Your total is "+counter);
        }
    });

}
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For each Android API, there might be new features added, which can't work on lower API versions. Thus, to fix this, you can just increase the minimum required API in your project.

In your build.gradle (app-module), you will find this line:

minSdkVersion 8

Change it to:

minSdkVersion 11

If you didn't find this line in build.gradle, check your AndroidManifest.xml and change the minSdkVersion from 8 to 11 or whatever you want:

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

But now your app will only work on API 11+, which is fine. Nobody uses below API 11 these days, so it shouldn't be a problem for you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...