2015-02-10 82 views
0

我想有一个按钮,主菜单,每个都会自己去标签时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> 
+1

'当我点击该按钮就会crash'请出示logcat的结果 – 2015-02-10 07:49:31

+0

请后崩溃! – 2015-02-10 07:49:45

+0

我添加了它,即时消息也是新的日食,如何一次获得logcat中的所有日志(我不得不将它保存1和合并句子)。有些日志丢失,就像那样.... 11更多。谢谢, – 2015-02-10 08:19:07

回答

0

它看起来像活动没有正确地添加到清单或他们拼写错误。请张贴清单。

您正在调用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> 
+0

添加了清单。谢谢 – 2015-02-10 08:42:17

+0

是的谢谢,错误拼写Produkpromotest Productpromotest。 “k”和“ct”。感谢thxxx – 2015-02-10 08:50:51

+0

它现在正在工作,但只有Produkpromotest。其他人仍然导致崩溃。它不是错误的拼写,我认为,任何想法? – 2015-02-10 08:55:59