I created an android app project in android eclipse, I have a problem with the log-in command. i have already registered but i can't login, the username and password is already registered in the database using sqlite browser. But when I put the username and password I cant login. I dont know where the error is. please help.
here's my mainactivity.java code:
package com.example.howtos;
import com.example.howtos.DatabaseManager;
import com.example.howtos.MainActivity;
import com.example.howtos.R;
import com.example.howtos.reg;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.CursorIndexOutOfBoundsException;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final DatabaseManager dataBase;
dataBase = DatabaseManager.instance();
Button b = (Button) findViewById (R.id.btn12);
b.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
try
{
final EditText username = (EditText) findViewById(R.id.editText1);
final EditText password = (EditText) findViewById(R.id.editText2);
final String COLUMN_PW = "password";
Cursor cursor = dataBase.select("SELECT password FROM users WHERE username = '" + username.getText().toString() + "';");
String s = cursor.getString(cursor.getColumnIndex(COLUMN_PW));
if(password.getText().toString() == s)
{
startActivity(new Intent(MainActivity.this,homepage.class));
Toast.makeText(getApplicationContext(), "Successfully Login", Toast.LENGTH_SHORT).show();
cursor.close();
}
}
catch(CursorIndexOutOfBoundsException e1)
{
Toast.makeText(getApplicationContext(), "Invalid Username or Password", Toast.LENGTH_SHORT).show();
}
}
});
TextView r = (TextView) findViewById (R.id.textView7);
r.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
startActivity(new Intent(MainActivity.this,reg.class));
}
});
}
}