title: calling a boolean method from another class
body: <p>I am trying to call a boolean from another class, to check for internet connection. </p>
  
  <p>calling code is </p>
  
  <pre><code>public void submit_user(View view){
      EditText editText = (EditText) findViewById(R.id.new_username);
      String user_name = editText.getText().toString();
      EditText pw = (EditText)findViewById(R.id.new_password);
      String pwd = pw.getText().toString();
  
      MyActivity my = new MyActivity();
      if(my.isConnected()) {
          //do something
      }
  }
  </code></pre>
  
  <p>boolean method is:</p>
  
  <pre><code>public boolean isConnected(){
      ConnectivityManager connMgr = (ConnectivityManager)
              getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
      if (networkInfo != null &amp;&amp; networkInfo.isConnected()) {
          return true;
      }else{
          return false;
      }
  }
  </code></pre>
  
  <p>error message:</p>
  
  <pre><code>FATAL EXCEPTION: main
  
                                                                                     Caused by: java.lang.reflect.InvocationTargetException
                                                                                        at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                        at java.lang.reflect.Method.invoke(Method.java:525)
  
  
                                                                                     Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()
  </code></pre>
  
  <p>tried to post error message, but won't let me submit.</p>
  
  <p>new at this, appreciate help. Thank you in advance.</p>
  
  <p>Richard</p>