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"?>
Android: orientation="vertical"
XMLNS: tools="http://schemas.android.com/tools"
Android: layout_width="match_parent"
Android: layout_height="match_parent"
Tools: context="MainActivity" & gt;
Android: layout_width="match_parent"
Android: layout_height="100 sp/& gt;"
Android: layout_width="match_parent"
Android: layout_height="wrap_content"
Android: hint="please enter the measured values"
/>
Android: layout_width="match_parent"
Android: layout_height="wrap_content"
Android: hint="please enter the measured temperature"/& gt;
Android: layout_width="match_parent"
Android: layout_height="wrap_content"
Android: hint="please enter the conversion temperature"/& gt;
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 exceptionCodePudding 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 onlyCodePudding 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:

CodePudding user response:
Log log log!!!!!! See the top postsCodePudding user response:
Bad, a see is confused,