简体   繁体   English

android无法在选项菜单中启动主要活动

[英]android unable to start Main activity in options menu

Hi there basically i have created a options menu and have one of the menu items as the home button which essentially calls the home activity Main.java. 嗨,基本上,我已经创建了一个选项菜单,并将菜单项之一作为主页按钮,该按钮实际上称为主页活动Main.java。 I have used the code 我已经使用了代码

startActivity(new Intent("org.me.myandroidstuff.Main")); startActivity(new Intent(“ org.me.myandroidstuff.Main”));

in a GetHome method. 在GetHome方法中。 My problem is that when i run this the application crashes because it isnt handled. 我的问题是,当我运行此应用程序时,由于未处理该应用程序而崩溃。 Now i know this generally means there is some error in the androidmanifest file however i think my coding is okay so im a bit stumped. 现在我知道这通常意味着androidmanifest文件中存在一些错误,但是我认为我的编码还可以,所以我有点难过。 Here is my androidmanifest.xml code 这是我的androidmanifest.xml代码

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.me.myandroidstuff"
    android:versionCode="1"
    android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" android:allowBackup="false">

**<activity
android:name=".Main"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>**

<activity
android:name=".PetrolPriceActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="org.me.myandroidstuff.PetrolPriceActivity" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<activity
android:name=".AreaURL"
android:label="@string/app_name" >
<intent-filter>
<action android:name="org.me.myandroidstuff.AreaURL" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

</application>

</manifest>

the part highlighted is the code for my main class. 突出显示的部分是我的主要课程的代码。 Im rather new to android so i imagine its a relatively simple fix but ive looked and i havent found a solution yet. 我对android来说还很陌生,所以我认为它是一个相对简单的修复程序,但是我看过并且我还没有找到解决方案。 Thanks 谢谢

change the code to 将代码更改为

startActivity(new Intent("android.intent.action.MAIN"));

In manifest file in action you have written 在清单文件中,您已经编写了

< action android:name="android.intent.action.MAIN" /> <action android:name =“ android.intent.action.MAIN” />

while calling the new Intent(String Action), you need to put the same action name. 在调用新的Intent(String Action)时,您需要输入相同的操作名称。

or you can use different signature of constructor, change the code to 或者您可以使用构造函数的不同签名,将代码更改为

startActivity(new Intent(this, Main.class);

in place of "this" you can use the appropriate context. 可以使用适当的上下文代替“ this”。

使用startActivity(new Intent(getApplicationContext(), Main.class));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM