Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Unable to instantiate activity

I'm currently using Android Studio to develop my own project for Android (my custom launcher)! The thing is, since last update (to version 0.4.0) I can't run my app.

Instead I get the following error:

FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.natercio.myhome/com.natercio.myhome.Launcher}: java.lang.ClassNotFoundException: Didn't find class "com.natercio.myhome.Launcher" on path: DexPathList[[zip file "/data/app/com.natercio.myhome-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.natercio.myhome-2, /system/lib]]
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.natercio.myhome.Launcher" on path: DexPathList[[zip file "/data/app/com.natercio.myhome-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.natercio.myhome-2, /system/lib]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)

I've searched everywhere I could remember for a solution (or something related) and tried a bunch of stuff already without any success.

  • check the "compiler.xml" (there are no excludes)
  • clean/build (error persists)
  • check the "AndroidManifest.xml" (everything seems correct)
  • recreated the whole project (only imported the code and the resources but the error persists)

One thing I did notice in this line

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.natercio.myhome.Launcher" on path: DexPathList[[zip file "/data/app/com.natercio.myhome-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.natercio.myhome-2, /system/lib]]

is that there is an "-2" (and sometimes a "-1") appended to the name of the app (both in the apk file and in the lib path) but I never really noticed this before so I can't tell for sure if this is somehow related with my problem.

Please also take in consideration that I use git and I've already tried to revert any changes to one of my previously stable commits.

UPDATE:

Has anyone else encountered this problem in Android Studio? Is there any other solution to this kind of error that I missed or is this likely to be some bug in the latest android plugin (for android studio).

UPDATE (build.gradle & manifest file):

build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion '18.1.1'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:+'
    compile 'com.android.support:support-v13:+'
    compile 'com.j256.ormlite:ormlite-android:4.47'
}

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.natercio.myhome"
          android:versionName="@string/app_version_name">

    <uses-sdk android:targetSdkVersion="17"
              android:minSdkVersion="15"/>

    <uses-permission android:name="android.permission.SET_WALLPAPER"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/Theme.Launcher">

        <service android:name=".profiler.ProfilerService"
                 android:exported="false"/>

        <activity android:name=".Launcher"
                  android:screenOrientation="portrait"
                  android:launchMode="singleTask"
                  android:description="@string/app_description">

            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.HOME"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>

        </activity>

    </application>

</manifest>
like image 788
prototyp3PT Avatar asked Oct 03 '22 00:10

prototyp3PT


2 Answers

I was having this same issue after updating Android Studio to 0.4.0. It seems overly-simplistic, but I solved the issue by simply deleting my whole /build folder (the one created before the 0.4.0 update) and rebuilding.

like image 154
Brian Avatar answered Oct 13 '22 11:10

Brian


try this java.lang.RuntimeException: Unable to instantiate activity ComponentInfo / java.lang.ClassNotFoundException

or, use the CMD to access the project and Clean your project

gradlew clean

gradlew build

like image 29
toufik3119 Avatar answered Oct 13 '22 11:10

toufik3119