How to avoid .IllegalStateException
<pre><code>    02-09 12:06:38.745: WARN/dalvikvm(198): threadid=3: thread exiting with uncaught     exception (group=0x4001b188)
02-09 12:06:38.766: ERROR/AndroidRuntime(198): Uncaught handler: thread main exiting due   to uncaught exception
  02-09 12:06:39.415: DEBUG/dalvikvm(198): GC freed 1522 objects / 308248 bytes in 400ms
  02-09 12:06:39.574: ERROR/AndroidRuntime(198): java.lang.IllegalStateException: Could    not execute method of the activity
 02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.View$1.onClick(View.java:2031)
 02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.View.performClick(View.java:2364)
02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.View.onTouchEvent(View.java:4179)
02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at  android.widget.TextView.onTouchEvent(TextView.java:6541)
 02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.View.dispatchTouchEvent(View.java:3709)
02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
 02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
 02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
  02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
 02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
 02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
 02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
 02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.os.Handler.dispatchMessage(Handler.java:99)
  02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.os.Looper.loop(Looper.java:123)
02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.app.ActivityThread.main(ActivityThread.java:4363)
  02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at java.lang.reflect.Method.invokeNative(Native Method)
   02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at java.lang.reflect.Method.invoke(Method.java:521)
 02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
     02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at dalvik.system.NativeStart.main(Native Method)
    02-09 12:06:39.574: ERROR/AndroidRuntime(198): Caused by: java.lang.reflect.InvocationTargetException
   02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at com.ey.eyconnect.Connect_EY.btnSaveActive(Connect_EY.java:1734)
    02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at java.lang.reflect.Method.invokeNative(Native Method)
   02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at java.lang.reflect.Method.invoke(Method.java:521)
02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.View$1.onClick(View.java:2026)
  02-09 12:06:39.574: ERROR/AndroidRuntime(198):     ... 22 more
    02-09 12:06:39.574: ERROR/AndroidRuntime(198): Caused by: java.lang.IllegalStateException: Could not execute method of the activity
    02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.View$1.onClick(View.java:2031)
        02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android. view.View.performClick(View.java:2364)
           02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.View.onTouchEvent(View.java:4179)
          02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.widget.TextView.onTouchEvent(TextView.java:6541)
       02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.View.dispatchTouchEvent(View.java:3709)
      02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
      02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
           02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
        02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
      02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
            02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at              com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
      02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
    02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
  02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
    02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
    02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.os.Handler.dispatchMessage(Handler.java:99)
        02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.os.Looper.loop(Looper .java:123)
          02-09 12:06:39.574: ERROR/AndroidRuntime(198):     ... 26 more
         02-09 12:06:39.574: ERROR/AndroidRuntime(198): Caused by: java.lang.reflect.InvocationTargetException
   02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at com.ey.eyconnect.Connect_EY.btnSaveActive(Connect_EY.java:1734)
  02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at java.lang.reflect.Method.invokeNative(Native Method)
 02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at java.lang.reflect.Method.invoke(Method.java:521)
 02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.View$1.onClick(View.java:2026)
  02-09 12:06:39.574: ERROR/AndroidRuntime(198):     ... 42 more
  02-09 12:06:39.574: ERROR/AndroidRuntime(198): Caused by: java.lang.IllegalStateException: Could not execute method of the activity
     02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.View$1.onClick(View.java:2031)
    02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.View.performClick(View.java:2364)
 02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.View.onTouchEvent(View.java:4179)
       02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.widget.TextView.onTouchEvent(TextView.java:6541)
          02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.View.dispatchTouchEvent(View.java:3709)
     02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
      02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
     02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
     02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
 02-09 12:06:39.574: ERROR/AndroidRuntime(198):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:
</code></pre>

<p>I need to save a number. when i save for 5-6 times this exception is throwing..</p>

<pre><code>  its shown is the   ***background.start();
        Looper.loop(); line*** 
  background is the Thread  and my method for saving a number is :


  public void btnSave(View v) { // Save Button Invoked

 db = eventsData.getWritableDatabase();
edt = (EditText) this.findViewById(R.id.edteyconnect);
edt1 = (EditText) this.findViewById(R.id.edtpass);
String prevedt = edt.getText().toString();
String eyid = edt.getText().toString();

    Thread background = new Thread(new Runnable() {
    public void run() {
    boolean res = false;
    boolean stringres = false;
     db = eventsData.getWritableDatabase();
    String eyid = edt.getText().toString();
    Looper.prepare();
    // -------------------------------------------------------------------------
    try {

                            CharSequence char0 = "success";
        CharSequence char1 = edt2.getText().toString();

        res = result.contains(char0);
        stringres = result.contains(char1);

        Bundle bundle = new Bundle();
        bundle.putBoolean("key1", res);
        bundle.putBoolean("key2", stringres);
        bundle.putInt("flag", 1);

        Message message = new Message();
        message.setData(bundle);
        handler.sendMessage(message);

    } catch (Exception e) {
         ContentValues values = new      ContentValues();
        values.put(EventDataSQLHelper.STATUS, stat);

        db.update(EventDataSQLHelper.TABLE, values, "ID = " + eyid,
            null);

        Bundle bundle = new Bundle();
        bundle.putInt("flag", 0);

        Message message = new Message();
        message.setData(bundle);

    }
    }
});

// start the background thread
background.start();
Looper.loop();

}
</code></pre>
