I want to add some data to sqlite dy fragmnet.but when i Run the code it gives this error..

  java.lang.RuntimeException: Unable to start activity ComponentInfo{codes.project.sameera.o_project/codes.project.sameera.o_project.Indi_Add_Details_menu}: java.lang.NullPointerException

i can add data to sqlite by this code without using Fragment.but when i convert my class into Fragmnet this happen.

How Can i fix this..?

this is my Fragment_addStudentDetails class

public class Fragment_addStudentDetails extends Fragment implements View.OnClickListener {
EditText fName,mName, Address, sName, hNo, mNo, presentSpo;


DatabaseAdapter databaseHelper;
Button btnAdd;
Button btnView;

@Override
public View onCreateView(LayoutInflater inflater,
                         ViewGroup container, Bundle savedInstanceState) {
    View view=inflater.inflate(R.layout.fragment_add_student_details,container,false);

    fName=(EditText) view.findViewById(R.id.editTextfname);
    mName=(EditText) view.findViewById(R.id.editTextmName);
    Address = (EditText) view.findViewById(R.id.editTextAdd);
    sName = (EditText) view.findViewById(R.id.editTextsure);
    hNo = (EditText) view.findViewById(R.id.editTexttpH);
    mNo = (EditText) view.findViewById(R.id.editTextTPM);
    presentSpo = (EditText) view.findViewById(R.id.editTextPS);

    btnAdd = (Button) view.findViewById(R.id.btnAdd);
    btnView = (Button) view.findViewById(R.id.btnView);
    btnAdd.setOnClickListener(this);
    btnView.setOnClickListener(this);
    databaseHelper = new DatabaseAdapter(getActivity());

    return view;
}
@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.btnAdd:
            addStudent(view);
            break;
        case R.id.btnView:
            viewDetails(view);

            break;

        default:
            break;
    }
}
public void addStudent(View view){
    String fname = fName.getText().toString();
    String mname = mName.getText().toString();
    String sname = sName.getText().toString();
    String address = Address.getText().toString();
    String TPhome = hNo.getText().toString();
    String TPmobile = mNo.getText().toString();
    String presentsport = presentSpo.getText().toString();

    long id= databaseHelper.insertData(fname, mname, sname, address, TPhome, TPmobile, presentsport);
    if(id<0){
        Message.message(getActivity(),"Error inInsertiong Data");
    }else
    {
        Message.message(getActivity(),"Succecsfuly inserted to data");

    }

}

public void viewDetails(View view){
    String data = databaseHelper.getAllData();
    Message.message(getActivity(),data);
}

}

log cat

        java.lang.RuntimeException: Unable to start activity ComponentInfo{codes.project.sameera.o_project/codes.project.sameera.o_project.Indi_Add_Details_menu}: java.lang.NullPointerException
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
         at android.app.ActivityThread.access$800(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.NullPointerException
        at codes.project.sameera.o_project.Fragment_addStudentDetails.onCreateView(Fragment_addStudentDetails.java:38)
        at android.app.Fragment.performCreateView(Fragment.java:1700)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
        at android.app.BackStackRecord.run(BackStackRecord.java:684)
        at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
        at android.app.Activity.performStart(Activity.java:5240)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168)

           

Related posts

Recent Viewed