【发布时间】:2017-09-10 01:43:55
【问题描述】:
我正在尝试将用户的数据读入数据库,但单选按钮输入没有被存储。它给出了一个空异常。在未存储文本的其他活动中将文本写入文件时面临同样的问题。
这是存储在数据库活动中的代码:
public class S4CharacterForm extends AppCompatActivity {
TextView t1, t2, t3, t4, t5, t6, t7, t8, t9;
EditText e1, e3, e4, e5, e6, e7, e8, e9;
RadioGroup rg;
RadioButton r2;
int selected_ID;
String radioText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_s4);
ImageView imageView = (ImageView) findViewById(R.id.img_s3);
Glide.with(this).load(R.drawable.banner_s3).into(imageView);
Typeface tf = Typeface.createFromAsset(getAssets(), "font.ttf");
t1 = (TextView) findViewById(R.id.name);
t1.setTypeface(tf);
t2 = (TextView) findViewById(R.id.gender);
t2.setTypeface(tf);
t3 = (TextView) findViewById(R.id.age);
t3.setTypeface(tf);
t4 = (TextView) findViewById(R.id.hair_c);
t4.setTypeface(tf);
t5 = (TextView) findViewById(R.id.eye_c);
t5.setTypeface(tf);
t6 = (TextView) findViewById(R.id.prof);
t6.setTypeface(tf);
t7 = (TextView) findViewById(R.id.dreams);
t7.setTypeface(tf);
t8 = (TextView) findViewById(R.id.peeves);
t8.setTypeface(tf);
t9 = (TextView) findViewById(R.id.purpose);
t9.setTypeface(tf);
e1 = (EditText) findViewById(R.id.name_ip);
e3 = (EditText) findViewById(R.id.age_ip);
e4 = (EditText) findViewById(R.id.hair_c_ip);
e5 = (EditText) findViewById(R.id.eye_c_ip);
e6 = (EditText) findViewById(R.id.prof_ip);
e7 = (EditText) findViewById(R.id.dreams_ip);
e8 = (EditText) findViewById(R.id.peeves_ip);
e9 = (EditText) findViewById(R.id.purpose_ip);
rg = (RadioGroup) findViewById(R.id.gender_ip);
selected_ID = rg.getCheckedRadioButtonId();
try {
switch (selected_ID){
case R.id.f:
radioText = "Female";
break;
case R.id.m:
radioText = "Male";
break;
}
// radioText = (String) r2.getText();
} catch (Exception e) {
e.printStackTrace();
Log.i(TAG, "Radio Button Null Exception");
// r2 = (RadioButton) findViewById(selected_ID);
}
}
public void nextScreen(View view) {
CharacterTable charTable = new CharacterTable(this);
charTable.open();
long rowID = charTable.createCharacter(e1.getText().toString(), radioText, e3.getText().toString(),
e4.getText().toString(), e5.getText().toString(), e6.getText().toString(), e7.getText().toString(),
e8.getText().toString(), e9.getText().toString());
if (rowID != -1)
Toast.makeText(S4CharacterForm.this, "Character Created", Toast.LENGTH_SHORT).show();
else
Toast.makeText(S4CharacterForm.this, "Something went wrong", Toast.LENGTH_SHORT).show();
charTable.close();
Intent intent = new Intent(S4CharacterForm.this, S5.class);
startActivity(intent);
}
}
我认为这是一个范围问题?谁能解释一下?
【问题讨论】:
-
请显示logcat
标签: java android sqlite radio-button