2013-09-22 25 views
0

嗨我正在爲教育啓動器,我有一個計算器活動和xml佈局文件,我想包含在fragmenttab2我在xml中使用include佈局,它顯示了罰款,但當我點擊一個按鈕說數字3應用程序崩潰我做錯了什麼?在Sherlock片段中包含計算器活動

fragmenttab2.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/bg" > 

    <include 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     layout="@layout/activity_calculator" /> 

    <Button 
     android:id="@+id/app" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:background="@drawable/allapps" /> 

    <Button 
     android:id="@+id/tools" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:background="@drawable/tools" /> 

    <Button 
     android:id="@+id/web" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:background="@drawable/internet" /> 

</RelativeLayout> 

計算器按鈕:

button0=(Button)findViewById(R.id.button0); 
     button1=(Button)findViewById(R.id.engery); 
     button2=(Button)findViewById(R.id.heatcal); 
     button3=(Button)findViewById(R.id.tempcal); 
     button4=(Button)findViewById(R.id.button4); 

     button5=(Button)findViewById(R.id.button5); 
     button6=(Button)findViewById(R.id.button6); 
     button7=(Button)findViewById(R.id.button7); 
     button8=(Button)findViewById(R.id.button8); 
     button9=(Button)findViewById(R.id.button9); 

     buttonPlus=(Button)findViewById(R.id.buttonPlus); 
     buttonMinus=(Button)findViewById(R.id.buttonMinus); 
     buttonMultiply=(Button)findViewById(R.id.buttonMultiply); 
     buttonDivide=(Button)findViewById(R.id.buttonDivide); 
     buttonPoint=(Button)findViewById(R.id.buttonPoint); 

     buttonEqual=(Button)findViewById(R.id.buttonEqual); 



     vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); 
     //button_del=(Button)findViewById(R.id.button_del) 

;

enter image description here

的logcat:

09-22 00:18:53.036: D/AndroidRuntime(1578): Shutting down VM 
09-22 00:18:53.036: W/dalvikvm(1578): threadid=1: thread exiting with uncaught exception (group=0x40a71930) 
09-22 00:18:53.076: E/AndroidRuntime(1578): FATAL EXCEPTION: main 
09-22 00:18:53.076: E/AndroidRuntime(1578): java.lang.IllegalStateException: Could not find a method onClickListener7(View) in the activity class com.d4a.stzh.MainActivity for onClick handler on view class android.widget.Button with id 'button7' 
09-22 00:18:53.076: E/AndroidRuntime(1578):  at android.view.View$1.onClick(View.java:3586) 
09-22 00:18:53.076: E/AndroidRuntime(1578):  at android.view.View.performClick(View.java:4204) 
09-22 00:18:53.076: E/AndroidRuntime(1578):  at android.view.View$PerformClick.run(View.java:17355) 
09-22 00:18:53.076: E/AndroidRuntime(1578):  at android.os.Handler.handleCallback(Handler.java:725) 
09-22 00:18:53.076: E/AndroidRuntime(1578):  at android.os.Handler.dispatchMessage(Handler.java:92) 
09-22 00:18:53.076: E/AndroidRuntime(1578):  at android.os.Looper.loop(Looper.java:137) 
09-22 00:18:53.076: E/AndroidRuntime(1578):  at android.app.ActivityThread.main(ActivityThread.java:5041) 
09-22 00:18:53.076: E/AndroidRuntime(1578):  at java.lang.reflect.Method.invokeNative(Native Method) 
09-22 00:18:53.076: E/AndroidRuntime(1578):  at java.lang.reflect.Method.invoke(Method.java:511) 
09-22 00:18:53.076: E/AndroidRuntime(1578):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
09-22 00:18:53.076: E/AndroidRuntime(1578):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
09-22 00:18:53.076: E/AndroidRuntime(1578):  at dalvik.system.NativeStart.main(Native Method) 
09-22 00:18:53.076: E/AndroidRuntime(1578): Caused by: java.lang.NoSuchMethodException: onClickListener7 [class android.view.View] 
09-22 00:18:53.076: E/AndroidRuntime(1578):  at java.lang.Class.getConstructorOrMethod(Class.java:460) 
09-22 00:18:53.076: E/AndroidRuntime(1578):  at java.lang.Class.getMethod(Class.java:915) 
09-22 00:18:53.076: E/AndroidRuntime(1578):  at android.view.View$1.onClick(View.java:3579) 
09-22 00:18:53.076: E/AndroidRuntime(1578): 

任何幫助將是驚人的我還是新至Android所以請不要判斷

Rapsong11

+0

在eclipse裏面找到logcat窗口。當你的應用程序崩潰時,應該有一堆紅色的文本,它解釋了什麼異常導致了你的崩潰。編輯您的問題並添加此例外文本。 – FoamyGuy

+0

將Logcat添加到說明 – rapsong11

回答

0

這是關於你的「button7.setOnClickListener() 」。你可以檢查你的button7定義,像這樣;

button_name = (Button) findviewbyId(R.id.button7); 

並且您應該在定義之後添加clicklistener。 順便說一句,如果你想定義&在你的活動中使用任何視圖,首先你應該加載所需的xml文件。使用「setContentView();

這只是一個假設,因爲我需要查看您的代碼。

也許this可以幫助你。

+0

我添加了計算器按鈕的代碼 – rapsong11

+0

我的意思是,您應該添加clicklistener部分的定義或全部。 –

相關問題