不幸的是 <app><package> 已经停止在 android emulator-error ,如何解决这个问题?
Posted
技术标签:
【中文标题】不幸的是 <app><package> 已经停止在 android emulator-error ,如何解决这个问题?【英文标题】:unfortunately <app><package> has stopped in android emulator-error ,How to solve this? 【发布时间】:2013-11-14 23:37:37 【问题描述】:我是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_
android:layout_
android:background="@drawable/bg1"
>
<TableLayout
android:layout_
android:layout_
android:layout_gravity="center"
android:stretchColumns="*" >
<TableRow>
<ImageButton
android:id="@+id/imageButton1"
android:layout_
android:layout_
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_
android:layout_
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_
android:layout_
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_
android:layout_
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_
android:layout_
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_
android:layout_
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_
android:layout_
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_
android:layout_
android:text="@string/TextView" />
</LinearLayout>
请解释一下为什么会这样。告诉我解决方案
【问题讨论】:
您好,请也添加您的清单。 :) 【参考方案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,消息通常提供非常丰富的信息,您将能够比在此处发布更快地纠正错误。
【讨论】:
【参考方案2】:这是一个 ActivityNotFound 异常。
包括
<activity android:name="com.somayaji.abhi.Second" >
</activity>
在你的 Manifest 文件的 Application 标签内。
【讨论】:
【参考方案3】:声明第二个活动
<activity android:name="com.somayaji.abhi.Second" >
</activity>
在清单文件中
检查主题将其添加到清单
http://developer.android.com/training/basics/firstapp/starting-activity.html
【讨论】:
以上是关于不幸的是 <app><package> 已经停止在 android emulator-error ,如何解决这个问题?的主要内容,如果未能解决你的问题,请参考以下文章