httppost.execute 进入异常

发布于 2024-12-06 04:28:00 字数 4483 浏览 0 评论 0原文

我已经搜索了这个网站上的每一个内容,但我仍然不明白我的代码出了什么问题,我已经调试了它,当它尝试执行这一行“HttpResponse response=httpclient.execute(httppost)”时,它也会出现异常“我还在 Android 清单文件中添加了互联网权限,但仍然不明白发生了什么事。

请帮助我,我将非常感谢你们所有人......

这是我的代码

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

         // set a click listener on the alert button
        Button alert = (Button) findViewById(R.id.alertbtn);
        alert.setOnClickListener(this);

    }

public void onClick(View view) 
    {

        if (view == findViewById(R.id.alertbtn)) 
        {

            AlertDialog.Builder alertbox = new AlertDialog.Builder(this);

            ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>(2);
            postParameters.add(new BasicNameValuePair("email","awais"));
            postParameters.add(new BasicNameValuePair("password","123"));

        try 
        {
            HttpClient httpclient=new DefaultHttpClient();
            HttpPost httppost=new HttpPost("http://localhost/doctroidlogin.php");
            httppost.setEntity(new UrlEncodedFormEntity(postParameters));
            HttpResponse response=httpclient.execute(httppost);

            HttpEntity entity=response.getEntity();

            if(entity.toString().length()>0)
            alertbox.setMessage("Welcome to DangerZone!");
            else
                alertbox.setMessage("Invalid Email or Password");   


            alertbox.show();        
        } 
        catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        }
        catch (ClientProtocolException e)
        {
            e.printStackTrace();
        } 
        catch (IOException e)
        {
            e.printStackTrace();
    }

Log Cat

09-23 00:53:51.251: WARN/System.err(327): java.net.UnknownHostException: pannl.com
09-23 00:53:51.266: WARN/System.err(327):     at java.net.InetAddress.lookupHostByName(InetAddress.java:506)
09-23 00:53:51.285: WARN/System.err(327):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:294)
09-23 00:53:51.285: WARN/System.err(327):     at java.net.InetAddress.getAllByName(InetAddress.java:256)
09-23 00:53:51.306: WARN/System.err(327):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
09-23 00:53:51.316: WARN/System.err(327):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
09-23 00:53:51.336: WARN/System.err(327):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
09-23 00:53:51.356: WARN/System.err(327):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359)
09-23 00:53:51.366: WARN/System.err(327):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
09-23 00:53:51.375: WARN/System.err(327):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
09-23 00:53:51.386: WARN/System.err(327):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
09-23 00:53:51.406: WARN/System.err(327):     at huuah.dialogboxes.LastActivity.onClick(LastActivity.java:57)
09-23 00:53:51.415: WARN/System.err(327):     at android.view.View.performClick(View.java:2485)
09-23 00:53:51.436: WARN/System.err(327):     at android.view.View$PerformClick.run(View.java:9080)
09-23 00:53:51.466: WARN/System.err(327):     at android.os.Handler.handleCallback(Handler.java:587)
09-23 00:53:51.476: WARN/System.err(327):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-23 00:53:51.486: WARN/System.err(327):     at android.os.Looper.loop(Looper.java:123)
09-23 00:53:51.506: WARN/System.err(327):     at android.app.ActivityThread.main(ActivityThread.java:3683)
09-23 00:53:51.516: WARN/System.err(327):     at java.lang.reflect.Method.invokeNative(Native Method)
09-23 00:53:51.526: WARN/System.err(327):     at java.lang.reflect.Method.invoke(Method.java:507)
09-23 00:53:51.546: WARN/System.err(327):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-23 00:53:51.566: WARN/System.err(327):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-23 00:53:51.566: WARN/System.err(327):     at dalvik.system.NativeStart.main(Native Method)

i have searched each and every thing at this site but still i don't understand what is matter with my code i have debugged it also it goes to exception when it tries to execute the this line "HttpResponse response=httpclient.execute(httppost)" i have also added permission of internet in android manifest file but still don't understand whats the matter.

please help me i shall be very thankful to all of you.....

here is my code

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

         // set a click listener on the alert button
        Button alert = (Button) findViewById(R.id.alertbtn);
        alert.setOnClickListener(this);

    }

public void onClick(View view) 
    {

        if (view == findViewById(R.id.alertbtn)) 
        {

            AlertDialog.Builder alertbox = new AlertDialog.Builder(this);

            ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>(2);
            postParameters.add(new BasicNameValuePair("email","awais"));
            postParameters.add(new BasicNameValuePair("password","123"));

        try 
        {
            HttpClient httpclient=new DefaultHttpClient();
            HttpPost httppost=new HttpPost("http://localhost/doctroidlogin.php");
            httppost.setEntity(new UrlEncodedFormEntity(postParameters));
            HttpResponse response=httpclient.execute(httppost);

            HttpEntity entity=response.getEntity();

            if(entity.toString().length()>0)
            alertbox.setMessage("Welcome to DangerZone!");
            else
                alertbox.setMessage("Invalid Email or Password");   


            alertbox.show();        
        } 
        catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        }
        catch (ClientProtocolException e)
        {
            e.printStackTrace();
        } 
        catch (IOException e)
        {
            e.printStackTrace();
    }

Log Cat

09-23 00:53:51.251: WARN/System.err(327): java.net.UnknownHostException: pannl.com
09-23 00:53:51.266: WARN/System.err(327):     at java.net.InetAddress.lookupHostByName(InetAddress.java:506)
09-23 00:53:51.285: WARN/System.err(327):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:294)
09-23 00:53:51.285: WARN/System.err(327):     at java.net.InetAddress.getAllByName(InetAddress.java:256)
09-23 00:53:51.306: WARN/System.err(327):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
09-23 00:53:51.316: WARN/System.err(327):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
09-23 00:53:51.336: WARN/System.err(327):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
09-23 00:53:51.356: WARN/System.err(327):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359)
09-23 00:53:51.366: WARN/System.err(327):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
09-23 00:53:51.375: WARN/System.err(327):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
09-23 00:53:51.386: WARN/System.err(327):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
09-23 00:53:51.406: WARN/System.err(327):     at huuah.dialogboxes.LastActivity.onClick(LastActivity.java:57)
09-23 00:53:51.415: WARN/System.err(327):     at android.view.View.performClick(View.java:2485)
09-23 00:53:51.436: WARN/System.err(327):     at android.view.View$PerformClick.run(View.java:9080)
09-23 00:53:51.466: WARN/System.err(327):     at android.os.Handler.handleCallback(Handler.java:587)
09-23 00:53:51.476: WARN/System.err(327):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-23 00:53:51.486: WARN/System.err(327):     at android.os.Looper.loop(Looper.java:123)
09-23 00:53:51.506: WARN/System.err(327):     at android.app.ActivityThread.main(ActivityThread.java:3683)
09-23 00:53:51.516: WARN/System.err(327):     at java.lang.reflect.Method.invokeNative(Native Method)
09-23 00:53:51.526: WARN/System.err(327):     at java.lang.reflect.Method.invoke(Method.java:507)
09-23 00:53:51.546: WARN/System.err(327):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-23 00:53:51.566: WARN/System.err(327):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-23 00:53:51.566: WARN/System.err(327):     at dalvik.system.NativeStart.main(Native Method)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人疚 2024-12-13 04:28:00

http://localhost 意味着您正在设备(或模拟器)上运行服务器。你是?我想不是,因为它是 php.

您必须使用服务器的真实IP或域名。

OTOH,如果您在模拟器上尝试此操作并且服务器位于您的主机上,那么您需要设置一些参数: http://juristr.com/blog/2009/10/accessing-host-machine-from-your/

http://localhost implies that you are running server on your device (or emulator). Are you? I guess not since it's php.

You have to use a real IP or domain name of the server.

OTOH if you are trying this on emulator and server is on your host machne then you need to set a few parameters: http://juristr.com/blog/2009/10/accessing-host-machine-from-your/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文