I’ve put in a “finally” statement, but I get Syntax error, I don’t have any idea on how to correct them, I’ve tried everything, but to no avail. My class get’s the string from the two edit text fields, if the checkbox is checked it saves the two strings to a file, to be called up later, then, if there’s nothing in the edit text’s, it displays a toast. If it’s their first time, their data(user and pass it saved) and, if they’ve done this before via checking the file, it goes to another class via an intent. Oh, sorry for my bad code, I’m a new Java programmer and I’m trying to make it as neat as possible. Secondly, if there’s a better way to code, than I’ve done, please feel free to change it,
Thanks.
Errors marked with an ^.
Code:
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;
}
}
}
} ^
Errors
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
You don’t close the second catch statement :
Common structure is :
EDIT :
and replace :
by