我是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>
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,消息通常非常丰富,您可以更快地纠正错误,而不是在此处发布。
答案 1 :(得分:1)
宣布第二项活动
<activity android:name="com.somayaji.abhi.Second" >
</activity>
清单文件中的
检查主题将其添加到清单
http://developer.android.com/training/basics/firstapp/starting-activity.html
答案 2 :(得分:1)
这是一个ActivityNotFound异常。
包括
<activity android:name="com.somayaji.abhi.Second" >
</activity>
在您的清单文件的Application标记内。