ここにlogcatファイルを投稿しています。 runtimeException
エラーを解決するにはどうすればよいですか。Android:アプリケーションが予期せず停止する
package com.example.FirstProject;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
//import android.widget.EditText;
//import android.widget.RadioButton;
//import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
public class FirstProjectActivity extends Activity {
/** Called when the activity is first created. */
protected ListAdapter adapter;
Cursor cursor;
protected String[] cities = {"Mumbai"};
ListView lv ;
ListView stations;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, Open the Next Screen
if(position==0)
{
}
}
});*/
}
public void myClickHandler(View view)
{
Toast.makeText(this, "button clicked",Toast.LENGTH_LONG).show();
/*setContentView(R.layout.screen1);
ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, cities);
ListView FirstProjectActivity = (ListView) findViewById(R.id.mylist1);
FirstProjectActivity.setAdapter(adapter);*/
Intent i=new Intent(this,City.class);
i.setClass(this,City.class);
startActivity(i);
}
/*public void onListItemClick(ListView parent, View view, int position, long id) {
// super.onListItemClick(parent, view, position, id);
Toast.makeText(this, "yesss",Toast.LENGTH_LONG).show();
Intent intent = new Intent(this, List.class);
Cursor cursor = (Cursor) adapter.getItem(position);
intent.putExtra("tn", cursor.getInt(cursor.getColumnIndex("_id")));
startActivity(intent);
}*/
}
コード:私はcity.classを呼び出していた場所からクラスの
03-03 03:12:30.716: E/AndroidRuntime(880): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.FirstProject/com.example.FirstProject.City}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' Logcat:
03-03 03:46:30.607: D/AndroidRuntime(908): Shutting down VM
03-03 03:46:30.607: W/dalvikvm(908): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
03-03 03:46:30.657: E/AndroidRuntime(908): FATAL EXCEPTION: main
03-03 03:46:30.657: E/AndroidRuntime(908): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.FirstProject/com.example.FirstProject.City}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
03-03 03:46:30.657: E/AndroidRuntime(908): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-03 03:46:30.657: E/AndroidRuntime(908): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-03 03:46:30.657: E/AndroidRuntime(908): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-03 03:46:30.657: E/AndroidRuntime(908): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-03 03:46:30.657: E/AndroidRuntime(908): at android.os.Handler.dispatchMessage(Handler.java:99)
03-03 03:46:30.657: E/AndroidRuntime(908): at android.os.Looper.loop(Looper.java:123)
03-03 03:46:30.657: E/AndroidRuntime(908): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-03 03:46:30.657: E/AndroidRuntime(908): at java.lang.reflect.Method.invokeNative(Native Method)
03-03 03:46:30.657: E/AndroidRuntime(908): at java.lang.reflect.Method.invoke(Method.java:521)
03-03 03:46:30.657: E/AndroidRuntime(908): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-03 03:46:30.657: E/AndroidRuntime(908): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-03 03:46:30.657: E/AndroidRuntime(908): at dalvik.system.NativeStart.main(Native Method)
03-03 03:46:30.657: E/AndroidRuntime(908): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
03-03 03:46:30.657: E/AndroidRuntime(908): at android.app.ListActivity.onContentChanged(ListActivity.java:245)
03-03 03:46:30.657: E/AndroidRuntime(908): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
03-03 03:46:30.657: E/AndroidRuntime(908): at android.app.Activity.setContentView(Activity.java:1647)
03-03 03:46:30.657: E/AndroidRuntime(908): at com.example.FirstProject.City.onCreate(City.java:23)
03-03 03:46:30.657: E/AndroidRuntime(908): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-03 03:46:30.657: E/AndroidRuntime(908): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-03 03:46:30.657: E/AndroidRuntime(908): ... 11 more
コード:Logcatはこのエラーを示しています
package com.example.FirstProject;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class City extends ListActivity{
protected ListAdapter adapter;
Cursor cursor;
protected String[] cities = {"Mumbai"};
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.screen1);
ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, cities);
ListView FirstProjectActivity = (ListView) findViewById(R.id.mylist1);
FirstProjectActivity.setAdapter(adapter);
}
public void onListItemClick(ListView parent, View view, int position, long id) {
super.onListItemClick(parent, view, position, id);
Toast.makeText(this, "yesss",Toast.LENGTH_LONG).show();
Intent intent = new Intent(this, List.class);
Cursor cursor = (Cursor) adapter.getItem(position);
intent.putExtra("tn", cursor.getInt(cursor.getColumnIndex("_id")));
startActivity(intent);
}
}
関連コードを投稿してください。 – kosa
ねえ全員、コードを投稿して問題を解決してください。xmlなどのコードが必要な場合は、私にお知らせください.iはあなたの時間を与えるためにできるだけ早く投稿します。 – TechHelper
私が追加した答えを確認してください。 – kosa