Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

android

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);
        }
    });

}
}
like image 814
Manoj Majumdar Avatar asked Aug 24 '15 11:08

Manoj Majumdar


People also ask

What is the minimum API level that the Android application supports?

When you upload an APK, it must meet Google Play's target API level requirements. New apps must target Android 12 (API level 31) or higher; except for Wear OS apps, which must target Android 11 (API level 30) or higher.

What is API level in Android Apps?

What is API Level? API Level is an integer value that uniquely identifies the framework API revision offered by a version of the Android platform. The Android platform provides a framework API that applications can use to interact with the underlying Android system.

How do I change minimum API levels?

Step 1: Open your Android Studio, and go to Menu. File >Project Structure. Step 2: In project Structure window, select app module in the list given on left side. Step 3: Select the Flavors tab and under this you will have an option for setting “Min Sdk Version” and for setting “Target Sdk Version”.

Why do we need API level in Android?

Declaring a minimum API Level This ensures that users will only be able to install your application if their devices are running a compatible version of the Android platform. In turn, this ensures that your application can function properly on their devices.


1 Answers

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.

like image 132
Hussein El Feky Avatar answered Oct 19 '22 23:10

Hussein El Feky