NullPointerException crash, using AsyncTask and db connection

66 Views Asked by At

I'm trying to connect my app with a database (mySql) and i'm using an AsyncTask function. This is a sort of introduction, the real problem comes out in the MainActivity. The app starts normally, but if i use the button to upload a single string on the db, it crashes. Here is the LogCat

06-09 16:33:12.625: E/AndroidRuntime(2048): FATAL EXCEPTION: main
06-09 16:33:12.625: E/AndroidRuntime(2048): Process: kh.edit_skill, PID: 2048
06-09 16:33:12.625: E/AndroidRuntime(2048): java.lang.NullPointerException
06-09 16:33:12.625: E/AndroidRuntime(2048):     at kh.edit_skill.MainActivity.isEmptyS(MainActivity.java:137)
06-09 16:33:12.625: E/AndroidRuntime(2048):     at kh.edit_skill.MainActivity.onClick(MainActivity.java:216)
06-09 16:33:12.625: E/AndroidRuntime(2048):     at android.view.View.performClick(View.java:4438)
06-09 16:33:12.625: E/AndroidRuntime(2048):     at android.view.View$PerformClick.run(View.java:18422)
06-09 16:33:12.625: E/AndroidRuntime(2048):     at android.os.Handler.handleCallback(Handler.java:733)
06-09 16:33:12.625: E/AndroidRuntime(2048):     at android.os.Handler.dispatchMessage(Handler.java:95)
06-09 16:33:12.625: E/AndroidRuntime(2048):     at android.os.Looper.loop(Looper.java:136)
06-09 16:33:12.625: E/AndroidRuntime(2048):     at android.app.ActivityThread.main(ActivityThread.java:5017)
06-09 16:33:12.625: E/AndroidRuntime(2048):     at java.lang.reflect.Method.invokeNative(Native Method)
06-09 16:33:12.625: E/AndroidRuntime(2048):     at java.lang.reflect.Method.invoke(Method.java:515)
06-09 16:33:12.625: E/AndroidRuntime(2048):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-09 16:33:12.625: E/AndroidRuntime(2048):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-09 16:33:12.625: E/AndroidRuntime(2048):     at dalvik.system.NativeStart.main(Native Method)

These are the 2 functions mentioned in the LogCat;

1) isEmptyS at line 137

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);          
private boolean isEmptyS (EditText myText)
{
    if(myText.getText().toString().trim().length() > 0)     <----line 137
        return false;
    else
        return true;
}

......code......
}

2) and his implementation in the onClick block

@Override
public void onClick(View v){
if(!isEmptyS(RequisitesTxt)){             <-----line 216
        String MultilineRequisites = RequisitesTxt.getText().toString();
        String Delimiter = ",";
        mySkillRequisites = MultilineRequisites.split(Delimiter);

        try{
            EditSkillRequisites(myID_Skill, myID_Community, mySkillRequisites);}
        catch(Validation_Error e){
            e.showError();}
    }

.......code........
}

P.S. i've used the same function in another app, and it works properly without errors. I checked the code so many times, I really don't know where is the problem and the difference with the working one. Ty

0

There are 0 best solutions below