多くのアプリケーションのエミュレーターで「残念ながらアプリが停止しました」というエラーが発生しました。ここで述べたように、すべてのアプリケーションが同じ logcat.java ファイルを持つことができます。解決策を投稿してください。ありがとう.....
これは私のマニフェストファイルです:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.onitemclicklistener"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.onitemclicklistener.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.onitemclicklistener.MainActivity1"
android:label="@string/app_name" ></activity>
<activity
android:name="com.example.onitemclicklistener.MainActivity2"
android:label="@string/app_name" ></activity>
<activity
android:name="com.example.onitemclicklistener.MainActivity3"
android:label="@string/app_name" ></activity>
</application>
</manifest>
Logcat.java
05-21 13:45:40.194: E/AndroidRuntime(1380): FATAL EXCEPTION: main
05-21 13:45:40.194: E/AndroidRuntime(1380): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.onitemclicklistener/com.example.onitemclicklistener.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
05-21 13:45:40.194: E/AndroidRuntime(1380): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
05-21 13:45:40.194: E/AndroidRuntime(1380): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-21 13:45:40.194: E/AndroidRuntime(1380): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-21 13:45:40.194: E/AndroidRuntime(1380): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-21 13:45:40.194: E/AndroidRuntime(1380): at android.os.Handler.dispatchMessage(Handler.java:99)
05-21 13:45:40.194: E/AndroidRuntime(1380): at android.os.Looper.loop(Looper.java:137)
05-21 13:45:40.194: E/AndroidRuntime(1380): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-21 13:45:40.194: E/AndroidRuntime(1380): at java.lang.reflect.Method.invokeNative(Native Method)
05-21 13:45:40.194: E/AndroidRuntime(1380): at java.lang.reflect.Method.invoke(Method.java:511)
05-21 13:45:40.194: E/AndroidRuntime(1380): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-21 13:45:40.194: E/AndroidRuntime(1380): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-21 13:45:40.194: E/AndroidRuntime(1380): at dalvik.system.NativeStart.main(Native Method)
05-21 13:45:40.194: E/AndroidRuntime(1380): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
05-21 13:45:40.194: E/AndroidRuntime(1380): at android.app.ListActivity.onContentChanged(ListActivity.java:243)
05-21 13:45:40.194: E/AndroidRuntime(1380): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:254)
05-21 13:45:40.194: E/AndroidRuntime(1380): at android.app.Activity.setContentView(Activity.java:1835)
05-21 13:45:40.194: E/AndroidRuntime(1380): at com.example.onitemclicklistener.MainActivity.onCreate(MainActivity.java:22)
05-21 13:45:40.194: E/AndroidRuntime(1380): at android.app.Activity.performCreate(Activity.java:4465)
05-21 13:45:40.194: E/AndroidRuntime(1380): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-21 13:45:40.194: E/AndroidRuntime(1380): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-21 13:45:40.194: E/AndroidRuntime(1380): ... 11 more
05-21 13:45:40.554: I/dalvikvm(1380): threadid=3: reacting to signal 3
05-21 13:45:40.584: I/dalvikvm(1380): Wrote stack traces to '/data/anr/traces.txt'
05-21 13:45:40.924: I/dalvikvm(1380): threadid=3: reacting to signal 3
05-21 13:45:41.034: I/dalvikvm(1380): Wrote stack traces to '/data/anr/traces.txt'
05-21 13:45:56.044: I/Process(1380): Sending signal. PID: 1380 SIG: 9
MainActivity.java
package com.example.onitemclicklistener;
import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends ListActivity {
String [] ipl=new String[]{"chennai","mumbai","rajasthan"};
ListView lv;
final Context con=this;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv=(ListView)findViewById(R.id.list);
lv=getListView();
lv.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,ipl));
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> Parent, View v, int Position,
long id) {
Intent i=null;
switch(Position)
{
case 0:
i=new Intent(getApplicationContext(),MainActivity1.class);
startActivity(i);
break;
case 1:
i=new Intent(getApplicationContext(),MainActivity2.class);
startActivity(i);
break;
case 2:
i=new Intent(getApplicationContext(),MainActivity3.class);
startActivity(i);
break;
};
}
});
}
}