【发布时间】:2012-03-21 16:45:40
【问题描述】:
我已经输入了“finally”语句,但我收到语法错误,我不知道如何纠正它们,我已经尝试了所有方法,但无济于事。我的类从两个编辑文本字段中获取字符串,如果选中该复选框,它将两个字符串保存到一个文件中,以便稍后调用,然后,如果编辑文本中没有任何内容,它会显示一个 toast。如果这是他们第一次,他们的数据(用户并保存传递),如果他们之前通过检查文件完成了此操作,则通过意图进入另一个类。哦,抱歉我的代码不好,我是一名新的 Java 程序员,我正在努力使其尽可能整洁。其次,如果有比我更好的编码方式,请随时更改,
谢谢。
用 ^ 标记的错误。
代码:
Button send;
EditText user;
EditText pass;
CheckBox staySignedIn;
FileOutputStream Fos;
String a;
String b;
String string = a;
String string2 = b;
String FILENAME = "userandpass";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
send = (Button) findViewById(R.id.bLogIn);
user = (EditText) findViewById(R.id.eTuser);
pass = (EditText) findViewById(R.id.eTpassword);
staySignedIn = (CheckBox) findViewById(R.id.Cbstay);
send.setOnClickListener(this);
File file = getBaseContext().getFileStreamPath(FILENAME);
if (file.exists())
;
Intent i = new Intent(LogIn.this, ChatService.class);
startActivity(i); ^
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bLogIn:
if (pass.length() == 0)
Toast.makeText(this,
"Try to type in your username and password again!",
Toast.LENGTH_LONG).show();
else if (user.length() == 0)
Toast.makeText(this,
"Try to type in your username and password again!",
Toast.LENGTH_LONG).show();
else {
if (staySignedIn.isChecked()) {
String a = user.getText().toString();
String b = pass.getText().toString();
File f = new File(FILENAME);
try {
Fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
if (Fos != null) {
Fos.write(a.getBytes());
Fos.write(b.getBytes());
}
Fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); ^
finally {
String u = user.getText().toString();
String p = pass.getText().toString();
Bundle send = new Bundle();
send.putString("key", u);
send.putString("key1", p);
Intent c = new Intent(LogIn.this, logincheck.class);
c.putExtra("key", u);
c.putExtra("key1", p);
startActivity(c);
Toast.makeText(this, "Were signing you in!", Toast.LENGTH_LONG)
.show();
break;
}
}
}
} ^
错误
Syntax error, insert "}" to complete Block LogIn.java /Banana Phone/src/com/gta5news/bananaphone line 53 Java Problem
Description Resource Path Location Type
Syntax error, insert "}" to complete ClassBody LogIn.java /Banana Phone/src/com/gta5news/bananaphone line 36 Java Problem
Description Resource Path Location Type
Syntax error, insert "}" to complete MethodBody LogIn.java /Banana Phone/src/com/gta5news/bananaphone line 53 Java Problem
Description Resource Path Location Type
Syntax error, insert "}" to complete MethodBody LogIn.java /Banana Phone/src/com/gta5news/bananaphone line 107 Java Problem
【问题讨论】:
标签: java android syntax syntax-error