0

嗨,我正在开发一个教育启动器,我有一个计算器活动和 xml 布局文件,我想包含在 fragmenttab2 中3 应用程序崩溃我做错了什么?

片段表2.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)

;

在此处输入图像描述

日志猫:

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还是新手所以请不要判断

说唱11

4

1 回答 1

0

这是关于你的“ button7.setOnClickListener()”。您可以像这样检查您的 button7 定义;

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

并且您应该在定义之后添加clicklistener。顺便说一句,如果您想在活动中定义和使用任何视图,首先您应该加载所需的 xml 文件。使用“ setContentView();

这只是一个假设,因为我需要查看您的代码。

也许可以帮助你。

于 2013-09-22T01:11:12.753 回答