我想有一個按鈕,主菜單,每個都會自己去標籤時clicked.Please更正代碼我已經做出,下面(IES):日食的android主菜單與按鈕開始新的活動
@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$1.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$1.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)
新增AndroidManifest:
<?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:固定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>
'當我點擊該按鈕就會crash'請出示logcat的結果 – 2015-02-10 07:49:31
請後崩潰! – 2015-02-10 07:49:45
我添加了它,即時消息也是新的日食,如何一次獲得logcat中的所有日誌(我不得不將它保存1和合並句子)。有些日誌丟失,就像那樣.... 11更多。謝謝, – 2015-02-10 08:19:07