Note that there are some explanatory texts on larger screens.

plurals
  1. POWeird null pointer exception with DbHelper class context, code within
    primarykey
    data
    text
    <p>I am getting a null pointer on this code... So lost.</p> <p>I have a Database helper class called DbAdapter.</p> <pre><code>public class DbAdapter { private final Context mCtx; public DbAdapter(Context ctx) { mCtx = ctx; //set context } /// This function adds all the student INFO to the DB public long addStudentInfoToDb(String stuID,String stuFName, String stuLName) { ContentValues student_info = new ContentValues(); student_info.put(STU_ID, stuID); student_info.put(STU_FNAME, stuFName); student_info.put(STU_LNAME, stuLName); return mDb.insert("Student", null, student_info); } </code></pre> <p>And I am using this info in another class/activity called:LoginScreenActivity</p> <p>I declare the DbAdapter class like this... dbHelper = new DbAdapter(LoginScreenActivity.this);</p> <pre><code> public void loginScreenFill() { final EditText student_id = (EditText) findViewById(R.id.student_id_edit); final EditText student_fname = (EditText) findViewById(R.id.fname_edit); final EditText student_lname = (EditText) findViewById(R.id.lname_edit); final EditText course_code = (EditText) findViewById(R.id.classcode_edit); Button login_button = (Button) findViewById(R.id.login_button); login_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub String id = String.valueOf((student_id.getText())); String first_name = String.valueOf(student_fname.getText()); String last_name = String.valueOf(student_lname.getText()); String class_code = String.valueOf(course_code.getText()); dbHelper.addStudentInfoToDb(id, first_name, last_name); addStudentInfo(id,first_name,last_name); } </code></pre> <p>And I am getting this... 07-27 19:26:02.211: E/AndroidRuntime(1924): java.lang.NullPointerException 07-27 19:09:22.615: E/AndroidRuntime(1113): at com.test.quizapp.DbAdapter.addStudentInfoToDb(DbAdapter.java:121)</p> <pre><code>07-27 19:26:02.211: E/AndroidRuntime(1924): FATAL EXCEPTION: main 07-27 19:26:02.211: E/AndroidRuntime(1924): java.lang.NullPointerException 07-27 19:26:02.211: E/AndroidRuntime(1924): at com.test.quizapp.DbAdapter.addStudentInfoToDb(DbAdapter.java:121) 07-27 19:26:02.211: E/AndroidRuntime(1924): at com.test.quizapp.LoginScreenActivity$1.onClick(LoginScreenActivity.java:54) 07-27 19:26:02.211: E/AndroidRuntime(1924): at android.view.View.performClick(View.java:4211) 07-27 19:26:02.211: E/AndroidRuntime(1924): at android.view.View$PerformClick.run(View.java:17362) 07-27 19:26:02.211: E/AndroidRuntime(1924): at android.os.Handler.handleCallback(Handler.java:725) 07-27 19:26:02.211: E/AndroidRuntime(1924): at android.os.Handler.dispatchMessage(Handler.java:92) 07-27 19:26:02.211: E/AndroidRuntime(1924): at android.os.Looper.loop(Looper.java:137) 07-27 19:26:02.211: E/AndroidRuntime(1924): at android.app.ActivityThread.main(ActivityThread.java:5227) 07-27 19:26:02.211: E/AndroidRuntime(1924): at java.lang.reflect.Method.invokeNative(Native Method) 07-27 19:26:02.211: E/AndroidRuntime(1924): at java.lang.reflect.Method.invoke(Method.java:511) 07-27 19:26:02.211: E/AndroidRuntime(1924): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795) 07-27 19:26:02.211: E/AndroidRuntime(1924): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562) 07-27 19:26:02.211: E/AndroidRuntime(1924): at dalvik.system.NativeStart.main(Native Method) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload