我正在为 Android 编写一个应用程序,所有应用程序在我的 Android 4.1 上都可以正常工作,但是当我在我的其他 Android 2.2 上测试它时,除了表单之外,所有应用程序都可以正常工作,当您单击按钮发送表单时崩溃。
我试过注释不同的代码,我在 if-else 中发现了问题,但我不知道为什么我希望你能帮助我。
此代码发送表单:
private void createAccount(){
EditText nombre = (EditText) findViewById(R.id.name);
EditText mail = (EditText) findViewById(R.id.mail);
EditText tel = (EditText) findViewById(R.id.phone);
EditText pass = (EditText) findViewById(R.id.pass);
EditText pass2 = (EditText) findViewById(R.id.pass2);
name = nombre.getText().toString();
email = mail.getText().toString();
phone = tel.getText().toString();
pas = pass.getText().toString();
pas2 = pass2.getText().toString();
if(name.isEmpty() == false && email.isEmpty() == false && phone.isEmpty() == false && pas.isEmpty() == false && pas2.isEmpty() == false){
if(pas.equals(pas2)){
respTxt = Cloud.CreateAccout(phone, name, email, pas, tel_id, tel_oper, tel_country);
TextView alert = (TextView)findViewById(R.id.reg_alert);
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if(networkInfo != null && networkInfo.isConnected()){
if(respTxt.equals("email")){
alert.setText(getText(R.string.reg_error1));
regBtn.setEnabled(true);
}else if(respTxt.equals("error") || respTxt.equals("errorc")){
alert.setText(getText(R.string.reg_error2));
regBtn.setEnabled(true);
}else if(respTxt.equals("correct")){
SharedPreferences settings = getSharedPreferences(prefs_file, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("AccountCreated", true);
editor.putString("status", "ok");
editor.commit();
Intent move = new Intent(AppRegis.this, HomeAct.class);
startActivityForResult(move, 0);
}
}else{
alert.setText(getText(R.string.noInternet));
regBtn.setEnabled(true);
}
}else{
TextView alert = (TextView)findViewById(R.id.reg_alert);
alert.setText(getText(R.string.reg_alert)+" "+email);
regBtn.setEnabled(true);
}
}else{
TextView alert = (TextView)findViewById(R.id.reg_alert);
alert.setText(getText(R.string.reg_alert2).toString());
regBtn.setEnabled(true);
}
}
LogCat 输出为
07-11 17:21:26.251: I/dalvikvm(335): Could not find method java.lang.String.isEmpty, referenced from method com.example/testactivity.createAccount()
07-11 17:21:26.251: W/dalvikvm(335): VFY: unable to resolve virtual method 177: Ljava/lang/String;.isEmpty ()Z
07-11 17:21:26.251: D/dalvikvm(335): VFY: replacing opcode 0x6e at 0x0042
07-11 17:21:26.251: D/dalvikvm(335): VFY: dead code 0x0045-0069 in Lcom/example/testactivity/createAccount() (Landroid/content/Context;Lcom/example/testtctivity;I)V
07-11 17:21:26.361: D/AndroidRuntime(335): Shutting down VM
07-11 17:21:26.361: W/dalvikvm(335): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-11 17:21:26.371: E/AndroidRuntime(335): FATAL EXCEPTION: main
07-11 17:21:26.371: E/AndroidRuntime(335): java.lang.NoSuchMethodError: java.lang.String.isEmpty
07-11 17:21:26.371: E/AndroidRuntime(335): at com.example.testactivity.createAccount()(testactivity.java:178)
抛出异常的行是if(name.isEmpty() == false....