代码中缺少什么?
我这里有问题。我这里有 2 个编辑文本。一个用于金额,一个用于密码。我的应用程序就像一个魅力,除了当我在编辑文本上输入 NONE 时,它崩溃了(不幸的是停止)。我是否遗漏了我的活动中的任何代码?请帮忙。这是我的代码。
public class MainActivity extends Activity {
Button REDIRECT;
private EditText txtbox1,txtbox2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
REDIRECT = (Button) findViewById(R.id.button1);
txtbox1= (EditText) findViewById(R.id.editText1);
txtbox2= (EditText) findViewById(R.id.editText2);
REDIRECT.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int Amount = Integer.parseInt(txtbox1.getText().toString());
String Password = txtbox2.getText().toString();
if(Amount<=50&&Amount>=1 & Password.equals("TUBOL"))
{
final Intent i = new Intent(MainActivity.this, Redirect.class);
startActivity(i);
}
else
{
Toast.makeText(MainActivity.this, "INVALID", Toast.LENGTH_LONG).show();
}
}
});
}
这是我的日志:
09-15 01:46:34.641: E/AndroidRuntime(30540): FATAL EXCEPTION: main
09-15 01:46:34.641: E/AndroidRuntime(30540): java.lang.NumberFormatException: Invalid int: ""
09-15 01:46:34.641: E/AndroidRuntime(30540): at java.lang.Integer.invalidInt(Integer.java:138)
09-15 01:46:34.641: E/AndroidRuntime(30540): at java.lang.Integer.parseInt(Integer.java:359)
09-15 01:46:34.641: E/AndroidRuntime(30540): at java.lang.Integer.parseInt(Integer.java:332)
09-15 01:46:34.641: E/AndroidRuntime(30540): at com.example.pwordlockdown.MainActivity$1.onClick(MainActivity.java:29)
09-15 01:46:34.641: E/AndroidRuntime(30540): at android.view.View.performClick(View.java:3549)
09-15 01:46:34.641: E/AndroidRuntime(30540): at android.view.View$PerformClick.run(View.java:14400)
09-15 01:46:34.641: E/AndroidRuntime(30540): at android.os.Handler.handleCallback(Handler.java:605)
09-15 01:46:34.641: E/AndroidRuntime(30540): at android.os.Handler.dispatchMessage(Handler.java:92)
09-15 01:46:34.641: E/AndroidRuntime(30540): at android.os.Looper.loop(Looper.java:154)
09-15 01:46:34.641: E/AndroidRuntime(30540): at android.app.ActivityThread.main(ActivityThread.java:4945)
09-15 01:46:34.641: E/AndroidRuntime(30540): at java.lang.reflect.Method.invokeNative(Native Method)
09-15 01:46:34.641: E/AndroidRuntime(30540): at java.lang.reflect.Method.invoke(Method.java:511)
09-15 01:46:34.641: E/AndroidRuntime(30540): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-15 01:46:34.641: E/AndroidRuntime(30540): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-15 01:46:34.641: E/AndroidRuntime(30540): at dalvik.system.NativeStart.main(Native Method)