- Forum posts: 2
Mar 22, 2015, 5:07:50 PM via Website
Mar 22, 2015 5:07:50 PM via Website
I have created a login app that once the login is successful the user is directed to a new activity. I have used a bundle to store the username to a string in the new activity, Then I went to my login adapter class and created a function that gets a string and returns a database query. But when I call the function in my new activity the emulator crashes!
Here is the code of the bundle:
String userName=editTextUserName.getText().toString();
String password=editTextPassword.getText().toString();
Bundle bundle = new Bundle();
bundle.putString("username", userName);
Here I pass what i stored in the bundle to a string:
Bundle bundle = getIntent().getExtras();
String username = bundle.getString("username");
Here is the function in the LoginDataBaseAdapter class:
public Cursor FetchRow (String username){
return db.query("LOGIN",null,"USERNAME='"+username,null,null,null,null);
}
And finally here I call the function in the new activity and pass the string declared earlier:
loginDataBaseAdapter.FetchRow(username);
Why does the emulator crash and doesn't display the data? All it says is "Unfortunately Login_Final (name of the app) has crashed!
This is the error log:
Caused by: java.lang.NullPointerException
at com.example.michalis.login_final.Login_home.onCreate(Login_home.java:32)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
— modified on Mar 22, 2015, 5:08:21 PM