Error : Unable to instantiate Activity Componentinfo

Asked

Viewed 528 times

0

Guys I need to create an App, I’m still new in android, and I’m with the following error, and I’m not finding the solution. I even searched here on the forum. Anyone know what it might be? Error:

10-07 17:10:53.950 10339-10339/com.example.cristianhaas.myapplication E/Androidruntime: FATAL EXCEPTION: main Process: com.example.cristianhaas.myapplication, PID: 10339 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.cristianhaas.myapplication/com.example.cristianhaas.myapplication.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.cristianhaas.myapplication.MainActivity" on path: Dexpathlist[[zip file "/data/app/com.example.cristianhaas.myapplication-2/base.apk", zip file "/data/app/com.example.cristianhaas.myapplication-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.cristianhaas.myapplication-2/lib/arm, /vendor/lib, /system/lib]] at android.app.Activitythread.performLaunchActivity(Activitythread.java:2345) at android.app.Activitythread.handleLaunchActivity(Activitythread.java:2500) at android.app.Activitythread.access$900(Activitythread.java:163) at android.app.Activitythread$H.handleMessage(Activitythread.java:1362) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.Activitythread.main(Activitythread.java:5585) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:730) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:620) Caused by: java.lang.Classnotfoundexception: Didn’t find class "com.example.cristianhaas.myapplication.Mainactivity" on path: Dexpathlist[[zip file "/data/app/com.example.cristianhaas.myapplication-2/base.apk", zip file "/data/app/com.example.cristianhaas.myapplication-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.cristianhaas.myapplication-2/lib/arm, /vendor/lib, /system/lib]] at Dalvik.system.Basedexclassloader.findClass(Basedexclassloader.java:56) at java.lang.Classloader.loadClass(Classloader.java:511) at java.lang.Classloader.loadClass(Classloader.java:469) at android.app.Instrumentation.newActivity(Instrumentation.java:1068) at android.app.Activitythread.performLaunchActivity(Activitythread.java:2335) at android.app.Activitythread.handleLaunchActivity(Activitythread.java:2500)  at android.app.Activitythread.access$900(Activitythread.java:163)  at android.app.Activitythread$H.handleMessage(Activitythread.java:1362)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.Activitythread.main(Activitythread.java:5585)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:730)  at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:620)  Suppressed: java.lang.Noclassdeffounderror: com.example.cristianhaas.myapplication.Mainactivity at Dalvik.system.Dexfile.defineClassNative(Native Method) at Dalvik.system.Dexfile.defineClass(Dexfile.java:226) at Dalvik.system.Dexfile.loadClassBinaryName(Dexfile.java:219) at Dalvik.system.Dexpathlist.findClass(Dexpathlist.java:338) at Dalvik.system.Basedexclassloader.findClass(Basedexclassloader.java:54) ... 13 more Suppressed: java.lang.Classnotfoundexception: com.example.cristianhaas.myapplication.Mainactivity at java.lang.Class.classForName(Native Method) at java.lang.Bootclassloader.findClass(Classloader.java:781) at java.lang.Bootclassloader.loadClass(Classloader.java:841) at java.lang.Classloader.loadClass(Classloader.java:504) ... 12 more

Mainactivity.java

package com.example.cristianhaas.myapplication;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;


public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tela_inicial);

    Button bttCheguei = (Button) findViewById(R.id.credenciar);
    Button bttQrcode = (Button) findViewById(R.id.bttqrcode);
    bttQrcode.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent it = new Intent(MainActivity.this, LeitorQRCode.class);
            startActivity(it);
        }
    });
    bttCheguei.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent it = new Intent(MainActivity.this, ViewProjeto.class);
            startActivity(it);
        }
    });
    Button bttConhecerProjetos = (Button) findViewById(R.id.projetos);
    bttConhecerProjetos.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent it = new Intent(MainActivity.this, Projeto.class);
            startActivity(it);
        }
    });

}
}

Androidmanifest.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.cristianhaas.myapplication">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-permission android:name="android.permission.FLASHLIGHT" />

<application
    android:allowBackup="true"
    android:fullBackupContent="false"
    android:hardwareAccelerated="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.gms.vision.DEPENDENCIES"
        android:value="barcode" />

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

        </intent-filter>
    </activity>
    <activity
        android:name=".SegundaTela"
        android:label="@string/app_name">

        <intent-filter>
            <action android:name="com.emanuel.teste.AJUDA" />
            <category android:name="android.intent.category.DEFAULT" />

        </intent-filter>
    </activity>
    <activity
        android:name=".ViewProjeto"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name=".ViewProjeto" />
            <category android:name="android.intent.category.DEFAULT" />

        </intent-filter>
    </activity>
    <activity
        android:name=".Projeto"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name=".Projeto" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

    </activity>
    <activity
        android:name=".LeitorQRCode"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name=".LeitorQRCode" />
            <category android:name="android.intent.category.DEFAULT" />

        </intent-filter>

    </activity>
    <activity
        android:name=".BarcodeCaptureActivity"
        android:label="Read Barcode" />

</application>

Thanks in advance, any help!!

  • Here compiled and ran without any problem. What exactly causes the error?

  • @Pauloalmeida, it doesn’t even open the Home screen. And it displays the message that stopped working

  • Ok, so better isolate the error because the problem is not in this code that you gave me. Create a new project just with it and see for yourself.

  • @Pabloalmeisa, thanks for the help, I did what you said, I was sifting to find where the error was, because I thought the error log was there in main. With this I come to the conclusion that PHP > Java haha Thanks

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.