我是android应用程序开发的新手(从昨天开始,我才开始学习android)。

我在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>


我的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>


请解释为什么会这样。告诉我解决方案

最佳答案

直接从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,消息通常非常有用,并且比在这里发布错误更容易纠正错误。

07-24 09:47
查看更多