몇 가지 질문을했지만 이전에 다시 돌아가보기로했습니다.문장이 강제로 프로그램을 강제 실행하는 경우
나는 수학적 안드로이드 응용 프로그램을 만들고 있는데, 각 페이지는 사용자가 숫자를 입력 할 수있는 세 개의 TextField
을 가지고 있으며, 나는이 두 글자를 두 번 파싱했습니다. 그러나 사용자가 TextField
중 2 개에 숫자를 입력했다고 가정하면 프로그램에서 세 번째 텍스트 필드의 값을 알려주고 싶습니다.
현재 하나의 계산을 실행하는 프로그램을 얻을 수 있지만 나머지 두 개의 if 문을 추가 할 때초를 계산할 때 계산을 클릭하면 프로그램이 충돌합니다. 프로그램의 핵심은 프로그램이 올바른 계산을 할 수 있도록 TextField
이 비어 있는지 확인하는 것입니다.
나는 현재 .getText().toString().isEmpty()
을 시도하고 있지만 작동하지 않습니다. 또한 시도했습니다 .length() == 0, 그러나 이것도 작동하지 않습니다.
에뮬레이터를 실행하고 계산기 단추를 클릭하면 더 많은 변수를 추가 할 때 프로그램이 중단되지만 단 하나의 계산으로도 문제가 없습니다.
누군가가 왜 If 문이 작동하지 않는지 파악하고 가능한 경우 누구든지 솔루션을 제공 할 수 있습니까? 내 서식이 꺼져있는 경우
, 나는 아래의 자바 인, 자바 비교적 새로운 미안 해요 나는 또한이 필요한 경우에는 XML을 제공 한
Button calc1 = (Button) findViewById(R.id.current_calculate);
calc1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
EditText Charge1 = (EditText) findViewById(R.id.number_input_2);
EditText Time1 = (EditText) findViewById(R.id.number_input_3);
EditText current1 = (EditText) findViewById(R.id.number_input_1);
TextView Distances_answer = (TextView) findViewById(R.id.Distances_answer);
double charge = Double
.parseDouble(Charge1.getText().toString());
double time = Double.parseDouble(Time1.getText().toString());
double current = Double.parseDouble(current1.getText()
.toString());
// Time is a class in Java
if (current1.getText().toString().isEmpty()) {
Distances_answer.setText("" + charge * time);
} else if (Time1.length() == 0) {
Distances_answer.setText(" " + charge/current);
}
}
});
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background1"
android:gravity="fill"
android:orientation="vertical"
android:textColor="#ffffff"
tools:context=".CurrentPage" >
<TextView
android:id="@+id/Current_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_marginTop="33dp"
android:text="Welcome to the Current Calculation page.
Hint - Use the check boxes to find the values that are missing "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/Equation_letter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/current_calculate"
android:layout_marginTop="37dp"
android:layout_toLeftOf="@+id/current_calculate"
android:text=" HELLO "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/Distances_answer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/Equation_letter"
android:layout_alignBottom="@+id/Equation_letter"
android:layout_alignLeft="@+id/current_calculate"
android:layout_alignParentRight="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff" />
<TextView
android:id="@+id/t"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/Q"
android:layout_alignRight="@+id/Q"
android:layout_below="@+id/Q"
android:layout_marginTop="36dp"
android:gravity="right|top"
android:text="t ="
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff"
tools:ignore="HardcodedText" />
<CheckBox
android:id="@+id/custom3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/t"
android:layout_alignLeft="@+id/custom2"
android:background="@drawable/check_box_new"
android:button="@drawable/check_box_new" />
<CheckBox
android:id="@+id/custom1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/number_input_3"
android:layout_alignLeft="@+id/custom3"
android:background="@drawable/check_box_new"
android:button="@drawable/check_box_new" />
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/Current_hint"
android:layout_alignRight="@+id/Current_hint"
android:layout_below="@+id/Equation_letter"
android:layout_marginTop="25dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/CurrentmainHelp"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1.31"
android:text="HELP! This equation can be used to calculate the current of an object in amps. The correct equation to discover amps is I=Q/t. Where I = current, Q = charge flowing past a point in the circuit, and t = time taken for the charge to flow. Please note, Q is measure in coulombs and t is measured in seconds, with I being measured in amperes.
Still need more help? "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/Yes_Please"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="36dp"
android:layout_weight="1.31"
android:onClick="CurrentHelp"
android:text="Yes Please"
android:textColor="#ffffff" />
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/current_calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/Calculate_Current"
android:textColor="#ffffff" />
<EditText
android:id="@+id/number_input_2"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_above="@+id/t"
android:layout_alignLeft="@+id/number_input_1"
android:layout_alignRight="@+id/number_input_1"
android:ems="10"
android:focusable="true"
android:inputType="numberDecimal"
android:textColor="#ffffff" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/number_input_3"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/t"
android:layout_alignLeft="@+id/number_input_2"
android:layout_alignRight="@+id/number_input_2"
android:ems="10"
android:focusable="true"
android:inputType="numberDecimal"
android:textColor="#ffffff" />
<CheckBox
android:id="@+id/custom2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/number_input_1"
android:layout_marginLeft="45dp"
android:layout_toRightOf="@+id/number_input_1"
android:background="@drawable/check_box_new"
android:button="@drawable/check_box_new" />
<EditText
android:id="@+id/number_input_1"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_above="@+id/Q"
android:layout_alignRight="@+id/current_calculate"
android:ems="10"
android:focusable="true"
android:inputType="numberDecimal"
android:singleLine="true"
android:textColor="#ffffff" />
<TextView
android:id="@+id/Q"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/Equation_letter"
android:layout_below="@+id/I"
android:layout_marginTop="36dp"
android:gravity="right|top"
android:text="Q ="
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/I"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/Q"
android:layout_alignRight="@+id/Q"
android:layout_below="@+id/Current_hint"
android:layout_marginTop="65dp"
android:gravity="right|top"
android:text="I ="
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff"
tools:ignore="HardcodedText" />
빠른 도움 (http://www.sscce.org/) [짧은, 콘도, 수정 (에 Compilable) 질문을보십시오]. –
또한 게시 스택 추적. – njzk2
오류 로그에 명백하게 명시된 이유로 앱이 다운됩니다. 그것을 읽으십시오. – njzk2