My `MainActivity` code:
package com.example.android.myproject3;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import static com.example.android.myproject3.R.id.ans1;
import static com.example.android.myproject3.R.id.uid;
public class MainActivity extends AppCompatActivity {
String answ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onRadioButtonClicked(View view) {
// Is the button now checked?
boolean checked = ((Button) view).isPressed();
// Check which radio button was clicked
switch (view.getId()) {
case R.id.radio3a:
if (checked)
break;
case R.id.radio3b:
if (checked)
// Ninjas rule
break;
}
}
public void onRadioButtonClicked1(View view) {
// Is the button now checked?
boolean checked1 = ((Button) view).isPressed();
// Check which radio button was clicked
switch (view.getId()) {
case R.id.radio6a:
if (checked1)
break;
case R.id.radio6b:
if (checked1)
break;
}
}
public void onRadioButtonClicked2(View view) {
// Is the button now checked?
boolean checked2 = ((Button) view).isPressed();
// Check which radio button was clicked
switch (view.getId()) {
case R.id.radio8a:
if (checked2)
break;
case R.id.radio8b:
if (checked2)
break;
}
}
public String createanswers(String name, String uid, String ans1, boolean checkbox2a, boolean checkbox2b, boolean checkbox2c, boolean checkbox2d, boolean checked, boolean checkbox4a, boolean checkbox4b, boolean checkbox4c, boolean checkbox4d, String ans5, boolean checked1, String ans7, boolean checked2) {
String answers = "Name: " + name + "\nuid: " + uid + "\nAns 1: " + ans1 + "\nAns 2:" + (checkbox2a) + "\nAns 2:" + (checkbox2b) +"\nAns 2:" + (checkbox2c) +"\nAns 2:" + (checkbox2d) +"\nAns 3: " + checked + "\nAns 4:" + (checkbox4a) + "\nAns 4:" + (checkbox4b) +"\nAns 4:" + (checkbox4c) +"\nAns 4:" + (checkbox4d) + "\nAns 5: " + ans5 + "\nAns 6: " + checked1 + "\nAns 7: " + ans7 + "\nAns 8: " + checked2;
return answers;
}
public void review(View view) {
EditText editText = (EditText) findViewById(R.id.name);
String name = editText.getText().toString();
Log.v("MainActivity", "Name: " + name);
EditText editText1 = (EditText) findViewById(uid);
String uid = editText.getText().toString();
Log.v("MainActivity", "uid: " + uid);
EditText editText3 = (EditText) findViewById(ans1);
String ans1 = editText.getText().toString();
Log.v("MainActivity", "Ans 1: " + ans1);
CheckBox checkBox2a = (CheckBox) findViewById(R.id.a);
boolean checkbox2a = checkBox2a.isChecked();
Log.v("MainActivity", "Ans 2:" + checkBox2a);
CheckBox checkBox2b = (CheckBox) findViewById(R.id.b2);
boolean checkbox2b = checkBox2b.isChecked();
Log.v("MainActivity", "Ans 2:" + checkBox2b);
CheckBox checkBox2c = (CheckBox) findViewById(R.id.c2);
boolean checkbox2c = checkBox2c.isChecked();
Log.v("MainActivity", "Ans 2:" + checkbox2c);
CheckBox checkBox2d = (CheckBox) findViewById(R.id.d2);
boolean checkbox2d = checkBox2d.isChecked();
Log.v("MainActivity", "Ans 2:" + checkbox2d);
RadioGroup rg = (RadioGroup) findViewById(R.id.rg1);
boolean checked = ((RadioButton) view).isChecked();
CheckBox checkBox4a = (CheckBox) findViewById(R.id.a4);
boolean checkbox4a = checkBox4a.isChecked();
Log.v("MainActivity", "Ans 4:" + checkbox4a);
CheckBox checkBox4b = (CheckBox) findViewById(R.id.b4);
boolean checkbox4b = checkBox4b.isChecked();
Log.v("MainActivity", "Ans 4:" + checkbox4b);
CheckBox checkBox4c = (CheckBox) findViewById(R.id.c4);
boolean checkbox4c = checkBox4c.isChecked();
Log.v("MainActivity", "Ans 4:" + checkbox4c);
CheckBox checkBox4d = (CheckBox) findViewById(R.id.d4);
boolean checkbox4d = checkBox4d.isChecked();
Log.v("MainActivity", "Ans 4:" + checkbox4d);
EditText editText5 = (EditText) findViewById(R.id.ans5);
String ans5 = editText5.getText().toString();
Log.v("MainActivity", "Ans 5: " + ans5);
RadioGroup rg2 = (RadioGroup) findViewById(R.id.rg2);
boolean checked1 = ((RadioButton) view).isChecked();
EditText editText7 = (EditText) findViewById(R.id.ans7);
String ans7 = editText7.getText().toString();
Log.v("MainActivity", "Ans 7: " + ans7);
RadioGroup rg3 = (RadioGroup) findViewById(R.id.rg3);
boolean checked2 = ((RadioButton) view).isChecked();
answ = createanswers(name, uid, ans1, checkbox2a, checkbox2b, checkbox2c, checkbox2d, checked, checkbox4a, checkbox4b, checkbox4c, checkbox4d, ans5, checked1, ans7, checked2);
displayMessage(answ);
}
public void submit(View view){
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_TEXT, answ);
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
private void displayMessage(String message) {
TextView quantity = (TextView) findViewById(
R.id.review1);
quantity.setText(message);
}
}
当我点击评论按钮时,我的应用程序崩溃了。
I want to display the information when the review button is clicked, but the display method is not working.
``````````````````````
``````````````````
logcat
``````````````````
```````````````````````
07-12 22:15:49.553 14147-14147/com.example.android.myproject3 I/art: Late-enabling -Xcheck:jni
07-12 22:15:49.553 14147-14147/com.example.android.myproject3 I/art: Reinit property: dalvik.vm.checkjni= false
07-12 22:15:49.702 14147-14147/com.example.android.myproject3 W/System: ClassLoader referenced unknown path: /data/app/com.example.android.myproject3-2/lib/arm64
07-12 22:15:49.714 14147-14147/com.example.android.myproject3 I/InstantRun: starting instant run server: is main process
07-12 22:15:49.757 14147-14147/com.example.android.myproject3 I/HwCust: Constructor found for class android.app.HwCustActivityImpl
07-12 22:15:49.783 14147-14147/com.example.android.myproject3 I/HwCust: Constructor found for class android.app.HwCustHwWallpaperManagerImpl
07-12 22:15:49.808 14147-14147/com.example.android.myproject3 W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
07-12 22:15:49.885 14147-14147/com.example.android.myproject3 E/HW-JPEG-DEC: [HME_JPEG_DEC_Delete](3321): HME_JPEG_DEC_Delete: decoder_ctx=null
07-12 22:15:49.929 14147-14147/com.example.android.myproject3 E/HW-JPEG-DEC: [HME_JPEG_DEC_Delete](3321): HME_JPEG_DEC_Delete: decoder_ctx=null
07-12 22:15:49.931 14147-14147/com.example.android.myproject3 E/HW-JPEG-DEC: [HME_JPEG_DEC_Delete](3321): HME_JPEG_DEC_Delete: decoder_ctx=null
07-12 22:15:49.932 14147-14147/com.example.android.myproject3 E/HW-JPEG-DEC: [HME_JPEG_DEC_Delete](3321): HME_JPEG_DEC_Delete: decoder_ctx=null
07-12 22:15:50.012 14147-14147/com.example.android.myproject3 I/HwSecImmHelper: mSecurityInputMethodService is null
07-12 22:15:50.025 14147-14147/com.example.android.myproject3 I/HwPointEventFilter: do not support AFT because of no config
07-12 22:15:50.120 14147-14169/com.example.android.myproject3 I/OpenGLRenderer: Initialized EGL, version 1.4
07-12 22:15:50.128 14147-14169/com.example.android.myproject3 W/linker: /vendor/lib64/libhwuibp.so: unused DT entry: type 0xf arg 0xe3a
07-12 22:15:50.147 14147-14147/com.example.android.myproject3 W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
07-12 22:15:50.183 14147-14169/com.example.android.myproject3 E/OpenGLRenderer: allen debug liyu Key: 0
07-12 22:15:50.189 14147-14169/com.example.android.myproject3 E/OpenGLRenderer: allen debug liyu Key: 3
07-12 22:15:50.191 14147-14169/com.example.android.myproject3 E/OpenGLRenderer: allen debug liyu Key: 5242945
07-12 22:15:50.192 14147-14169/com.example.android.myproject3 E/OpenGLRenderer: allen debug liyu Key: 5242944
07-12 22:15:50.193 14147-14169/com.example.android.myproject3 E/OpenGLRenderer: allen debug liyu Key: 34364981312
07-12 22:15:50.194 14147-14169/com.example.android.myproject3 E/OpenGLRenderer: allen debug liyu Key: 34359738371
07-12 22:15:50.199 14147-14169/com.example.android.myproject3 E/OpenGLRenderer: allen debug liyu Key: 240518168576
```````````````````````````````
`````````````````````````````
审核按钮不会按照我的计划显示。其他一切工作除了审查按钮 当我点击评论按钮时,该应用程序停止工作。我尝试了所有我知道但失败的事情。
答案 0 :(得分:0)
您将view
视为RadioButton
,但实际上是Button
boolean checked = ((RadioButton) view).isChecked();
所以试试
boolean checked = ((Button) view).isPressed();
虽然仅仅按下按钮并不是真的有意义,但这就是导致崩溃的原因。