Error occurs in saving data in a database and show them in a listview in a Fragment class in android : I'm developing an android application where it uses a side navigation drawer. In the Fragment class I have an image button and it navigate to a new form to collect user data. After clicks save button, data store in database and display them in a list view in the fragment class where the form creation button is in. 

I successfully implement this scenario without using navigation drawer and fragments by following a tutorial. but when I try to implement this using fragment my app stops work. I read the logcat, but I couldn't find any error in those classes.  Please If someone could help me to resolve this problem I really appreciate your help.  

This is my Firs Fragment class

  
    
    /**
     * A simple {@link Fragment} subclass.
     */
    public class FirstFragment extends ListFragment implements android.view.View.OnClickListener {
    
        private View rootView;
        ImageButton btnAccounts;
        TextView getAll;
        TextView student_Id;
        Context context;
    
        public FirstFragment() {
            // Required empty public constructor
        }
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            // return inflater.inflate(R.layout.fragment_first, container, false);
    
    
            rootView = inflater.inflate(R.layout.fragment_first, container, false);
    
            btnAccounts = rootView.findViewById(R.id.create_account_btn);
            /* btnAccounts.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(getActivity(), AccountsType.class);
                    startActivity(intent);
                }
            }); */
    
            btnAccounts.setOnClickListener(this);
    
            getAll = rootView.findViewById(R.id.textView7);
            getAll.setOnClickListener(this);
    
                return  rootView;
    
        }
    
        @Override
        public void onClick(View view) {
            if (view == view.findViewById(R.id.create_account_btn)) {
    
                Intent intent = new Intent(getActivity(), AccountsType.class);
                intent.putExtra("account_Id", 0);
                startActivity(intent);
            }else {
    
                AccountRepo repo = new AccountRepo(this);
    
                ArrayList<HashMap<String, String>> accountList =  repo.getUserList();
                if(accountList.size()!=0) {
                    ListView lv = getListView();
                    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
                            student_Id = (TextView) view.findViewById(R.id.student_Id);
                            String accountId = student_Id.getText().toString();
                            Intent objIndent = new Intent(getActivity().getApplicationContext(),AccountsType.class);
                            objIndent.putExtra("student_Id", Integer.parseInt( accountId));
                            startActivity(objIndent);
                        }
                    });
                    ListAdapter adapter = new SimpleAdapter(getActivity(),accountList, R.layout.view_account_entry, new String[] { "id","name"}, new int[] {R.id.student_Id, R.id.student_name});
                    setListAdapter(adapter);
                }else{
                    Toast.makeText(context,"No Created Invoices!",Toast.LENGTH_SHORT).show();
                }
    
            }
        }
    }

this is the AccountRepo class
    
    /**
     * Created by User on 10/10/2017.
     */
    
    public class AccountRepo {
    
        private DBHelper dbHelper;
    
        public AccountRepo(Context context) {
            dbHelper = new DBHelper(context);
        }
    
        public AccountRepo(FirstFragment firstFragment) {
        }
    
        public int insert(AccountTypesCl account1) {
    
            //open connection to write data
            SQLiteDatabase db = dbHelper.getWritableDatabase();
            ContentValues values = new ContentValues();
            //values.put(AccountTypesCl.KEY_discount, user1.discount);
            values.put(AccountTypesCl.KEY_code, account1.code);
            values.put(AccountTypesCl.KEY_name, account1.name);
            values.put(AccountTypesCl.KEY_des, account1.des);
            //values.put(User1.KEY_date, user1.date);
    
            //Inserting row
            long account_Id = db.insert(AccountTypesCl.TABLE, null, values);
            db.close(); //close db connection
            return (int) account_Id;
        }
    
        public void delete(int account_Id) {
            SQLiteDatabase db = dbHelper.getWritableDatabase();
            db.delete(AccountTypesCl.TABLE, AccountTypesCl.KEY_ID + "= ?", new String[]{String.valueOf(account_Id)});
            db.close();
        }
    
    
        public void update(AccountTypesCl account1) {
            SQLiteDatabase db = dbHelper.getWritableDatabase();
            ContentValues values = new ContentValues();
    
            //values.put(User1.KEY_discount, user1.discount);
            values.put(AccountTypesCl.KEY_code, account1.code);
            values.put(AccountTypesCl.KEY_name, account1.name);
            values.put(AccountTypesCl.KEY_des, account1.des);
            //values.put(User1.KEY_date, user1.date);
    
            db.update(AccountTypesCl.TABLE, values, AccountTypesCl.KEY_ID + "= ?", new String[]{String.valueOf(account1.Account_ID)});
            db.close();
        }
    
        public ArrayList<HashMap<String, String>> getUserList() {
            //Open connection to read only
            SQLiteDatabase db = dbHelper.getReadableDatabase();
            String selectQuery = "SELECT  " +
                    AccountTypesCl.KEY_ID + "," +
                    AccountTypesCl.KEY_code + "," +
                    AccountTypesCl.KEY_name + "," +
                   // User1.KEY_discount + "," +
                    //User1.KEY_date + "," +
                    AccountTypesCl.KEY_des +
                    " FROM " + AccountTypesCl.TABLE;
    
            //Student student = new Student();
            ArrayList<HashMap<String, String>> userList = new ArrayList<HashMap<String, String>>();
    
            Cursor cursor = db.rawQuery(selectQuery, null);
            // looping through all rows and adding to list
    
            if (cursor.moveToFirst()) {
                do {
                    HashMap<String, String> account1 = new HashMap<String, String>();
                    account1.put("id", cursor.getString(cursor.getColumnIndex(AccountTypesCl.KEY_ID)));
                    account1.put("name", cursor.getString(cursor.getColumnIndex(AccountTypesCl.KEY_name)));
                    userList.add(account1);
    
                } while (cursor.moveToNext());
            }
    
            cursor.close();
            db.close();
            return userList;
        }
    
    
        public AccountTypesCl getUserById(int Id) {
            SQLiteDatabase db = dbHelper.getReadableDatabase();
            String selectQuery = "SELECT  " +
                    AccountTypesCl.KEY_ID + "," +
                    AccountTypesCl.KEY_code + "," +
                    AccountTypesCl.KEY_name + "," +
                    //User1.KEY_discount + "," +
                    //User1.KEY_date + "," +
                    AccountTypesCl.KEY_des +
                    " FROM " + AccountTypesCl.TABLE
                    + " WHERE " +
                    AccountTypesCl.KEY_ID + "=?";// It's a good practice to use parameter ?, instead of concatenate string
    
            int iCount = 0;
            AccountTypesCl account1 = new AccountTypesCl();
            Cursor cursor = db.rawQuery(selectQuery, new String[]{String.valueOf(Id)});
    
            if (cursor.moveToFirst()) {
                do {
                    account1.Account_ID = cursor.getInt(cursor.getColumnIndex(AccountTypesCl.KEY_ID));
                    account1.code = cursor.getString(cursor.getColumnIndex(AccountTypesCl.KEY_code));
                    account1.name = cursor.getString(cursor.getColumnIndex(AccountTypesCl.KEY_name));
                    account1.des = cursor.getString(cursor.getColumnIndex(AccountTypesCl.KEY_des));
                   // user1.date = cursor.getString(cursor.getColumnIndex(User1.KEY_date));
                    //user1.value = cursor.getString(cursor.getColumnIndex(User1.KEY_value));
    
                } while (cursor.moveToNext());
            }
    
            cursor.close();
            db.close();
            return account1;
        }
    }

this is the logcat,

    10-10 13:40:04.563 2853-2853/com.example.user.navigationdrawer E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                     Process: com.example.user.navigationdrawer, PID: 2853
                                                                                     java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.sqlite.SQLiteDatabase android.content.Context.openOrCreateDatabase(java.lang.String, int, android.database.sqlite.SQLiteDatabase$CursorFactory, android.database.DatabaseErrorHandler)' on a null object reference
                                                                                         at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
                                                                                         at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:187)
                                                                                         at com.example.user.navigationdrawer.AccountRepo.getUserList(AccountRepo.java:64)
                                                                                         at com.example.user.navigationdrawer.fragments.FirstFragment.onClick(FirstFragment.java:82)
                                                                                         at android.view.View.performClick(View.java:5198)
                                                                                         at android.view.View$PerformClick.run(View.java:21147)
                                                                                         at android.os.Handler.handleCallback(Handler.java:739)
                                                                                         at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                         at android.os.Looper.loop(Looper.java:148)
                                                                                         at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

