title: android : Unable to instantiate activity ComponentInfo java.lang.NullPointerException
body: <p>I have the error as below : </p>
  
  <pre><code>     FATAL EXCEPTION: main
  Process: com.example.jsontest, PID: 9486
  java.lang.RuntimeException: Unable to instantiate activity  ComponentInfo{com.example.jsontest/com.example.jsontest.ClosetMainActivity}: java.lang.NullPointerException
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
  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:5001)
  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:785)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
  at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.NullPointerException
  at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:109)
  at com.example.jsontest.ClosetMainActivity.&lt;init&gt;(ClosetMainActivity.java:69)
  at java.lang.Class.newInstanceImpl(Native Method)
  at java.lang.Class.newInstance(Class.java:1208)
  at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)
  </code></pre>
  
  <p>I have checked my manifest file and every activity has been added, but I still get the error. 
  I don't know why.Does anyone can help? 
  Thanks.</p>
  
  <p>The only method I use when I start the application up is:</p>
  
  <pre><code>private void DbCheckUser(){
      GlobalVariable globalVariable = (GlobalVariable)LoginActivity.this.getApplicationContext();
      String UserId = globalVariable.UserId.toString();
      String sqlString = "SELECT COUNT(fbId) AS G FROM member where fbId="+UserId;
      try{
  
          String result = DBConnector.executeQuery(sqlString,phpUrl);
          JSONArray jsonArray = new JSONArray(result);
          Log.e("result",result);
          JSONObject jsonData = jsonArray.getJSONObject(0);
  
          if (jsonData.getString("G").equals("0")){ 
  
              String ImgUrl ="http://graph.facebook.com/"+UserId+"/picture?type=large";
              String InsertMemberSqlString = "INSERT INTO member(mId, fbId, fbName, fbEmail, fbIcon, fbIconType)"
                                               +" VALUES ('','"+UserId+"','"+UserName+"','"+UserEmail+"','"+ImgUrl+"','image/png')";
              String insertResult = DBConnector.executeQuery(InsertMemberSqlString, "http://140.117.71.81/connect_to_cloze.php");
              Log.e("insertResult",insertResult);
          }
          else{ 
              String mIdSqlString = "SELECT mId FROM member WHERE fbId='"+UserId+"'";
              try{
                  String mIdResult = DBConnector.executeQuery(mIdSqlString, "http://140.117.71.81/connect_to_cloze.php");
                  JSONArray jsonArraymId = new JSONArray(mIdResult);
                  final JSONObject jsonDatamId = jsonArraymId.getJSONObject(0);
  
                  globalVariable.mId = jsonDatamId.getString("mId");
                  //mId = jsonDatamId.getString("mId");
                  Log.e("mId",globalVariable.mId);
  
                  Intent intent = new Intent();
                  intent.setClass(LoginActivity.this, ClosetMainActivity.class);
                  startActivity(intent); 
  
              }catch(Exception e){
                  Log.e("error",e.toString());
  
              }               
          }
  
      }catch(Exception e){
          Log.e("LogInError",e.toString());
  
      }
  }
  </code></pre>