gpt4 book ai didi

java - Android应用程序调试中的强制关闭错误

转载 作者:行者123 更新时间:2023-12-01 19:05:13 26 4
gpt4 key购买 nike

我没有收到任何编译错误,甚至没有收到重大警告,但是当我运行该程序时,它会强制关闭,并且日志告诉我一行中存在某种错误。它成功过一次,但我不知道如何或何时成功。

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);
}

程序失败时的日志之一:

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)

我相信这与小数文本框有关。在我让它们只取十进制数之前,该程序运行良好,但在一两次之后它也运行良好。我不想展示我的其余代码,除非你们确定问题出在那里。

最佳答案

如果这是搞砸的线路:

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

然后它说您正在尝试将 TextView 转换为 EditText

第 31 行是什么?那个?

关于java - Android应用程序调试中的强制关闭错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10343795/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com