0

I have updated the script and reduced unnecessary script from my previous post.

The HTTP client is not declared within the login.java file in the doinBackground function.

The result is supposed to display is "Login success" if http response is "1" and "Login failed"if http response is "0".

But I am not getting the result I am expecting, I get always login failed. and when I also coded a display of the Http Response value in string and it gives me "org.apache.http.message.BasicHttpResponse@40e79618"

############################################
                login.java File
############################################
public class login extends Activity{

EditText un,pw;
TextView error;
Button ok;


public void onCreate(Bundle saveInstanceSate)    {

super.onCreate(saveInstanceSate);
setContentView(R.layout.main);
un = (EditText)findViewById(R.id.et_un);
pw = (EditText)findViewById(R.id.et_pw);
error = (TextView)findViewById(R.id.tv_error);
ok = (Button)findViewById(R.id.btn_login);


ok.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // Action on click of the button btn_login
        new MyHttpRequest().execute();

    }
});


}
 private class MyHttpRequest extends AsyncTask<String, Void, String>{

    ProgressDialog progress;

    public String doInBackground(String... urls){

        ArrayList<NameValuePair> postinfo = new ArrayList<NameValuePair>();
        postinfo.add(new BasicNameValuePair("username", un.getText().toString()));
        postinfo.add(new BasicNameValuePair("password", pw.getText().toString()));

        HttpClient MyhttpClient = new DefaultHttpClient();
        HttpPost MyhttpPost = new HttpPost("http://10.0.0.41/test/check.php");
        String response="";


        // Start of Http post information
        try{
            MyhttpPost.setEntity(new UrlEncodedFormEntity(postinfo));

        }catch (UnsupportedEncodingException e){
            //writing error logs
            e.printStackTrace();
        }

        // Start of HTTP Response Capture
        try{
            HttpResponse Myhttpresponse = MyhttpClient.execute(MyhttpPost);
            Log.d("Http Response:", Myhttpresponse.toString());

            // Convert my response into a string value
             response = Myhttpresponse.toString();


        // Decision based on response
        if (response.equals("1")){

            error.setText("Login Successfull. Result:" + " " +response);
        }
        else{
            error.setText("Login failed. Result:" + " " + response);
        }

    }catch (ClientProtocolException e){
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }

        // End of Do in Background
        return response;
    }

    protected void onPreExecute(){

        // Creates a progress message while connecting to the database
        progress = new ProgressDialog(login.this);
        progress.setMessage("Please wait while connecting...");
        progress.show();


    }

    public void onPostExecute(String response){

       super.onPostExecute(response);

       if(progress.isShowing()){

           progress.dismiss();
       }

    }

  }
  }
#
                        Debug Trace
#

02-16 23:36:55.345 4720-4897/com.voicetone.login2 D/Http Response:﹕ org.apache.http.message.BasicHttpResponse@40e80120 02-16 23:36:55.365 4720-4897/com.voicetone.login2 W/dalvikvm﹕ threadid=12: thread exiting with uncaught exception (group=0x40ab8228) 02-16 23:36:55.415 4720-4897/com.voicetone.login2 E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1

java.lang.RuntimeException: An error occured while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:278)
        at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
        at java.util.concurrent.FutureTask.run(FutureTask.java:137)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
        at java.lang.Thread.run(Thread.java:864)
 Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the

original thread that created a view hierarchy can touch its views. at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4132) at android.view.ViewRootImpl.invalidateChild(ViewRootImpl.java:736) at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:785) at android.view.ViewGroup.invalidateChild(ViewGroup.java:4013) at android.view.View.invalidate(View.java:8614) at android.view.View.invalidate(View.java:8565) at android.widget.TextView.checkForRelayout(TextView.java:7117) at android.widget.TextView.setText(TextView.java:3460) at android.widget.TextView.setText(TextView.java:3316) at android.widget.TextView.setText(TextView.java:3291) at com.voicetone.login2.login$MyHttpRequest.doInBackground(login.java:96) at com.voicetone.login2.login$MyHttpRequest.doInBackground(login.java:58) at android.os.AsyncTask$2.call(AsyncTask.java:264) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) at java.util.concurrent.FutureTask.run(FutureTask.java:137) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) at java.lang.Thread.run(Thread.java:864) com.android.internal.policy.impl.PhoneWindow$DecorView@40e5a668 that was originally added here android.view.WindowLeaked: Activity com.voicetone.login2.login has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40e5a668 that was originally added here at android.view.ViewRootImpl.(ViewRootImpl.java:352) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:373) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:321) at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:152) at android.view.Window$LocalWindowManager.addView(Window.java:541) at android.app.Dialog.show(Dialog.java:301) at com.voicetone.login2.login$MyHttpRequest.onPreExecute(login.java:114) at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561) at android.os.AsyncTask.execute(AsyncTask.java:511) at com.voicetone.login2.login$1.onClick(login.java:51) at android.view.View.performClick(View.java:3549) at android.view.View$PerformClick.run(View.java:14393) at android.os.Handler.handleCallback(Handler.java:605) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:4945) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method) 02-16 23:36:59.719 4720-4897/com.voicetone.login2 D/Process﹕ killProcess, pid=4720 02-16 23:36:59.739 4720-4897/com.voicetone.login2 D/Process﹕ dalvik.system.VMStack.getThreadStackTrace(Native Method) 02-16 23:36:59.819 4720-4720/com.voicetone.login2 W/IInputConnectionWrapper﹕ showStatusIcon on inactive InputConnection 02-16 23:36:59.919 4720-4720/com.voicetone.login2 W/IInputConnectionWrapper﹕ InputConnection = com.android.internal.widget.EditableInputConnection@40e50640, active client = false 02-16 23:37:00.049 4720-4897/com.voicetone.login2 D/Process﹕ java.lang.Thread.getStackTrace(Thread.java:599)

02-16 23:37:00.049 4720-4897/com.voicetone.login2 D/Process﹕ com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:104) 02-16 23:37:00.059 4720-4897/com.voicetone.login2 D/Process﹕ java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693) 02-16 23:37:00.059 4720-4897/com.voicetone.login2 D/Process﹕ java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690) 02-16 23:37:00.059 4720-4897/com.voicetone.login2 I/Process﹕ Sending signal. PID: 4720 SIG: 9 02-16 23:37:00.049 4720-4897/com.voicetone.login2 D/Process﹕ android.os.Process.killProcess(Process.java:790)

#

I added the traces you requested this time.

Please help me and if there is any link you can give with good examples that tell my mistake I will follow them.

Thank you Mad Rolly

  • Too difficult without the stacktrace... Wait until it crashes and update the question. – nKn Feb 13 '14 at 22:09
  • Might be helpful: http://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception – SteAp Feb 13 '14 at 22:12
  • You posted a lot of code. You should try from now on to post only the relevant parts. Anyway, take a better look at your AsyncTask, especially your onProgressUpdate() method. And best bet would be to show your stacktrace. – Bandreid Feb 13 '14 at 22:40
  • Thank you for your inputs guys, – user3307892 Feb 16 '14 at 13:29
  • Thank you for your inputs guys, I have updated the code above by remove the external httpClient and calling a default httpclient within the code. Then I have inserted the tarce information. Application is no more crashing but the issue now is I am not getting the result epecting. it 'looks like the if statement in the doInbackground task always produces wrong result. Please help. – user3307892 Feb 16 '14 at 13:37

0 Answers0