[Android Q&A, Help & Troubleshooting] Junzuke:
Hello Iv been developing my app for around 2 weeks now and Iv hit a bug were I'm getting a null pointer Exception error iv been going around and around in circles trying to figure out what I'm doing wrong but im completely new to programming iv posted my code below and if you have any idea what im doing wrong please tell me

mainActivity

package com.example.joelg.clapp;

import android.database.Cursor;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.widget.ArrayAdapter;

import android.widget.ListView;

import java.util.ArrayList;

import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

ListView lstJob;

IntDataBaseHelper myhelper = new IntDataBaseHelper(this);

ArrayAdapter<String> mAdapter;

[MENTION=439709]override[/MENTION]

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

/*create instance of db helper and jobs

Create the database (only if it doesn't exists)

does so by copying from the assets */

LoadJobList();

if (CopyDBFromAssets.createDataBase(this,IntDataBaseHelper.DB_TABLE)) {

// problem area

// Get the data from the database

lstJob = (ListView) findViewById(R.id.lstJob);

ArrayList<String> jobs = myhelper.getJobList();

for (String s : jobs) {

Log.d("JobList ", "Found Job " + s);

}

} else {

throw new RuntimeException("No Usable Database exists or was copied from the assets.");

}

}

// loads job to screen

public void LoadJobList() {

ArrayList<String> JobList = myhelper.getJobList();

if (mAdapter == null) {

mAdapter = new ArrayAdapter<>(this,R.layout.header,R.id.header);

mAdapter = new ArrayAdapter<>(this,R.layout.row,R.id.BtnComplete,JobList);

mAdapter = new ArrayAdapter<>(this, R.layout.row, R.id.Job_name,JobList);

lstJob.setAdapter(mAdapter);

} else

{

mAdapter.clear();

mAdapter.addAll(JobList);

mAdapter.notifyDataSetChanged();

}

}

}

// public void JobComplete(View view){

// View parent = (View)view.getParent();

// TextView taskTextView=(TextView)parent.findViewById(R.id.BtnComplete);

// Log.e("String",(String) taskTextView.getText());

//

this is My IntDatabaseHandler file

package com.example.joelg.clapp;

import android.content.Context;

import android.database.Cursor;

import android.database.sqlite.SQLiteDatabase;

import android.database.sqlite.SQLiteException;

import android.database.sqlite.SQLiteOpenHelper;

import android.util.Log;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import java.util.ArrayList;

/**

* Created by joelg on 22/10/2017.

*/

public class IntDataBaseHelper extends SQLiteOpenHelper{

private static String DB_PATH ="/data/data/com.example.joelg.clapp/databases";

public static String DB_NAME = "JobList";

public static String DB_COLUMN = "jobNM";

public static String DB_TABLE = "job";

private static String DB_JOB_DETAILS = "jobDetails";

private static String DB_ISDONE = "jobIsDone";

public Context jobContext;

private SQLiteDatabase JobListDatabase;

/**

* constructor t

*/

public IntDataBaseHelper (Context context) {

super (context, DB_NAME,null, 1);

this.jobContext = context;

DB_PATH = jobContext.getDatabasePath(DB_NAME).getPath();

}

public void openDataBase() {

// open the database

String JobListPath = DB_PATH;

JobListDatabase = SQLiteDatabase.openDatabase(JobListPath,null,SQLiteDatabase.OPEN_READONLY);

}

// Getting Job Count

public ArrayList<String> getJobList() {

ArrayList<String> JobList = new ArrayList<>();

SQLiteDatabase db = this.getReadableDatabase();

Cursor cursor = db.query(DB_TABLE,new String[]

{DB_COLUMN},null,null,null,null,null);

while(cursor.moveToNext()){

int index = cursor.getColumnIndex(DB_COLUMN);

JobList.add(cursor.getString(index));

}

cursor.close();

db.close();

return JobList;

}

// Gets the job state if it has been competed or not

public ArrayList<String> getIsDone() {

ArrayList<String> IsDone = new ArrayList<>();

SQLiteDatabase db = this.getReadableDatabase();

Cursor cursor = db.query(DB_TABLE,new String[]{DB_ISDONE},null,null,null,null,null);

while(cursor.moveToNext()){

int index = cursor.getColumnIndex(DB_ISDONE);

IsDone.add(cursor.getString(index));

}

cursor.close();

db.close();

return IsDone;

}

[MENTION=439709]override[/MENTION]

public synchronized void close(){

if(JobListDatabase !=null){

JobListDatabase.close();

super.close();

}

}

[MENTION=439709]override[/MENTION]

public void onCreate(SQLiteDatabase db) {

}

[MENTION=439709]override[/MENTION]

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}

}

CopyDBFromAssets

package com.example.joelg.clapp;

import android.content.Context;

import android.database.sqlite.SQLiteDatabase;

import android.database.sqlite.SQLiteException;

import android.util.Log;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

/**

* Created by joelg on 24/10/2017.

*/

public class CopyDBFromAssets {

boolean copied = false;

public static boolean createDataBase(Context context, String databasename) {

boolean copied = false;

boolean dbExist = checkDataBase(context, databasename);

if (!dbExist) {

// calling this method will create an empty database

// which will hopefully be overidden, if not then

// empty database will exist ?????????

//this.getReadableDatabase(); <<<<< NOTE Commented out as empty db with no tables is useless

if (!checkAssetExists(context, databasename, "")) {

Log.e("CREATEDB", "Error getting asset " + databasename);

} else {

return copyDataBase(context, databasename);

}

return false;

}

return true;

}

private static boolean checkAssetExists(Context context, String assetfile, String path) {

boolean rv = false; // assume asset file doesn't exist

String[] assetsfound = new String[]{};

// Get the list of assets at the given path

try {

assetsfound = context.getAssets().list(path);

} catch (IOException e) {

Log.e("CHECKASSET", "IO Exception when checking for the asset file." + e.getMessage());

return false;

}

// Check to see if the desired asset (passed assetfile) exists

for (String s : assetsfound) {

if (s.equals(assetfile)) {

rv = true;

break;

}

}

if (rv) {

Log.d("CHECKASSET", "Asset " + assetfile + "was found.");

} else {

String assetlist = "";

for (String s : assetsfound) {

assetlist = assetlist + " " + s;

}

Log.e("CHECKASSET", "Asset " + assetfile +

"could not be found. Assets that exists are:- " +

assetlist

);

}

// Asset not found lets try ignoring case

if (!rv) {

for (String s : assetsfound) {

if ((s.toLowerCase()).equals(assetfile.toLowerCase())) {

Log.e("CHECKASSET", "Found asset as " + assetfile +

" but looking for " + s +

", although they are similar the case is different."

);

}

}

}

return rv;

}

// check if database exists to avoid recopying it

private static boolean checkDataBase(Context context, String database) {

SQLiteDatabase checkDB = null;

String dbpath = context.getDatabasePath(database).getPath();

try {

checkDB = SQLiteDatabase.openDatabase(dbpath, null,

SQLiteDatabase.OPEN_READONLY);

} catch (SQLiteException e) {

// database doesnt exist yet

}

if (checkDB != null) {

checkDB.close();

}

return checkDB != null ? true : false;

}

// copies db from local assets file, were it can be accessed and handled

private static boolean copyDataBase(Context context, String databasename) {

InputStream asset;

OutputStream db;

int bytescopied = 0;

int length_read;

int buffersize = 16384;

int blockcount = 0;

boolean rv = false;

try {

asset = context.getAssets().open(databasename);

} catch (IOException e) {

Log.e("COPYDB",

"IO Error opening the asset " +

databasename +

". Error Message was " +

e.getMessage()

);

return false;

}

try {

db = new FileOutputStream(context.getDatabasePath(databasename).getPath());

} catch (IOException e) {

Log.e("COPYDB",

"IO Error opening the output file for the database with path " +

databasename +

". error Message was " +

e.getMessage()

);

try {

asset.close();

} catch (IOException e2) {

Log.e("COPYDB",

"IO Error closing the asset. Message was " + e2.getMessage()

);

}

return false;

}

byte[] buffer = new byte[buffersize];

try {

while ((length_read = asset.read(buffer)) > 0) {

db.write(buffer);

bytescopied = bytescopied + length_read;

blockcount++;

rv = true;

}

} catch (IOException e) {

Log.e("COPYDB",

"IO Error Copying Database. Bytes Copied = "

+ bytescopied +

" in " +

blockcount +

" blocks of " +

buffersize

);

}

Log.d("COPYDB", "Succesfully copied Database " + databasename + " from the assets." +

" Number of bytes copied = " + bytescopied +

" in " + blockcount + " blocks of length " + buffersize

);

try {

db.flush();

db.close();

asset.close();

} catch (IOException e) {

Log.e("COPYDB",

"IO Error flushing or closing Database or closing asset."

);

}

return rv;

}

}