Eclipse android 主菜单,带有启动新按钮的按钮 activity(ies)

eclipse android main menu with button to start new activity(ies)

我想要一个带有按钮的主菜单,当 clicked.Please 更正我编写的代码时,每个按钮都会转到自己的选项卡,如下所示:

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainmenu);
}
public void produkdanpromobutton(View view){
    Intent Intentprodukpromo = new Intent(this , Produkpromotest.class);
    startActivity(Intentprodukpromo);
    }
public void simulasilist(View view){
    Intent Intentsimulasilist = new Intent(this , Simulasilistcode.class);
    startActivity(Intentsimulasilist);
    }
public void aboutus(View view){
    Intent Intentaboutus = new Intent(this , Aboutuscode.class);
    startActivity(Intentaboutus);
    }}

我已经在清单和 xml 布局中添加了活动,但是 它不起作用,当我在 eclipse 模拟器(android 5554 模拟器)上尝试它时,当我单击这些按钮之一时,应用程序将崩溃。

Produkpromotest.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.productpromotab);
}

Simulatorlistcode.java

@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainmenu);
    }

Simulasilistcode.java 发现布局错误: 正确的:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.simulasilisttab);
    }

Aboutuscode.java

@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.abouttab);
    }

mainmenu.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
     <Button
            android:layout_height="35sp"
            android:layout_width="90sp"
            android:layout_gravity="center"
            android:layout_marginTop="90sp"
            android:id="@+id/bprodukdanpromo"
            android:onClick="produkdanpromobutton"
            android:text="@string/produkpromo"
            android:textSize="12sp"         
            />
        <Button
            android:layout_height="35sp"
            android:layout_width="90sp"
            android:layout_gravity="center"
            android:layout_marginTop="30sp"
            android:id="@+id/bsimulasilist"
            android:onClick="simulasilist"
            android:text="@string/simulasilist"
            android:textSize="12sp"
            />
          <Button
            android:layout_height="35sp"
            android:layout_width="90sp"
            android:layout_gravity="center"
            android:layout_marginTop="30sp"
            android:id="@+id/babout"
            android:onClick="aboutus"
            android:text="@string/about"
            android:textSize="12sp"
            />
</LinearLayout>

没有错误,程序运行正常,但是当我点击按钮时它会 crash.i 一定是哪里出错了,但我不知道 where.Please 帮我解决这个问题

提前致谢, 乔治

编辑:添加 logcat

02-10 15:08:33.255: E/AndroidRuntime(371): FATAL EXCEPTION: main
02-10 15:08:33.255: E/AndroidRuntime(371): java.lang.IllegalStateException: Could not execute method of the activity
02-10 15:08:33.255: E/AndroidRuntime(371):  at android.view.View.onClick(View.java:2072)
02-10 15:08:33.255: E/AndroidRuntime(371):  at android.view.View.performClick(View.java:2408)
02-10 15:08:33.255: E/AndroidRuntime(371):  at android.view.View$PerformClick.run(View.java:8816)
02-10 15:08:33.255: E/AndroidRuntime(371):  at android.os.Handler.handleCallback(Handler.java:587)
02-10 15:08:33.255: E/AndroidRuntime(371):  at android.os.Handler.dispatchMessage(Handler.java:92)
02-10 15:08:33.255: E/AndroidRuntime(371):  at android.os.Looper.loop(Looper.java:123)
02-10 15:08:33.255: E/AndroidRuntime(371):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-10 15:08:33.255: E/AndroidRuntime(371):  at java.lang.reflect.Method.invokeNative(Native Method)
02-10 15:08:33.255: E/AndroidRuntime(371):  at java.lang.reflect.Method.invoke(Method.java:521)
02-10 15:08:33.255: E/AndroidRuntime(371):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-10 15:08:33.255: E/AndroidRuntime(371):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-10 15:08:33.255: E/AndroidRuntime(371):  at dalvik.system.NativeStart.main(Native Method)
02-10 15:08:33.255: E/AndroidRuntime(371): Caused by: java.lang.reflect.InvocationTargetException
02-10 15:08:33.255: E/AndroidRuntime(371):  at com.m4nd1r1tun45f1n4nc3.abcdefg.Mainmenucode.produkdanpromobutton(Mainmenucode.java:18)
02-10 15:08:33.255: E/AndroidRuntime(371):  at java.lang.reflect.Method.invokeNative(Native Method)
02-10 15:08:33.255: E/AndroidRuntime(371):  at java.lang.reflect.Method.invoke(Method.java:521)
02-10 15:08:33.255: E/AndroidRuntime(371):  at android.view.View.onClick(View.java:2067)
02-10 15:08:33.255: E/AndroidRuntime(371):  ... 11 more
02-10 15:08:33.255: E/AndroidRuntime(371): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.m4nd1r1tun45f1n4nc3.abcdefg/com.m4nd1r1tun45f1n4nc3.abcdefg.Produkpromotest}; have you declared this activity in your AndroidManifest.xml?
02-10 15:08:33.255: E/AndroidRuntime(371):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)

已添加Android清单:

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Loadingawalawal"
            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=".Mainmenucode"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.m4nd1r1tun45f1n4nc3.abcdefg.MAINMENUCODE" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Mastercode"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.m4nd1r1tun45f1n4nc3.abcdefg.MASTERCODE" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Productpromotest"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.m4nd1r1tun45f1n4nc3.abcdefg.PRODUCTPROMOTEST" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Simulasilistcode"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.m4nd1r1tun45f1n4nc3.abcdefg.SIMULASILISTCODE" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Aboutuscode"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.m4nd1r1tun45f1n4nc3.abcdefg.ABOUTUSCODE" />

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

Android 清单 editted:fixed Productpromotest 到 Produkpromotest, Produkpromo 测试现在有效,但另一个仍然崩溃。

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Loadingawalawal"
            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=".Mainmenucode"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.m4nd1r1tun45f1n4nc3.abcdefg.MAINMENUCODE" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Mastercode"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.m4nd1r1tun45f1n4nc3.abcdefg.MASTERCODE" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Produkpromotest"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.m4nd1r1tun45f1n4nc3.abcdefg.PRODUKPROMOTEST" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Simulasilistcode"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.m4nd1r1tun45f1n4nc3.abcdefg.SIMULASILISTCODE" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Aboutuscode"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.m4nd1r1tun45f1n4nc3.abcdefg.ABOUTUSCODE" />

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

活动似乎没有正确添加到清单中,或者拼写错误。请post清单。

您正在调用 Produkpromotest.class,但在清单中有不同。

<activity
        android:name=".Productpromotest"  //RIGHT HERE
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.m4nd1r1tun45f1n4nc3.abcdefg.PRODUCTPROMOTEST" /> //and here

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

尝试

 <activity
        android:name=".Produkpromotest"  //RIGHT HERE
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.m4nd1r1tun45f1n4nc3.abcdefg.Produkpromotest" /> //and here

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