Home > Mobile >  Masters to help you! They hung up a run without error code! The code is as follows:
Masters to help you! They hung up a run without error code! The code is as follows:

Time:11-30

Several controls in the XML input decimal Numbers, and then click on the button, can according to the method to calculate, the result shows that in TX this control, the code is not an error why this run will hang up? You greatly help to see how to do?
Package com. Example. Mymeth;
The import android. Support. V7. App. AppCompatActivity;
The import android. OS. Bundle;
The import android. View. The view;
The import android. Widget. The Button;
The import android. Widget. The EditText;
The import android. Widget. TextView;
Public class MainActivity extends AppCompatActivity {
Double t1, t2, t, t1=235 + t1, t2=235 + t2, R1, R2=0;
Public void setR1 (double r1) {
R1=R1;
}
Public void setR2 (double r2) {
R2=R2;
}
Public double getR1 () {
R1=(T1/T2) * R2;
Return R1.
}
Public double getR2 () {
R1, R2=(T1/T2) *
Return R2;
}
@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView TX=(TextView) the findViewById (R.i which ext);
The EditText cet=(EditText) the findViewById (R.i, dc et);
String STR=cet. GetText (). The toString (). The trim ();
Double R2=double. ParseDouble (STR);
The EditText cxt1=(EditText) the findViewById (R.i, dc xt1);
Strings str1=cxt1. GetText (). The toString (). The trim ();
Double t1=double. ParseDouble (str1);
The EditText cxt2=(EditText) the findViewById (R.i, dc xt2);
String str2=cxt2. GetText (). The toString (). The trim ();
Double t2=double. ParseDouble (str2);
The Button bt=(Button) the findViewById (surprised R.i jeter isuan);

Bt. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v) {

}
});
TX. SetText (String. The valueOf (R1));
}

}
XML:
<? The XML version="1.0" encoding="utf-8"?>
XMLNS: app="http://schemas.android.com/apk/res-auto"
Android: orientation="vertical"
XMLNS: tools="http://schemas.android.com/tools"
Android: layout_width="match_parent"
Android: layout_height="match_parent"
Tools: context="MainActivity" & gt;
The android: id="@ + id/text"
Android: layout_width="match_parent"
Android: layout_height="100 sp/& gt;"
The android: id="@ + id/cet"
Android: layout_width="match_parent"
Android: layout_height="wrap_content"
Android: hint="please enter the measured values"
/>
The android: id="@ + id/cxt1"
Android: layout_width="match_parent"
Android: layout_height="wrap_content"
Android: hint="please enter the measured temperature"/& gt;
The android: id="@ + id/cxt2"
Android: layout_width="match_parent"
Android: layout_height="wrap_content"
Android: hint="please enter the conversion temperature"/& gt;

The android: id="@ + id/jisuan"
Android: layout_width="wrap_content"
Android: layout_height="wrap_content"
Android: layout_gravity="center_horizontal"
Android: text="calculation"/& gt;

CodePudding user response:

Blind guess Edittext. Gettext is null, resulting in a null pointer exception

CodePudding user response:

To write like this:
Bt. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v) {

TX. SetText (String. The valueOf (R1));

}
});

CodePudding user response:

Really! Code only

CodePudding user response:

 
String STR=cet. GetText (). The toString (). The trim ();
Strings str1=cxt1. GetText (). The toString (). The trim ();
String str2=cxt2. GetText (). The toString (). The trim ();

Haven't input, null values,

CodePudding user response:

god don't code logic

CodePudding user response:

Log log log!!!!!! See the top posts

CodePudding user response:

Bad, a see is confused,
  • Related