PreferenceActivity 导致强制关闭
我有一个问题,我不知道如何解决。我有一个选项菜单,其中包含这样的代码,
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.main_menu_settings:
startActivity(new Intent(MainMenuActivity.this, BackofficePreferencesActivity.class));
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
如果我注释掉“
startActivity(new Intent(MainMenuActivity.this, BackofficePreferencesActivity.class));
我的首选项活动”这一
public class BackofficePreferencesActivity extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.preferences);
}
}
行,则不会发生错误,并且我的布局
<PreferenceCategory android:title="System Configuration">
<ListPreference
android:title="Environment"
android:summary="Select the environment"
android:key="@string/pref_current_environment"
android:defaultValue="Production"
android:entries="@array/environment_list"
android:entryValues="@array/environment_list"
android:dialogTitle="Select Environment" />
</PreferenceCategory>
我什至尝试删除列表首选项以查看屏幕是否会加载为空,但它仍然错误。在 Eclipse 中,通常我可以通过查看 LogCat 选项卡来了解出了什么问题,但由于某种原因,那里不再记录任何内容。我尝试重新启动 AVD,但没有帮助。
I have a bit of an issue that I am not sure how to fix. I have an options menu which has code like this
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.main_menu_settings:
startActivity(new Intent(MainMenuActivity.this, BackofficePreferencesActivity.class));
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
No error happens if I comment out the line
startActivity(new Intent(MainMenuActivity.this, BackofficePreferencesActivity.class));
My preferences activity looks like this
public class BackofficePreferencesActivity extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.preferences);
}
}
and my layout
<PreferenceCategory android:title="System Configuration">
<ListPreference
android:title="Environment"
android:summary="Select the environment"
android:key="@string/pref_current_environment"
android:defaultValue="Production"
android:entries="@array/environment_list"
android:entryValues="@array/environment_list"
android:dialogTitle="Select Environment" />
</PreferenceCategory>
I even tried removing the list preference to see if the screen would load empty, but it still errors. In eclipse, usually I can see what went wrong by looking in the LogCat tab, but for some reason nothing is being logged there anymore. I tried rebooting my AVD and that hasn't helped.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在清单文件中声明
Activty
。XML 代码示例:
You need to declare the
Activty
in your manifest file.Sample XML code: