2013-11-04 28 views
0

我是新來android應用程序開發(從昨天我纔開始學習android)。不幸<app><package>已經停在android emulator-error中,如何解決這個問題?

我在AVD中收到消息 - 很不幸停止了,請幫我解決這個錯誤,我想在android中學習更多但被這個錯誤吸住.. plz..plz ..幫我解決這個問題。

我的MainActivity是

public class MainActivity extends Activity { 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    ImageButton mb=(ImageButton) findViewById(R.id.imageButton1); 
    ImageButton mc=(ImageButton) findViewById(R.id.imageButton2); 
    ImageButton me=(ImageButton) findViewById(R.id.imageButton3); 
    ImageButton mf=(ImageButton) findViewById(R.id.imageButton4); 
    ImageButton mg=(ImageButton) findViewById(R.id.imageButton5); 
    ImageButton mh=(ImageButton) findViewById(R.id.imageButton6); 

    mb.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
Intent activityChangeIntent= new Intent(MainActivity.this,Second.class);    
MainActivity.this.startActivity(activityChangeIntent); 

     } 
    }); 
    mc.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      startActivity(new Intent(MainActivity.this,Second.class)); 

     } 
    }); 


      me.setOnClickListener(new OnClickListener() { 

    @Override 
    public void onClick(View v) { 
     // TODO Auto-generated method stub 
     startActivity(new Intent(MainActivity.this,Second.class)); 

    } 
}); 



     mf.setOnClickListener(new OnClickListener() { 

    @Override 
    public void onClick(View v) { 
     // TODO Auto-generated method stub 
     startActivity(new Intent(MainActivity.this,Second.class)); 

    } 
}); 
    mg.setOnClickListener(new OnClickListener() { 

    @Override 
    public void onClick(View v) { 
     // TODO Auto-generated method stub 
     startActivity(new Intent(MainActivity.this,Second.class)); 

    } 
}); 


      mh.setOnClickListener(new OnClickListener() { 

    @Override 
    public void onClick(View v) { 
     // TODO Auto-generated method stub 
     startActivity(new Intent(MainActivity.this,Second.class)); 

    } 
}); 


} 

} 

我的MainActivity XML是:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
      android:layout_height="match_parent" 
     android:background="@drawable/bg1" 

      > 
     <TableLayout 
     android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:stretchColumns="*" > 

     <TableRow> 


    <ImageButton 
    android:id="@+id/imageButton1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="5dp" 
    android:layout_marginRight="2dp" 
    android:layout_marginLeft="5dp" 
    android:layout_marginTop="0dp" 
    android:scaleType="fitCenter" 
    android:background="@drawable/mob1" /> 

    <ImageButton 
    android:id="@+id/imageButton2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="20dp" 
    android:layout_marginLeft="2dp" 
    android:layout_marginRight="5dp" 
    android:layout_marginTop="0dp" 
    android:padding="20dp" 
    android:scaleType="fitCenter" 
    android:background="@drawable/cam1" /> 

    </TableRow> 
    <TableRow > 


    <ImageButton 
    android:id="@+id/imageButton3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="5dp" 
    android:layout_marginRight="2dp" 
    android:layout_marginLeft="5dp" 
    android:layout_marginTop="0dp" 
    android:scaleType="fitCenter" 
    android:background="@drawable/comp" /> 

    <ImageButton 
    android:id="@+id/imageButton4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="20dp" 
    android:layout_marginLeft="2dp" 
    android:layout_marginRight="5dp" 
    android:layout_marginTop="0dp" 
    android:padding="20dp" 
    android:scaleType="fitCenter" 
    android:background="@drawable/watch1" /> 

    </TableRow> 
<TableRow > 



    <ImageButton 
    android:id="@+id/imageButton5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="5dp" 
    android:layout_marginRight="2dp" 
    android:layout_marginLeft="5dp" 
    android:layout_marginTop="0dp" 
    android:scaleType="fitCenter" 
    android:background="@drawable/abt1" /> 

    <ImageButton 
    android:id="@+id/imageButton6" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="20dp" 
    android:layout_marginLeft="2dp" 
    android:layout_marginRight="5dp" 
    android:layout_marginTop="0dp" 
    android:padding="20dp" 
    android:scaleType="fitCenter" 
    android:background="@drawable/contact1" /> 

    </TableRow> 

    </TableLayout> 

</LinearLayout> 

MY logcat的是:

11-04 05:14:36.971: E/AndroidRuntime(1088): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.somayaji.abhi/com.somayaji.abhi.Second}; have you declared this activity in your AndroidManifest.xml? 
11-04 05:14:36.971: E/AndroidRuntime(1088):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628) 
11-04 05:14:36.971: E/AndroidRuntime(1088):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424) 
11-04 05:14:36.971: E/AndroidRuntime(1088):  at android.app.Activity.startActivityForResult(Activity.java:3423) 
11-04 05:14:36.971: E/AndroidRuntime(1088):  at android.app.Activity.startActivityForResult(Activity.java:3384) 
11-04 05:14:36.971: E/AndroidRuntime(1088):  at android.app.Activity.startActivity(Activity.java:3626) 
11-04 05:14:36.971: E/AndroidRuntime(1088):  at android.app.Activity.startActivity(Activity.java:3594) 
11-04 05:14:36.971: E/AndroidRuntime(1088):  at com.somayaji.abhi.MainActivity$1.onClick(MainActivity.java:40) 
11-04 05:14:36.971: E/AndroidRuntime(1088):  at android.view.View.performClick(View.java:4424) 
11-04 05:14:36.971: E/AndroidRuntime(1088):  at android.view.View$PerformClick.run(View.java:18383) 
11-04 05:14:36.971: E/AndroidRuntime(1088):  at android.os.Handler.handleCallback(Handler.java:733) 
11-04 05:14:36.971: E/AndroidRuntime(1088):  at android.os.Handler.dispatchMessage(Handler.java:95) 
11-04 05:14:36.971: E/AndroidRuntime(1088):  at android.os.Looper.loop(Looper.java:137) 
11-04 05:14:36.971: E/AndroidRuntime(1088):  at android.app.ActivityThread.main(ActivityThread.java:4998) 
11-04 05:14:36.971: E/AndroidRuntime(1088):  at java.lang.reflect.Method.invokeNative(Native Method) 
11-04 05:14:36.971: E/AndroidRuntime(1088):  at java.lang.reflect.Method.invoke(Method.java:515) 
11-04 05:14:36.971: E/AndroidRuntime(1088):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777) 
11-04 05:14:36.971: E/AndroidRuntime(1088):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 
11-04 05:14:36.971: E/AndroidRuntime(1088):  at dalvik.system.NativeStart.main(Native Method) 
11-04 05:14:49.691: I/Process(1088): Sending signal. PID: 1088 SIG: 9 

我的第二個活動是

public class Second extends Activity{ 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.mpage); 
    } 
    } 

我的第二個活動XML是:

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/TextView" /> 

    </LinearLayout> 

PLZ ..解釋爲什麼我得到這樣的..告訴我解決

+0

你好請加你的清單。 :) –

回答

1

直接從logcat的:

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.somayaji.abhi/com.somayaji.abhi.Second}; have you declared this activity in your AndroidManifest.xml? 

你忘了在清單xml文件中聲明您的Second活動。

嘗試閱讀logcat,消息通常非常豐富,您可以更快地糾正錯誤,而不是在此處發佈。

+0

雅...它解決了謝謝... – somayaji

+0

@somayaji如果答案有助於標記這個答案被接受 – Raghunandan

1

這是一個ActivityNotFound例外。

包括

<activity android:name="com.somayaji.abhi.Second" > 
</activity> 

您的清單文件中的應用標籤內。

相關問題