2016-11-25 82 views
-1

我收到錯誤「無法啓動活動ComponentInfo」。StartActivitity上的崩潰()Android Apps

當我打電話start_salud功能:

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

它崩潰的startActivity(intent)

我把它從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); 
    } 
} 

配音結果:

 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> 

貓日誌:

11-25 20:17:31.924 29226-29226/com.alertavecino.alertavecino E /合子:MountEmulatedStorage() 11-25 20:17:31.924 29226-29226/com.alertavecino .alertavecino E /合子:V2 11-25 20:17:31.944 29226-29226/com.alertavecino.alertavecino E/SELinux的:[DEBUG] get_category:可變seinfo:默認靈敏度:NULL,cateogry:NULL

+1

發佈崩潰日誌請 – Jon

+1

發佈您的LogCat –

+0

你可以發佈你的清單嗎?疑似。 –

回答

0

您需要在清單中聲明您的活動以便能夠啓動它。

以下添加到您的manifest.xml文件的<application>標籤內:

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

這將使你的活動開始,並從設備中的應用程序列表中的活動可發射。

0

您必須在清單中註冊所有活動,您可以這樣做:

<?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> 
     <activity android:name=".salud" > 
    </activity> 
    </application> 

</manifest> 

還請檢查this linkofficial docs