0

コンパイルエラーや重大な警告は表示されませんが、プログラムを実行すると、強制的に閉じられ、ログに行に何らかのエラーがあることが示されます。一度は成功しましたが、いつ、どのようにしたらいいのかわかりません。

onClickメソッド:

public TextView equation;
public TextView answer11;
public TextView answer12;
public TextView or1;
public TextView or2;

public void SolveOnClick(View view){

    EditText a = (EditText)findViewById(R.id.aValue);
    EditText b = (EditText)findViewById(R.id.bValue);       //screws up somewhere here
        EditText c = (EditText)findViewById(R.id.cValue);
        equation = (TextView)findViewById(R.id.equationText);
        answer11 = (TextView)findViewById(R.id.answer1);
        answer12 = (TextView)findViewById(R.id.answer2);
        or1 = (TextView)findViewById(R.id.or1);
        or2 = (TextView)findViewById(R.id.or2);

    double A = Double.parseDouble(a.getText().toString());
        double B = Double.parseDouble(b.getText().toString());
        double C = Double.parseDouble(c.getText().toString());


        Formula(A,B,C);

    }

私の主なグラフィックレイアウト:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<Button
    android:id="@+id/button1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:onClick="SolveOnClick"
    android:text="@string/solveButtonText" />

<TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:text="@string/quadFormText"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView4"
    android:layout_marginTop="17dp"
    android:layout_toLeftOf="@+id/textView4"
    android:text="@string/A"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
    android:id="@+id/aValue"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView4"
    android:layout_alignTop="@+id/textView1"
    android:layout_marginLeft="15dp"
    android:ems="10"
    android:inputType="numberDecimal" >

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/bValue"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/aValue"
    android:layout_below="@+id/aValue"
    android:layout_marginTop="14dp"
    android:ems="10"
    android:inputType="numberDecimal" />

<EditText
    android:id="@+id/cValue"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/bValue"
    android:layout_below="@+id/bValue"
    android:layout_marginTop="14dp"
    android:ems="10"
    android:inputType="numberDecimal" />

<TextView
    android:id="@+id/answer1Text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:text="@string/equals1"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/answer2Text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/answer1Text"
    android:layout_below="@+id/answer1Text"
    android:layout_marginTop="88dp"
    android:text="@string/equals2"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/answer1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/answer1Text"
    android:layout_toRightOf="@+id/answer1Text"
    android:text="@string/answer11"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/or1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/answer1Text"
    android:layout_below="@+id/answer1Text"
    android:layout_marginTop="25dp"
    android:text="@string/or1"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/answer2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/answer2Text"
    android:layout_toRightOf="@+id/answer1Text"
    android:text="@string/answer12"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/or2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/answer2Text"
    android:layout_below="@+id/answer2Text"
    android:layout_marginTop="24dp"
    android:text="@string/or2"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/equationText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/cValue"
    android:layout_marginTop="14dp"
    android:text="@string/equation"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/cValue"
    android:layout_toLeftOf="@+id/textView4"
    android:text="@string/C"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/bValue"
    android:layout_alignLeft="@+id/textView3"
    android:text="@string/B"
    android:textAppearance="?android:attr/textAppearanceLarge" />

onCreateメソッド:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

プログラムが失敗したときのログの1つ:

04-26 20:39:33.174: E/AndroidRuntime(16092): Caused by: java.lang.ClassCastException:     android.widget.TextView
04-26 20:39:33.174: E/AndroidRuntime(16092):    at calc.ulater.QuadCalcActivity.SolveOnClick(QuadCalcActivity.java:31)

これは、10進数のテキストボックスと関係があると思います。このプログラムは、10進数のみを使用するようにする前はうまく機能しましたが、1、2時間後にも機能しました。問題がそこにあると皆さんが確信していない限り、コードの残りの部分は表示したくありません。

4

2 に答える 2

2

これが台無しになっている行である場合:

EditText b = (EditText)findViewById(R.id.bValue);

TextView次に、 aを anにキャストしようとしていると言っていますEditText

31行目は?それです?

于 2012-04-27T02:04:10.253 に答える
2
EditText a = (EditText)findViewById(R.id.aValue);
EditText b = (EditText)findViewById(R.id.bValue);       //screws up somewhere here
EditText c = (EditText)findViewById(R.id.cValue);
equation = (TextView)findViewById(R.id.equationText);
answer11 = (TextView)findViewById(R.id.answer1);
answer12 = (TextView)findViewById(R.id.answer2);
or1 = (TextView)findViewById(R.id.or1);
or2 = (TextView)findViewById(R.id.or2);

すべての初期化はonCreate()constructor

更新しました::

EditText a = (EditText)view.findViewById(R.id.aValue);
EditText b = (EditText)view.findViewById(R.id.bValue);       //screws up somewhere here
EditText c = (EditText)view.findViewById(R.id.cValue);
equation = (TextView)view.findViewById(R.id.equationText);
answer11 = (TextView)view.findViewById(R.id.answer1);
answer12 = (TextView)view.findViewById(R.id.answer2);
or1 = (TextView)view.findViewById(R.id.or1);
or2 = (TextView)view.findViewById(R.id.or2);

ビューが親ビューの場合

于 2012-04-27T02:04:23.303 に答える