I am trying to access the information stored in my database by using the id that I am passing in from a list.
Here is the code i have on my mainList class:
studentList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
try {
String selected =parent.getItemAtPosition(position).toString();
Log.d("position: ", selected);
Class page = Class.forName("com.example.ltss.dyslexia.app.StudentProfilePage");
//Intent intent = new Intent(getApplicationContext(), StudentProfilePage.class);
Intent intent = new Intent(MainList.this, StudentProfilePage.class);
//Intent intent = new Intent(MainList.this, page);
intent.putExtra("id", selected);
String size = String.valueOf(id);
Log.d("id is: ", size);
intent.putExtra(ID_EXTRA, String.valueOf(id));
startActivity(intent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
/*Toast.makeText(getApplicationContext(),
((TextView) v).getText(), Toast.LENGTH_SHORT).show();*/
}
});
and my studentProfilePage (where i'm passing the data):
public class StudentProfilePage extends Activity {
String passedVar = null;
private TextView id = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.student_profile_page);
passedVar = getIntent().getStringExtra(MainList.ID_EXTRA);
//id = (TextView)findViewById(R.id.id);
final DatabaseHandler dyslexiaDb = new DatabaseHandler(this);
//dyslexiaDb.openDatabase();
String data[] = dyslexiaDb.retrieveDataFromStudents(passedVar);
Here is what I have in my DatabaseHandler class:
public String[] retrieveDataFromStudents(String id){
String table_name = TABLE_STUDENTS;
// Create query
String selectQuery = "SELECT * FROM "+table_name+" WHERE studentId = "+id;
dyslexiaDatabase = this.getReadableDatabase();
// set up Studnet Cursor (sCursor)
Cursor sCursor = dyslexiaDatabase.rawQuery(selectQuery, null);
String [] data = null;
int count = 0;
String[] data2 = data;
if(sCursor.moveToFirst()){
do{
data2[count] = sCursor.getString(count);
Log.d("info", data[count]);
}while(sCursor.moveToNext());
}
dyslexiaDatabase.close();
return data2;
}
And here is the error I'm getting:
02-11 01:09:14.689: E/AndroidRuntime(26180): FATAL EXCEPTION: main
02-11 01:09:14.689: E/AndroidRuntime(26180): Process: com.example.ltssdyslexiaapp, PID: 26180
02-11 01:09:14.689: E/AndroidRuntime(26180): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ltssdyslexiaapp/com.example.ltss.dyslexia.app.StudentProfilePage}: java.lang.NullPointerException
02-11 01:09:14.689: E/AndroidRuntime(26180): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
02-11 01:09:14.689: E/AndroidRuntime(26180): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
02-11 01:09:14.689: E/AndroidRuntime(26180): at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-11 01:09:14.689: E/AndroidRuntime(26180): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-11 01:09:14.689: E/AndroidRuntime(26180): at android.os.Handler.dispatchMessage(Handler.java:102)
02-11 01:09:14.689: E/AndroidRuntime(26180): at android.os.Looper.loop(Looper.java:136)
02-11 01:09:14.689: E/AndroidRuntime(26180): at android.app.ActivityThread.main(ActivityThread.java:5001)
02-11 01:09:14.689: E/AndroidRuntime(26180): at java.lang.reflect.Method.invokeNative(Native Method)
02-11 01:09:14.689: E/AndroidRuntime(26180): at java.lang.reflect.Method.invoke(Method.java:515)
02-11 01:09:14.689: E/AndroidRuntime(26180): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
02-11 01:09:14.689: E/AndroidRuntime(26180): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 02-11 01:09:14.689: E/AndroidRuntime(26180): at dalvik.system.NativeStart.main(Native Method) 02-11 01:09:14.689: E/AndroidRuntime(26180): Caused by: java.lang.NullPointerException 02-11 01:09:14.689: E/AndroidRuntime(26180): at com.example.ltss.dyslexia.app.DatabaseHandler.retrieveDataFromStudents(DatabaseHandler.java:322) 02-11 01:09:14.689: E/AndroidRuntime(26180): at com.example.ltss.dyslexia.app.StudentProfilePage.onCreate(StudentProfilePage.java:26) 02-11 01:09:14.689: E/AndroidRuntime(26180): at android.app.Activity.performCreate(Activity.java:5231) 02-11 01:09:14.689: E/AndroidRuntime(26180): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 02-11 01:09:14.689: E/AndroidRuntime(26180): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 02-11 01:09:14.689: E/AndroidRuntime(26180): ... 11 more 02-11 01:09:24.559: E/WindowManager(569): Starting window AppWindowToken{439fe3e0 token=Token{43152328 ActivityRecord{4279b590 u0 com.example.ltssdyslexiaapp/com.example.ltss.dyslexia.app.StudentProfilePage t725}}} timed out 02-11 01:09:25.199: E/WindowManager(569): Starting window AppWindowToken{43f5d3a8 token=Token{42940510 ActivityRecord{42782eb0 u0 com.example.ltssdyslexiaapp/com.example.ltss.dyslexia.app.MainActivity t725}}} timed out 02-11 01:09:27.011: E/InputDispatcher(569): channel '43420a88 com.example.ltssdyslexiaapp/com.example.ltss.dyslexia.app.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed! 02-11 01:09:27.011: E/InputDispatcher(569): channel '434566b8 com.example.ltssdyslexiaapp/com.example.ltss.dyslexia.app.MainList (server)' ~ Channel is unrecoverably broken and will be disposed!
I am currently using an Adapter instead of a CursorAdapter (just until I get the CursorAdapter working correctly) I just need to get one page displaying user data using the ID that's passed through as soon as i can.
Am I doing something seriously wrong?
Thanks for any help you can give me!
Aucun commentaire:
Enregistrer un commentaire