{"id":3447,"date":"2014-03-25T11:24:37","date_gmt":"2014-03-25T11:24:37","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/25\/nullpointerexception-crash-collection-of-common-programming-errors\/"},"modified":"2014-03-25T11:24:37","modified_gmt":"2014-03-25T11:24:37","slug":"nullpointerexception-crash-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/25\/nullpointerexception-crash-collection-of-common-programming-errors\/","title":{"rendered":"NullPointerException Crash-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m getting a crash with a nullpointer expection. I&#8217;m getting the suer to sign up and I&#8217;m not sure if it&#8217;s my backend that&#8217;s failing. I&#8217;ve pointed my app to my php file and I&#8217;ve checked my Apache log and it is getting there.<\/p>\n<p>code:<\/p>\n<pre><code>signUpButton.setOnClickListener(new OnClickListener(){\n        public void onClick(View arg0) \n        {                       \n        if (usernameText.length() &gt; 0 &amp;&amp;        \n                        passwordText.length() &gt; 0 &amp;&amp; \n                        passwordAgainText.length() &gt; 0 &amp;&amp;\n                        eMailText.length() &gt; 0\n                        )\n                    {\n                        \/\/TODO check email adress is valid\n\n                        if (passwordText.getText().toString().equals(passwordAgainText.getText().toString())){\n\n                            if (usernameText.length() &gt;= 5 &amp;&amp; passwordText.length() &gt;= 5) {\n\n                                    Thread thread = new Thread(){\n                                        String result = new String();\n                                        @Override\n                                        public void run() {\n                                            result = imService.signUpUser(usernameText.getText().toString(), \n                                                    passwordText.getText().toString(), \n                                                    eMailText.getText().toString());\n\n                                            handler.post(new Runnable(){\n\n                                                public void run() {\n                                                    if (result.equals(SERVER_RES_RES_SIGN_UP_SUCCESFULL)) {\n                                                        showDialog(SIGN_UP_SUCCESSFULL);\n                                                    }\n                                                    else if (result.equals(SERVER_RES_SIGN_UP_USERNAME_CRASHED)){\n                                                        showDialog(SIGN_UP_USERNAME_CRASHED);\n                                                    }\n                                                    else  if (result.equals(SERVER_RES_SIGN_UP_FAILED)) \n                                                    {\n                                                        showDialog(SIGN_UP_FAILED);\n                                                    }           \n                                                }\n\n                                            });\n                                        }\n\n                                    };\n                                    thread.start();\n                            }\n                            else{\n                                showDialog(USERNAME_AND_PASSWORD_LENGTH_SHORT);\n                            }                           \n                        }\n                        else {\n                            showDialog(TYPE_SAME_PASSWORD_IN_PASSWORD_FIELDS);\n                        }\n\n                    }\n                    else {\n                        showDialog(FILL_ALL_FIELDS);\n\n                    }               \n                }           \n            });\n\n            cancelButton.setOnClickListener(new OnClickListener(){\n                public void onClick(View arg0) {\n                Toast.makeText(getApplicationContext(), \"Sorry! Please try again.\", Toast.LENGTH_SHORT).show();\n                {                   \n                }               \n            }});\n\n\n        }\n\n\n    protected Dialog onCreateDialog(int id) \n    {       \n\n        switch (id) \n        {\n            case TYPE_SAME_PASSWORD_IN_PASSWORD_FIELDS:         \n                return new AlertDialog.Builder(SignUp.this)       \n                .setMessage(R.string.signup_type_same_password_in_password_fields)\n                .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {\n                    public void onClick(DialogInterface dialog, int whichButton) {\n                        \/* User clicked OK so do some stuff *\/\n                    }\n                })        \n                .create();          \n            case FILL_ALL_FIELDS:               \n                return new AlertDialog.Builder(SignUp.this)       \n                .setMessage(R.string.signup_fill_all_fields)\n                .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {\n                    public void onClick(DialogInterface dialog, int whichButton) {\n                        \/* User clicked OK so do some stuff *\/\n                    }\n                })        \n                .create();\n            case SIGN_UP_FAILED:\n                return new AlertDialog.Builder(SignUp.this)       \n                .setMessage(R.string.signup_failed)\n                .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {\n                    public void onClick(DialogInterface dialog, int whichButton) {\n                        \/* User clicked OK so do some stuff *\/\n                    }\n                })        \n                .create();\n            case SIGN_UP_USERNAME_CRASHED:\n                return new AlertDialog.Builder(SignUp.this)       \n                .setMessage(R.string.signup_username_crashed)\n                .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {\n                    public void onClick(DialogInterface dialog, int whichButton) {\n                        \/* User clicked OK so do some stuff *\/\n                    }\n                })        \n                .create();\n            case SIGN_UP_SUCCESSFULL:\n                return new AlertDialog.Builder(SignUp.this)       \n                .setMessage(R.string.signup_successfull)\n                .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {\n                    public void onClick(DialogInterface dialog, int whichButton) {\n                        finish();\n                    }\n                })        \n                .create();  \n            case USERNAME_AND_PASSWORD_LENGTH_SHORT:\n                return new AlertDialog.Builder(SignUp.this)       \n                .setMessage(R.string.username_and_password_length_short)\n                .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {\n                    public void onClick(DialogInterface dialog, int whichButton) {\n                        \/* User clicked OK so do some stuff *\/\n                    }\n                })        \n                .create();\n            default:\n                return null;\n\n        }\n\n\n    }\n\n    @Override\n    protected void onResume() {\n        bindService(new Intent(SignUp.this, IMService.class), mConnection , Context.BIND_AUTO_CREATE);\n\n        super.onResume();\n    }\n\n    @Override\n    protected void onPause() \n    {\n        unbindService(mConnection);\n        super.onPause();\n    }\n\n\n\n}\n<\/code><\/pre>\n<p>LogCat: 05-21 13:47:22.237: E\/AndroidRuntime(522): FATAL EXCEPTION: main<\/p>\n<pre><code>05-21 13:47:22.237: E\/AndroidRuntime(522): java.lang.NullPointerException \n\n05-21 13:47:22.237: E\/AndroidRuntime(522):  at com.mekya.SignUp$2$1$1.run(SignUp.java:113) \n\n05-21 13:47:22.237: E\/AndroidRuntime(522):  at android.os.Handler.handleCallback(Handler.java:587) \n\n05-21 13:47:22.237: E\/AndroidRuntime(522):  at android.os.Handler.dispatchMessage(Handler.java:92) \n\n05-21 13:47:22.237: E\/AndroidRuntime(522):  at android.os.Looper.loop(Looper.java:123) 05-21 13:47:22.237: E\/AndroidRuntime(522):   at android.app.ActivityThread.main(ActivityThread.java:4627) \n\n05-21 13:47:22.237: E\/AndroidRuntime(522):  at java.lang.reflect.Method.invokeNative(Native Method) \n\n05-21 13:47:22.237: E\/AndroidRuntime(522):  at java.lang.reflect.Method.invoke(Method.java:521) \n\n05-21 13:47:22.237: E\/AndroidRuntime(522):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 05-21 13:47:22.237: E\/AndroidRuntime(522):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) \n\n05-21 13:47:22.237: E\/AndroidRuntime(522):  at dalvik.system.NativeStart.main(Native Method)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m getting a crash with a nullpointer expection. I&#8217;m getting the suer to sign up and I&#8217;m not sure if it&#8217;s my backend that&#8217;s failing. I&#8217;ve pointed my app to my php file and I&#8217;ve checked my Apache log and it is getting there. code: signUpButton.setOnClickListener(new OnClickListener(){ public void onClick(View arg0) { if (usernameText.length() &gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3447","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3447","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3447"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3447\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}