0

I am new to android development and learning from udacity nanodegree That course was made in 2016. I imported an existing project and it is showing me the following,

Error: Could not initialize class com.android.sdklib.repositoryv2.AndroidSdkHandler

enter image description here

Please find the below snippet

build.gradle(app level)

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "com.example.android.miwok"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])   
    testCompile 'junit:junit:4.12'  
    compile 'com.android.support:appcompat-v7:23.3.0'   
    compile 'com.android.support:support-v4:23.3.0'
    compile 'com.android.support:design:23.3.0'
}

gradle-wrapper properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

MainActivity.java

package com.example.android.miwok;

        import android.content.Intent;
        import android.os.Bundle;
        import android.support.v7.app.AppCompatActivity;
        import android.view.View;
        import android.view.View.OnClickListener;
        import android.widget.TextView;
        
        public class MainActivity extends AppCompatActivity {
        
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
        
                // Set the content of the activity to use the activity_main.xml layout file
                setContentView(R.layout.activity_main);
        
                // Find the View that shows the numbers category
                TextView numbers = (TextView) findViewById(R.id.numbers);
        
                // Set a click listener on that View
                numbers.setOnClickListener(new OnClickListener() {
                    // The code in this method will be executed when the numbers category is clicked on.
                    @Override
                    public void onClick(View view) {
                        // Create a new intent to open the {@link NumbersActivity}
                        Intent numbersIntent = new Intent(MainActivity.this, NumbersActivity.class);
        
                        // Start the new activity
                        startActivity(numbersIntent);
                    }
                });
        
                // Find the View that shows the family category
                TextView family = (TextView) findViewById(R.id.family);
        
                // Set a click listener on that View
                family.setOnClickListener(new OnClickListener() {
                    // The code in this method will be executed when the family category is clicked on.
                    @Override
                    public void onClick(View view) {
                        // Create a new intent to open the {@link FamilyActivity}
                        Intent familyIntent = new Intent(MainActivity.this, FamilyActivity.class);
        
                        // Start the new activity
                        startActivity(familyIntent);
                    }
                });
        
                // Find the View that shows the colors category
                TextView colors = (TextView) findViewById(R.id.colors);
        
                // Set a click listener on that View
                colors.setOnClickListener(new OnClickListener() {
                    // The code in this method will be executed when the colors category is clicked on.
                    @Override
                    public void onClick(View view) {
                        // Create a new intent to open the {@link ColorsActivity}
                        Intent colorsIntent = new Intent(MainActivity.this, ColorsActivity.class);
        
                        // Start the new activity
                        startActivity(colorsIntent);
                    }
                });
        
                // Find the View that shows the phrases category
                TextView phrases = (TextView) findViewById(R.id.phrases);
        
                // Set a click listener on that View
                phrases.setOnClickListener(new OnClickListener() {
                    // The code in this method will be executed when the phrases category is clicked on.
                    @Override
                    public void onClick(View view) {
                        // Create a new intent to open the {@link PhrasesActivity}
                        Intent phrasesIntent = new Intent(MainActivity.this, PhrasesActivity.class);
        
                        // Start the new activity
                        startActivity(phrasesIntent);
                    }
                });
            }
        }

manifest file

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.miwok">
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".NumbersActivity"
            android:label="@string/category_numbers"
            android:parentActivityName=".MainActivity">
            <!-- Parent activity meta-data to support 4.0 and lower -->
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity"/>
        </activity>
        <activity
            android:name=".FamilyActivity"
            android:label="@string/category_family"
            android:parentActivityName=".MainActivity">
            <!-- Parent activity meta-data to support 4.0 and lower -->
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity"/>
        </activity>
        <activity
            android:name=".ColorsActivity"
            android:label="@string/category_colors"
            android:parentActivityName=".MainActivity">
            <!-- Parent activity meta-data to support 4.0 and lower -->
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity"/>
        </activity>
        <activity
            android:name=".PhrasesActivity"
            android:label="@string/category_phrases"
            android:parentActivityName=".MainActivity">
            <!-- Parent activity meta-data to support 4.0 and lower -->
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity"/>
        </activity>
    </application>
</manifest>
Manu
  • 4,730
  • 2
  • 20
  • 45
  • Look at this and see if it applies: https://stackoverflow.com/a/39679997/2711811 –  May 16 '21 at 02:34
  • I am not able to understand that . I am just a beginner. – Ricky Kapoor May 16 '21 at 02:39
  • The problem arises when you have multiple versions of Java installed on your machine; as some note, first use the File | Project Stucture menu to verify which SDK and JDK you intend to use. You should be using the Java that came bundled with studio. –  May 16 '21 at 02:48
  • @RickyKapoor Make Sure, you add the following lines in your build.gradle(app level) below android compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } – Manu May 16 '21 at 06:41

0 Answers0