-1

当我按下应用程序上的任何按钮时,会出现“不幸的是,(应用程序名称)已停止”。我正在使用日食。我使用另一个类似的[项目]:http ://android.okhelp.cz/dw/Calculator.apk我改变了一些东西。原始项目有效,但这个不是 http://android.okhelp.cz/calculator-open-source/

<?xml version="1.0" encoding="utf-8"?>
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="fill_parent"
        android:layout_height="130dp"
        android:clickable="false"
        android:cursorVisible="false"
        android:gravity="right"
       />
</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button_sin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onClickListener_sin"
        android:clickable="true"
        android:text="sin" />

    <Button
        android:id="@+id/button_cos"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onClickListener_cos"
        android:clickable="true"
        android:text="cos" />

    <Button
        android:id="@+id/button_del"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1.40"
        android:onClick="onClickListenerReset"
        android:text="Delete" />

</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button_tan"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:onClick="onClickListener_tan"
        android:text="tan" />

    <Button
        android:id="@+id/button7"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:onClick="onClickListener7"
        android:text="7" />

    <Button
        android:id="@+id/button8"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:onClick="onClickListener8"
        android:text="8" />

    <Button
        android:id="@+id/button9"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1.00"
        android:onClick="onClickListener9"
        android:text="9" />

    <Button
        android:id="@+id/buttonDivide"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1.00"
        android:onClick="onClickListenerDivide"
        android:text="/" />
</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button_log"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:onClick="onClickListener_log"
        android:text="log" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:onClick="onClickListener4"
        android:text="4" />

    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:onClick="onClickListener5"
        android:text="5" />

    <Button
        android:id="@+id/button6"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1.00"
        android:onClick="onClickListener6"
        android:text="6" />

    <Button
        android:id="@+id/buttonMultiply"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1.00"
        android:onClick="onClickListenerMultiply"
        android:text="*" />
</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button_bra1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:onClick="onClickListener_bra1"
        android:text="(" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:onClick="onClickListener1"
        android:text="1" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:onClick="onClickListener2"
        android:text="2" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1.00"
        android:onClick="onClickListener3"
        android:text="3" />

    <Button
        android:id="@+id/buttonMinus"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1.00"
        android:onClick="onClickListenerMinus"
        android:text="-" />
</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button_bra2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:onClick="onClickListener_bra2"
        android:text=")" />

    <Button
        android:id="@+id/buttonPoint"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:onClick="onClickListenerPoint"
        android:text="." />

    <Button
        android:id="@+id/button0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:onClick="onClickListener0"
        android:text="0" />

    <Button
        android:id="@+id/buttonEqual"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:onClick="onClickListenerEqual"
        android:text="="
        android:textSize="15sp" />

    <Button
        android:id="@+id/buttonPlus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:onClick="onClickListenerPlus"
        android:text="+"
        android:textSize="15dp" />
</LinearLayout>

jave 文件

package calc.pack;


import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;


public class MainActivity extends Activity {
EditText editText;

Button button0,button1,button2,button3,
       button4,button5,button6,button7,button8,button9,buttonPlus,buttonMinus,buttonMultiply,
            buttonDivide,buttonEqual,buttonPoint,buttonDel,buttonReset,
            button_sin,button_cos,button_tan,button_del,button_bra1,button_bra2,button_reset;

String sum="",one,two,three,four,five,
                        six,seven,eight,nine,
                        zero,plus,minus,multiply,divide,equal,point,del,reset,bra1,bra2;

Integer countOne=0;

Float result=0f,result_mul=1f,result_div=1f;

int pressCount=1,sumZero,c,i;

char press;

String EditTextMsg;

Float floatEditTextMsg;

Double after_log,doubleEditTextMsg,afterSin,after_cos,after_tan,toRadian_doubleEditTextMsg;

Vibrator vibrator;
Bundle savedInstanceState;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);




    editText=(EditText)findViewById(R.id.editText1);

    button0=(Button)findViewById(R.id.button0);
    button1=(Button)findViewById(R.id.button1);
    button2=(Button)findViewById(R.id.button2);
    button3=(Button)findViewById(R.id.button3);
    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);

    button_sin=(Button)findViewById(R.id.button_sin);
    button_cos=(Button)findViewById(R.id.button_cos);
    button_tan=(Button)findViewById(R.id.button_tan);

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

    vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); 


    editText.setText(result.toString());


}
public void onClickListener0(View v)
{
    vibrator.vibrate(30);
    if(press=='=')
    {
        onClickListenerReset(buttonReset);
    }

    if(sum !="")
    {
        zero=(String)button0.getText();

        sum=sum+zero;
        editText.setText(sum);
    }
    else
    {
        sum="0";
        editText.setText("0");
    }
}

public void onClickListener1(View v)
{
    vibrator.vibrate(30);

    if(press=='=')
    {
        onClickListenerReset(buttonReset);
    }

    one=(String)button1.getText();
    sum=sum+one;

    editText.setText(sum);
}

public void onClickListener2(View v)
{
    vibrator.vibrate(30);

    if(press=='=')
    {
        onClickListenerReset(buttonReset);
    }

    if(press=='=')
    {
        onClickListenerEqual(buttonEqual);
    }

    two=(String)button2.getText();
    sum=sum+two;

    editText.setText(sum);
}

public void onClickListener3(View v)
{
    vibrator.vibrate(30);
    if(press=='=')
    {
        onClickListenerReset(buttonReset);
    }
    three=(String)button3.getText();
    sum=sum+three;

    editText.setText(sum);
}

public void onClickListener4(View v)
{
    vibrator.vibrate(30);

    if(press=='=')
    {
        onClickListenerReset(buttonReset);
    }

    four=(String)button4.getText();
    sum=sum+four;

    editText.setText(sum);
}

public void onClickListener5(View v)
{
    vibrator.vibrate(30);
    if(press=='=')
    {
        onClickListenerReset(buttonReset);
    }

    five=(String)button5.getText();
    sum=sum+five;

    editText.setText(sum);
}

public void onClickListener6(View v)
{
    vibrator.vibrate(30);
    if(press=='=')
    {
        onClickListenerReset(buttonReset);
    }

    six=(String)button6.getText();
    sum=sum+six;

    editText.setText(sum);
}

public void onClickListener7(View v)
{
    vibrator.vibrate(30);
    if(press=='=')
    {
        onClickListenerReset(buttonReset);
    }

    seven=(String)button7.getText();
    sum=sum+seven;

    editText.setText(sum);
}

public void onClickListener8(View v)
{
    vibrator.vibrate(30);
    if(press=='=')
    {
        onClickListenerReset(buttonReset);
    }

    eight=(String)button8.getText();
    sum=sum+eight;

    editText.setText(sum);
}

public void onClickListener9(View v)
{
    vibrator.vibrate(30);
    if(press=='=')
    {
        onClickListenerReset(buttonReset);
    }

    nine=(String)button9.getText();
    sum=sum+nine;

    editText.setText(sum);
}

public void onClickListenerPlus(View v)
{
    vibrator.vibrate(30);

    if(press=='-')
    {
        onClickListenerEqual(buttonMinus);
    }
    else if(press=='*')
    {
        onClickListenerEqual(buttonMultiply);
    }

    else if(press=='/')
    {
        onClickListenerEqual(buttonDivide);
    }


    press='+';

    if(sum != "")
    {
        result=result+Float.parseFloat(editText.getText().toString());

        editText.setText(result.toString());

        result_mul=result;

        result_div=result;

        sum="";            
    }
    else
    {
        editText.setText(result.toString());

        result_mul=result;

        result_div=result;

        sum="";
    }

}

public void onClickListenerMinus(View v)
{
    vibrator.vibrate(30);
    if(press=='+')
    {
        onClickListenerEqual(buttonPlus);
    }
    else if(press=='*')
    {
        onClickListenerEqual(buttonMultiply);
    }
    else if(press=='/')
    {
        onClickListenerEqual(buttonDivide);
    }



    press='-';

    EditTextMsg= editText.getText().toString(); 
    floatEditTextMsg=Float.parseFloat(EditTextMsg);

    if(sum==""  && result==0)
    {
        sum=sum+'-';
        //Log.d("sum=","minus press");
    }
    else if(sum != "")
    {
        if(result==0)
        {
            result=Float.parseFloat(sum)-result;

            editText.setText(result.toString());

            result_mul=result;

            result_div=result;

            sum="";
        }

        else
        {
            result=result-Float.parseFloat(sum);

            editText.setText(result.toString());

            result_mul=result;

            result_div=result;

            sum="";
        }
    }

}

public void onClickListenerMultiply(View v)
{
    vibrator.vibrate(30);
    if(press=='/')
    {
        onClickListenerEqual(buttonDivide);
    }
    else if(press=='+')
    {
        onClickListenerEqual(buttonPlus);
    }

    else if(press=='-')
    {
        onClickListenerEqual(buttonMinus);
    }



    press='*';

    EditTextMsg= editText.getText().toString(); 
    floatEditTextMsg=Float.parseFloat(EditTextMsg);

    if(sum !="")
    {
        result_mul=result_mul * floatEditTextMsg; 

        result=result_mul;

        result_div=result_mul;

        editText.setText(result_mul.toString());

        sum="";
    }
    else
    {
        editText.setText(EditTextMsg);

        //result_mul=result_mul * Float.parseFloat(sum);

        //result=result_mul;

        sum="";
    }

}


public void onClickListenerDivide(View v)
{
    vibrator.vibrate(30);
    if(press=='+')
    {
        onClickListenerEqual(buttonPlus);
    }

    else if(press=='-')
    {
        onClickListenerEqual(buttonMinus);
    }

    else if(press=='*')
    {
        onClickListenerEqual(buttonMultiply);
    }

    press='/';

    EditTextMsg= editText.getText().toString(); 
    floatEditTextMsg=Float.parseFloat(EditTextMsg);

    if(sum !="" && result_div==1)
    {
        //int c=0;

        if(c==0)
        {
            result_div=floatEditTextMsg/result_div;  
            Log.d("if if result_div=", result_div.toString());
            c++;
        }
        else
        {
            result_div=result_div/floatEditTextMsg; 
            Log.d("if else result_div=", result_div.toString());
        }


        result=result_div;
        result_mul=result_div;

        editText.setText(result_div.toString());

        sum="";
    }
    else if(sum !="" && result_div !=1)
    {
        result_div=result_div/floatEditTextMsg; 

        Log.d("else if result_div=", result_div.toString());

        result=result_div;

        result_mul=result_div;

        editText.setText(result_div.toString());

        sum="";
    }
    else
    {
        editText.setText(EditTextMsg);

        sum="";
    }
}



public void onClickListenerPoint(View v)
{
    vibrator.vibrate(30);

   int error=0;

    if(sum !=null)
    {
        for(int i=0;i<sum.length();i++)
        {
            if(sum.charAt(i)=='.')
            {
                error=1;
                break;
            }
        }

    }

    if(error==0)
    {
        if(sum==null)
        {
            sum=sum+"0.";
        }
        else
        {
            sum=sum+".";
        }
    }

    editText.setText(sum);
}

public void onClickListenerEqual(View v)
{
    vibrator.vibrate(30);

    if(press=='+') 
    {
        onClickListenerPlus(buttonPlus);
        //msg1= editText.getText().toString(); 
        //floatMsg=Float.parseFloat(msg1);
    }
    else if(press=='-') 
    {
        onClickListenerMinus(buttonMinus);
    }
    else if(press=='*') 
    {
        onClickListenerMultiply(buttonMultiply);
    }
    else if(press=='/')
    {
        onClickListenerDivide(buttonDivide);
    }

    press='=';


}



public void onClickListenerReset(View v)
{
    vibrator.vibrate(30);

    sum="";
    countOne=0;//result=0;

    result=0f;
    result_mul=1f;
    result_div=1f;
    press=' ';
    c=0;

    editText.setText(result.toString());
}


public void onClickListener_sin(View v)
{
    vibrator.vibrate(30);

    EditTextMsg= editText.getText().toString(); 
    doubleEditTextMsg=Double.parseDouble(EditTextMsg);//degree

    toRadian_doubleEditTextMsg=Math.toRadians(doubleEditTextMsg);

    afterSin =Math.sin(toRadian_doubleEditTextMsg);

    editText.setText(afterSin.toString());

    EditTextMsg=editText.getText().toString();
    result=Float.parseFloat(EditTextMsg);

    result_mul=Float.parseFloat(EditTextMsg);

    result_div=Float.parseFloat(EditTextMsg);


    sum="";


}

public void onClickListener_cos(View v)
{
    vibrator.vibrate(30);
    EditTextMsg= editText.getText().toString(); 
    doubleEditTextMsg=Double.parseDouble(EditTextMsg);//degree

    toRadian_doubleEditTextMsg=Math.toRadians(doubleEditTextMsg);

    after_cos =Math.cos(toRadian_doubleEditTextMsg);

    editText.setText(after_cos.toString());

    EditTextMsg=editText.getText().toString();
    result=Float.parseFloat(EditTextMsg);

    result_mul=Float.parseFloat(EditTextMsg);

    result_div=Float.parseFloat(EditTextMsg);


    sum="";


}

public void onClickListener_tan(View v)
{
    vibrator.vibrate(30);

    EditTextMsg= editText.getText().toString(); 
    doubleEditTextMsg=Double.parseDouble(EditTextMsg);//degree

    toRadian_doubleEditTextMsg=Math.toRadians(doubleEditTextMsg);

    after_tan =Math.tan(toRadian_doubleEditTextMsg);

    editText.setText(after_tan.toString());

    EditTextMsg=editText.getText().toString();
    result=Float.parseFloat(EditTextMsg);

    result_mul=Float.parseFloat(EditTextMsg);

    result_div=Float.parseFloat(EditTextMsg);


    sum="";
}
public void onClickListener_log(View v)
{

    vibrator.vibrate(30);

   EditTextMsg= editText.getText().toString(); 
   doubleEditTextMsg=Double.parseDouble(EditTextMsg);//degree

   after_log =Math.log10(doubleEditTextMsg);

   editText.setText(after_log.toString());

   EditTextMsg=editText.getText().toString();
   result=Float.parseFloat(EditTextMsg);

   result_mul=Float.parseFloat(EditTextMsg);

   result_div=Float.parseFloat(EditTextMsg);


   sum="";


}


public void onClickListener_bra1(View v)
{

   vibrator.vibrate(30);


    bra1=(String)button_bra1.getText();

    sum=sum+"(";
    editText.setText(sum);

}

public void onClickListener_bra2(View v)
{



    bra2=(String)button_bra2.getText();

    sum=sum+")";
    editText.setText(sum);
} 




 public void onClickListener_del(View v)
 {
     vibrator.vibrate(30);
     if(sum !="")
     {
         StringBuilder stringBuilder=new StringBuilder(80);

         stringBuilder.append(sum);

         sum=stringBuilder.deleteCharAt(stringBuilder.length()-1).toString();

         editText.setText(sum);
     }

 }

}

日志猫

03-22 20:34:39.829: D/gralloc_goldfish(1499): Emulator without GPU emulation detected.
03-22 20:34:40.059: I/Choreographer(1499): Skipped 74 frames!  The application may be doing too much work on its main thread.
03-22 20:34:45.889: D/AndroidRuntime(1499): Shutting down VM
03-22 20:34:45.919: W/dalvikvm(1499): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
03-22 20:34:46.059: E/AndroidRuntime(1499): FATAL EXCEPTION: main
03-22 20:34:46.059: E/AndroidRuntime(1499): java.lang.IllegalStateException: Could not execute method of the activity
03-22 20:34:46.059: E/AndroidRuntime(1499):     at android.view.View$1.onClick(View.java:3599)
03-22 20:34:46.059: E/AndroidRuntime(1499):     at android.view.View.performClick(View.java:4204)
03-22 20:34:46.059: E/AndroidRuntime(1499):     at android.view.View$PerformClick.run(View.java:17355)
03-22 20:34:46.059: E/AndroidRuntime(1499):     at android.os.Handler.handleCallback(Handler.java:725)
03-22 20:34:46.059: E/AndroidRuntime(1499):     at android.os.Handler.dispatchMessage(Handler.java:92)
03-22 20:34:46.059: E/AndroidRuntime(1499):     at android.os.Looper.loop(Looper.java:137)
03-22 20:34:46.059: E/AndroidRuntime(1499):     at android.app.ActivityThread.main(ActivityThread.java:5041)
03-22 20:34:46.059: E/AndroidRuntime(1499):     at java.lang.reflect.Method.invokeNative(Native Method)
03-22 20:34:46.059: E/AndroidRuntime(1499):     at java.lang.reflect.Method.invoke(Method.java:511)
03-22 20:34:46.059: E/AndroidRuntime(1499):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-22 20:34:46.059: E/AndroidRuntime(1499):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-22 20:34:46.059: E/AndroidRuntime(1499):     at dalvik.system.NativeStart.main(Native Method)
03-22 20:34:46.059: E/AndroidRuntime(1499): Caused by: java.lang.reflect.InvocationTargetException
03-22 20:34:46.059: E/AndroidRuntime(1499):     at java.lang.reflect.Method.invokeNative(Native Method)
03-22 20:34:46.059: E/AndroidRuntime(1499):     at java.lang.reflect.Method.invoke(Method.java:511)
03-22 20:34:46.059: E/AndroidRuntime(1499):     at android.view.View$1.onClick(View.java:3594)
03-22 20:34:46.059: E/AndroidRuntime(1499):     ... 11 more
03-22 20:34:46.059: E/AndroidRuntime(1499): Caused by: java.lang.SecurityException: Requires VIBRATE permission
03-22 20:34:46.059: E/AndroidRuntime(1499):     at android.os.Parcel.readException(Parcel.java:1425)
03-22 20:34:46.059: E/AndroidRuntime(1499):     at android.os.Parcel.readException(Parcel.java:1379)
03-22 20:34:46.059: E/AndroidRuntime(1499):     at android.os.IVibratorService$Stub$Proxy.vibrate(IVibratorService.java:131)
03-22 20:34:46.059: E/AndroidRuntime(1499):     at android.os.SystemVibrator.vibrate(SystemVibrator.java:57)
03-22 20:34:46.059: E/AndroidRuntime(1499):     at calc.pack.MainActivity.onClickListener4(MainActivity.java:159)
03-22 20:34:46.059: E/AndroidRuntime(1499):     ... 14 more
03-22 20:34:46.509: D/dalvikvm(1499): GC_CONCURRENT freed 121K, 10% free 2659K/2924K, paused    82ms+29ms, total 448ms
03-22 20:34:49.429: I/Process(1499): Sending signal. PID: 1499 SIG: 9
4

2 回答 2

1
Caused by: java.lang.SecurityException: Requires VIBRATE permission

在您的清单中插入此权限即可获胜。

于 2013-03-22T20:42:56.760 回答
0

尝试将您的“ Integer”、“ Float”和“ Double”变量更改为原始的“ int”、“ float”和“ double”类型。

  • 因为其中许多值未初始化(即初始化为null),我担心在您的onClick...()函数中使用它们可能会导致 NullPointerException.
  • 我的另一个担心是读取这样的数字对象:“ one=(String)button1.getText();”可能不起作用,尽管我还没有测试过(为什么不在 final类级别将这些不变的值设置为常量值?)。

您必须对代码进行各种基本修改,以便将数值从 Objects 更改为 Primitives,但这些更改都应该是直截了当的。


尽管有此建议,但确定崩溃发生位置的最佳方法是查看 LogCat 输出。它会准确地告诉你哪行代码崩溃了。我假设它在您的一个onClick...()功能中只是因为您报告说每当按下按钮时应用程序就会崩溃。

于 2013-03-21T23:36:56.690 回答