安卓:开始从选项菜单活动选项、菜单

2023-09-12 06:01:53 作者:大雨冲刷记忆中的沙i

我想从启动选项菜单的活动,但我的应用程序不断崩溃。我收到的唯一的错误是ActivityThread.performLaunchActivity(ActivityThread $ ActivityRecord,意图)在Eclipse中的调试窗口错误。

I am trying to start an activity from an options menu, but my app keeps crashing. The only error that I receive is an ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord,Intent) error in the debug window in Eclipse.

下面是在code,我现在用的那一刻,但请记住,我曾尝试多种选择,所有这一切结束在相同的苦难,在同一块code的 - 的startActivity声明(通过使用断点发现,因为我不知道怎么看,在LogCat中窗口中的堆栈跟踪,因为在我的previous问题Android/Eclipse:协助LogCat中)。

Below is the the code that I am using at the moment, but keep in mind I have tried multiple options, all of which end in the same misery, at the same piece of code - the startActivity statement (discovered by using breakpoints, since I'm not sure how to see the stack trace in the LogCat window, as described in my previous question Android/Eclipse: assistance with LogCat).

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.changescheme, menu);
    menu.findItem(R.id.changeScheme).setIntent(new Intent(this, ColourActivity.class));
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);
    this.closeOptionsMenu();
    startActivity(item.getIntent());
    return true;
}

这里是changescheme.xml文件:

And here is the changescheme.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/changeScheme" android:title="Change Colour Scheme" android:icon="@android:drawable/ic_menu_edit"></item>
</menu>

我也尝试过使用一个开关作为onCreateOptionsMenu块反对menu.findItem的onOptionsItemSelected块(item.getItemId())语句,但仍没有运气。

I have also tried using a switch(item.getItemId()) statement in the onOptionsItemSelected block as opposed to the menu.findItem in the onCreateOptionsMenu block, but still no luck.

我定义我的清单文件中的活动。我也可以从一个普通按钮启动该活动,并在第一时间应用程序打开一个设备上,该活动是我的启动画面后,立即开始了,我有没有问题,以下两种方法之一。

I have defined the activity in my Manifest file. I can also start the activity from a regular button, and the first time the app opens on a device, the activity is started immediately after my splash screen, and I have had no problems with either of these methods.

对我来说这表明,有没有错ColourActivity类或与其相关的布局文件,但与从选项菜单中执行情况​​的问题。

To me this indicates that there is nothing wrong with the ColourActivity class or its associated layout file, but there is a problem with the implementation from the options menu.

我也实施了同样的方法,如上图所示(以code)在不同的应用程序,并没有任何问题,所以我真的在这里损失。

I have also implemented this same method as shown above (in code) in a different app and had no problems, so I'm am really at a loss here.

所有帮助将大大AP preciated。

All help will be greatly appreciated.

谢谢,亚当。

推荐答案

我现在已经解决了这个问题。

I have solved the problem now.

原来,这个问题是不是在所有的 ListActivity 类,它实际上是在 Col​​ourActivity 类。

It turns out the problem was not at all on the ListActivity class, it was in fact on the ColourActivity class.

我尝试分析一些颜色的onCreate ,但我忘了包括#的RGB颜色字符串之一,因此崩溃!

I was attempting to parse a few colours in onCreate, but I had forgotten to include the # in one of the RGB colour strings, hence the crash!

感谢堆大家的帮助,亚当。

Thanks heaps for everyone's help, Adam.