lorena lorena - 10 months ago 90
Android Question

Crashes on StartActivitity() Android Apps

I am getting the error "Unable to start activity ComponentInfo".

When I call start_salud function:

public void start_salud(View view) {
Intent intent = new Intent(MainActivity.this, salud.class);
startActivity(intent);
}


It crashes on
startActivity(intent)


I call it from
android:onClick="start_salud"
.

salud_class:

package com.alertavecino.alertavecino;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;

import java.util.ArrayList;

public class salud extends AppCompatActivity {
ArrayList<String> listDiseases;

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


Dubbing results:

if (mResolvedMethod == null) { // <-- This statment is true
resolveMethod(mHostView.getContext(), mMethodName);
}

try {
mResolvedMethod.invoke(mResolvedContext, v); // <-- Here it's crashes
} catch (IllegalAccessException e) {
throw new IllegalStateException(
"Could not execute non-public method for android:onClick", e);
} catch (InvocationTargetException e) {
throw new IllegalStateException(
"Could not execute method for android:onClick", e);
}


Manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alertavecino.alertavecino">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="Alerta Vecino!"
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>
</application>

</manifest>


Cat Log:

11-25 20:17:31.924 29226-29226/com.alertavecino.alertavecino E/Zygote: MountEmulatedStorage()
11-25 20:17:31.924 29226-29226/com.alertavecino.alertavecino E/Zygote: v2
11-25 20:17:31.944 29226-29226/com.alertavecino.alertavecino E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL

Answer Source

You need to declare your activity in the manifest in order for it to be able to be started.

Add the following to your manifest.xml file inside the <application> tags:

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

This will allow your activity to be started, and also make the activity launchable from the device app list.