0

I am trying to install my App on the phone, and at run time i received the following errors:

errors:

 java.lang.NullPointerException: lock == null
08-11 13:51:59.106 3380-3380/com.example.com.ecoassistant_03 E/AndroidRuntime:     at java.io.Reader.<init>(Reader.java:64)
08-11 13:51:59.106 3380-3380/com.example.com.ecoassistant_03 E/AndroidRuntime:     at java.io.BufferedReader.<init>(BufferedReader.java:107)
08-11 13:51:59.106 3380-3380/com.example.com.ecoassistant_03 E/AndroidRuntime:     at java.io.BufferedReader.<init>(BufferedReader.java:95)
08-11 13:51:59.106 3380-3380/com.example.com.ecoassistant_03 E/AndroidRuntime:     at com.example.com.ecoassistant_03.Populator.populate(Populator.java:38)
08-11 13:51:59.106 3380-3380/com.example.com.ecoassistant_03 E/AndroidRuntime:     at com.example.com.ecoassistant_03.ActMain.onOptionsItemSelected(ActMain.java:1182)
08-11 13:51:59.106 3380-3380/com.example.com.ecoassistant_03 E/AndroidRuntime:     at android.app.Activity.onMenuItemSelected(Activity.java:3205)

code

Populator populate = new Populator();
populate.populate(this, new File(Environment.getExternalStorageDirectory() + "/database/" + "kaAllNodesNumbered.txt"));


public void populate(Context context, File file) {
    this.mCtx = context;
    this.mSQLiteHelper = new SQLiteHelper(this.mCtx);
    //this.mSQLiteHelper.deleteALLRows();
    //Log.i(TAG, "total rows: " + this.mSQLiteHelper.getTotalRowsInDB());

    try {
        this.mFR = new FileReader(file);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    this.mBR = new BufferedReader(this.mFR); //LINE 38  <<<<=============
    ...
    ...
    ...
}

Note: the required permission are added in to the manifest file and the file "kaAllNodesNumbered.txt" and the path is correct as well

Please help me to fin dthe where the errors come from

Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • This NPE is happening because `new FileReader(file)` is throwing a `FileNotFoundException`, and you're then continuing on to pass `this.fMR` to `new BufferedReader`. So... the file ["does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading."](https://docs.oracle.com/javase/7/docs/api/java/io/FileReader.html#FileReader(java.io.File)). – Andy Turner Aug 11 '16 at 12:03
  • @AndyTurner but the file exists in the correct path and it is accessible – Amrmsmb Aug 11 '16 at 12:09
  • Your JVM disagrees. Or it's being capricious. Either way, the NPE occurs because you're ignoring the exception. – Andy Turner Aug 11 '16 at 12:10

0 Answers0