PreferenceActivity 导致强制关闭

发布于 2024-10-19 09:27:58 字数 1495 浏览 5 评论 0原文

我有一个问题,我不知道如何解决。我有一个选项菜单,其中包含这样的代码,

@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

茶花眉 2024-10-26 09:27:58

您需要在清单文件中声明Activty

XML 代码示例:

<activity android:label="@string/sample"
        android:name=".Sample"
        android:icon="@drawable/sample">
</activity>

You need to declare the Activty in your manifest file.

Sample XML code:

<activity android:label="@string/sample"
        android:name=".Sample"
        android:icon="@drawable/sample">
</activity>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文