title: Android - java.lang.IllegalStateException: Could not execute method of the activity
body: <p>I looked at a lot of posts with the same title, but everyone seems to have different solutions. I don't get an errors in Eclipse when it saves and compiles.</p>
  
  <p>we don't want logcat. we want succcess cast. this problem what's the problem?? if you know. would please tell me why??</p>
  
  <p><strong>Register.java</strong></p>
  
  <pre><code>    package com.example.tab;
  
      import java.io.BufferedReader;
      import java.io.IOException;
      import java.io.InputStreamReader;
      import java.io.OutputStreamWriter;
      import java.io.PrintWriter;
      import java.net.HttpURLConnection;
      import java.net.MalformedURLException;
      import java.net.URL;
  
      import android.app.Activity;
      import android.content.Intent;
      import android.os.Bundle;
      import android.view.View;
      import android.widget.EditText;
  
      public class Register extends Activity {     
  
      String myId, myPassword, myEmail, myResult; 
  
      public void onCreate(Bundle savedInstanceState) { 
          super.onCreate(savedInstanceState); 
          setContentView(R.layout.register);
      }
  
      public void RegisterClicked(View v) {
          Intent intent = null;
  
          switch(v.getId()) {
          case R.id.btn_register:
          intent = new Intent(getApplicationContext(), Register.class);
          startActivity(intent);
          finish();
  
          myId = ((EditText)(findViewById(R.id.registerName))).getText().toString();  
          myPassword = ((EditText)(findViewById(R.id.registerPassword))).getText().toString();  
          myEmail = ((EditText)(findViewById(R.id.registerEmail))).getText().toString();  
  
          httpPostData();
          }
      }
      public void httpPostData() {
          // TODO Auto-generated method stub
          try {
              URL url = new URL("http://localhost/register.php");    
                        HttpURLConnection http = (HttpURLConnection) url.openConnection();    
  
                        http.setDefaultUseCaches(false);                                            
                        http.setDoInput(true);                          
                        http.setDoOutput(true);                         
                        http.setRequestMethod("POST");          
                        http.setRequestProperty("content-type", "application/x-www-form-urlencoded"); 
                        StringBuffer buffer = new StringBuffer(); 
  
                        buffer.append("id").append("=").append(myId).append("&amp;");   
                        buffer.append("password").append("=").append(myPassword).append("&amp;");   
                        buffer.append("email").append("=").append(myEmail).append("&amp;");
                        OutputStreamWriter outStream = new OutputStreamWriter(http.getOutputStream(), "UTF-8"); 
                        PrintWriter writer = new PrintWriter(outStream); 
                        writer.write(buffer.toString()); 
                        writer.flush();
  
                        InputStreamReader tmp = new InputStreamReader(http.getInputStream(), "UTF-8");  
                        BufferedReader reader = new BufferedReader(tmp); 
                        StringBuilder builder = new StringBuilder(); 
                        String str; 
  
                        while ((str = reader.readLine()) != null) {        
                             builder.append(str + "\n");                     
                        } 
                   } catch (MalformedURLException e) { 
  
                   } catch (IOException e) { 
  
                   } 
          }
  }
  </code></pre>
  
  <p><strong>register.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="#3b3b3b" &gt;
  
      &lt;LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"
          android:padding="10dip" &gt;
          &lt;!--  View Title Label --&gt;
          &lt;TextView
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_marginBottom="10dip"
              android:text="REGISTER"
              android:textSize="25sp"
              android:textStyle="bold" /&gt;
          &lt;!--  Name Label --&gt;
          &lt;TextView
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="Name" /&gt;
          &lt;!--  Name TextField --&gt;
          &lt;EditText
              android:id="@+id/registerName"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content" /&gt;
  
          &lt;!--  Email Label --&gt;
          &lt;TextView
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="Email" /&gt;
          &lt;!--  Email TextField --&gt;
          &lt;EditText
              android:id="@+id/registerEmail"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content" /&gt;
  
          &lt;!--  Password Label --&gt;
          &lt;TextView
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="15dip"
              android:text="Password" /&gt;
          &lt;!--  Password TextField --&gt;
          &lt;EditText
              android:id="@+id/registerPassword"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:password="true" /&gt;
  
          &lt;!--  Error message --&gt;
          &lt;TextView android:id="@+id/register_error"
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content"
                      android:textColor="#e30000"
                      android:paddingTop="10dip"
                      android:textStyle="bold"/&gt;
  
          &lt;!--  Login Button --&gt;       
          &lt;Button
              android:id="@+id/btn_register"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="20dip"
              android:onClick="RegisterClicked" 
              android:text="Register" /&gt;
  
          &lt;!--  Link to Login Screen --&gt;
          &lt;Button
              android:id="@+id/btnLinkToLoginScreen"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="40dip"
              android:background="@null"
              android:text="Already registred. Login Me!"
              android:textColor="#21dbd4"
              android:textStyle="bold" /&gt;
      &lt;/LinearLayout&gt;
  
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p><strong>My Logcat</strong></p>
  
  <pre><code>  06-02 04:46:56.694: E/AndroidRuntime(2396): FATAL EXCEPTION: main 
      06-02 04:46:56.694: E/AndroidRuntime(2396): java.lang.IllegalStateException: Could not execute method of the activity
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at android.view.View$1.onClick(View.java:3597)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at android.view.View.performClick(View.java:4202)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at android.view.View$PerformClick.run(View.java:17340)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at android.os.Handler.handleCallback(Handler.java:725)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at android.os.Handler.dispatchMessage(Handler.java:92)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at android.os.Looper.loop(Looper.java:137)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at            android.app.ActivityThread.main(ActivityThread.java:5039)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at java.lang.reflect.Method.invokeNative(Native Method)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at java.lang.reflect.Method.invoke(Method.java:511)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at dalvik.system.NativeStart.main(Native Method)
     06-02 04:46:56.694: E/AndroidRuntime(2396): Caused by: java.lang.reflect.InvocationTargetException
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at java.lang.reflect.Method.invokeNative(Native Method)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at java.lang.reflect.Method.invoke(Method.java:511)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at android.view.View$1.onClick(View.java:3592)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  ... 11 more
     06-02 04:46:56.694: E/AndroidRuntime(2396): Caused by: android.os.NetworkOnMainThreadException
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at java.net.InetAddress.getAllByName(InetAddress.java:214)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at libcore.net.http.HttpConnection.&lt;init&gt;(HttpConnection.java:70)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at libcore.net.http.HttpConnection.&lt;init&gt;(HttpConnection.java:50)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:197)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at com.example.tab.Register.httpPostData(Register.java:65)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  at com.example.tab.Register.RegisterClicked(Register.java:40)
     06-02 04:46:56.694: E/AndroidRuntime(2396):  ... 14 more
     06-02 04:46:56.940: E/Trace(2420): error opening trace file: No such file or directory (2)
  </code></pre>
  
  <p><strong>AndroidManifast.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.tab"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="18" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name="com.example.tab.MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity 
              android:name=".MyTabActivity" /&gt;
          &lt;activity
              android:name=".pants10_1Activity" /&gt;
          &lt;activity
              android:name=".PhotoMainFragment" /&gt;
          &lt;activity
              android:name=".shirt10_1Activity" /&gt;
          &lt;activity
              android:name=".TabMain" /&gt;
          &lt;activity
              android:name=".Login" /&gt;
          &lt;activity
              android:name=".Register" /&gt;
          &lt;activity
              android:name=".Logout" /&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>