Aadhi Aadhi - 3 months ago 10
Android Question

Insert data to fragments from db. Is there any difference from common insertion method?

This is my code for insertion, When i put this code to activity it is working well, but in fragment it is not working.

View.OnClickListener addOnClickListener=new OnClickListener()
public void onClick(View v) {

String HouseName = "home";//txtName.getText().toString();
Integer HouseNumber =12; //Integer.parseInt(txtNumber.getText().toString());
String TableName="home_details";

dbhelper=new DatabaseHelper(context);
dbhelper.insertHome(HouseName, HouseNumber, sqlitedatabase);
// Toast.makeText(getActivity().getBaseContext() ,"Logout", Toast.LENGTH_SHORT).show();



try following code:

dbhelper = new DataBaseHelper(getActivity());

I think the NullPointException is because of context is null.