Menu というクラスを作成しました。ユーザーがメニューボタンを押すと、3つのオプションが表示されます。について、設定と終了。設定をクリックすると、設定アクティビティが開かれるはずです。ただし、アプリがクラッシュし、設定アクティビティを開くことができません。マニフェストとログファイルで開こうとしているアクティビティのアクティビティ タグである ListActivity を投稿しました。助けてください。
public class Menu extends ListActivity {
String[] list = { "StartView", "FunWithText", "Email", "Camera",
"ActivityStarter" };
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
try {
Class myClass = Class.forName("com.thenewboston.terry."
+ list[position]);
Intent myIntent = new Intent(Menu.this, myClass);
startActivity(myIntent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this,
android.R.layout.simple_list_item_1, list));
}
@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater balloon = getMenuInflater();
balloon.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case (R.id.about):
Intent myIntent = new Intent(Menu.this, Dialogue.class);
startActivity(myIntent);
break;
case (R.id.preferences):
Intent prefs = new Intent(Menu.this, Preferences.class);
startActivity(prefs);
break;
case (R.id.exit):
finish();
break;
}
return false;
}
}
マニフェスト.xml:
<activity
android:name=".Preferences"
android:label="Start Activity"
android:theme="@android:style/Theme.Dialog" >
<intent-filter>
<action android:name="com.thenewboston.terry.PREFS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
エラーログ:
07-18 00:39:07.133: E/AndroidRuntime(738): FATAL EXCEPTION: main
07-18 00:39:07.133: E/AndroidRuntime(738): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thenewboston.terry/com.thenewboston.terry.Preferences}: android.view.InflateException: Binary XML file line #14: Error inflating class listPreference
07-18 00:39:07.133: E/AndroidRuntime(738): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-18 00:39:07.133: E/AndroidRuntime(738): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-18 00:39:07.133: E/AndroidRuntime(738): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-18 00:39:07.133: E/AndroidRuntime(738): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-18 00:39:07.133: E/AndroidRuntime(738): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 00:39:07.133: E/AndroidRuntime(738): at android.os.Looper.loop(Looper.java:123)
07-18 00:39:07.133: E/AndroidRuntime(738): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-18 00:39:07.133: E/AndroidRuntime(738): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 00:39:07.133: E/AndroidRuntime(738): at java.lang.reflect.Method.invoke(Method.java:521)
07-18 00:39:07.133: E/AndroidRuntime(738): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-18 00:39:07.133: E/AndroidRuntime(738): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-18 00:39:07.133: E/AndroidRuntime(738): at dalvik.system.NativeStart.main(Native Method)
07-18 00:39:07.133: E/AndroidRuntime(738): Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class listPreference
07-18 00:39:07.133: E/AndroidRuntime(738): at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:441)
07-18 00:39:07.133: E/AndroidRuntime(738): at android.preference.GenericInflater.rInflate(GenericInflater.java:481)
07-18 00:39:07.133: E/AndroidRuntime(738): at android.preference.GenericInflater.inflate(GenericInflater.java:326)
07-18 00:39:07.133: E/AndroidRuntime(738): at android.preference.GenericInflater.inflate(GenericInflater.java:263)
07-18 00:39:07.133: E/AndroidRuntime(738): at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:251)
07-18 00:39:07.133: E/AndroidRuntime(738): at android.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:262)
07-18 00:39:07.133: E/AndroidRuntime(738): at com.thenewboston.terry.Preferences.onCreate(Preferences.java:12)
07-18 00:39:07.133: E/AndroidRuntime(738): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-18 00:39:07.133: E/AndroidRuntime(738): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-18 00:39:07.133: E/AndroidRuntime(738): ... 11 more
07-18 00:39:07.133: E/AndroidRuntime(738): Caused by: java.lang.ClassNotFoundException: android.preference.listPreference in loader dalvik.system.PathClassLoader[/data/app/com.thenewboston.terry-1.apk]
07-18 00:39:07.133: E/AndroidRuntime(738): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
07-18 00:39:07.133: E/AndroidRuntime(738): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
07-18 00:39:07.133: E/AndroidRuntime(738): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
07-18 00:39:07.133: E/AndroidRuntime(738): at android.preference.GenericInflater.createItem(GenericInflater.java:375)
07-18 00:39:07.133: E/AndroidRuntime(738): at android.preference.GenericInflater.onCreateItem(GenericInflater.java:417)
07-18 00:39:07.133: E/AndroidRuntime(738): at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:428)
07-18 00:39:07.133: E/AndroidRuntime(738): ... 19 more
**Preferences xml:** <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceCategory android:title="Label"> <EditTextPreference android:title="EditText" android:key="name" android:summary="Enter your name"/> <CheckBoxPreference android:title="checkBox" android:key="music" android:defaultValue="true" android:summary="music on?" /> <listPreference android:title="list" android:key="list" android:summary="Choose somethign" android:entries="@array/list" android:entryValues="@array/values" /> </PreferenceCategory> </PreferenceScreen>
public class Preferences extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs);
}
}