繁体   English   中英

Android:当我尝试打开网页时,应用程序在手机上崩溃,但在模拟器上可以正常工作

[英]Android: Application is crashing on phone but on emulator works when I'm trying to open a web page

首先,我无法将我的Galaxy s2 Android 4.0.3与我的PC连接,eclipse找不到设备,因此我必须编译并复制到我的存储卡上,然后将其安装在手机上。 我正在调试模式下进行编译。 这会是问题吗? 其次,我正在使用API​​级别10(姜饼2.3.3)来开发应用程序。

该应用程序做什么?

该应用程序。 有两个EditText(用户名和密码)和一个提交按钮。 该人员提交“表单”后,我将连接到网页,并验证该人员提供的用户名和密码是否有效。 如果有效,那么该人将被迫打开网页。 这使应用程序崩溃了。 手机显示屏变黑,并且10-15秒后,我收到一条警报,提示“应用程序已崩溃”。 在模拟器上,一切正常。

这是代码:

@Override
public void onCreate(Bundle savedInstance){
   //...
   if( checkUser(strUsername, strPassword) ){
      Intent browserInt = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.mydomain.com"));
      startActivity(browserInt);
   }
}

private boolean checkUser(String user, String pass){

        HttpClient client = new DefaultHttpClient();
        HttpGet req = new HttpGet("http://mydomain.com/login.php?u="+user+"&p="+pass+"");
        try {
            HttpResponse response = client.execute(req);

            String html = "";
            InputStream in = response.getEntity().getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            String line = "";
            while((line = reader.readLine()) != null){
                html += line;
            }

            reader.close();
            in.close();

            if(html == null || html.length() < 5) return false;

            String[] temp1 = html.split("<body>");
            String[] temp2 = temp1[1].split("</body>");

            if(!temp2[0].equals("correct")) return false;

            return true;

        } catch (ClientProtocolException e) {
            System.out.println(e);
        } catch (IOException e) {
            System.out.println(e);
        }

        return false;
    }

解决方案:我启动了CMD并键入了路径(adb.exe在其中)。 就我而言:

D:/ eclipse android / 5.sdk / sdk / platform-tools / adb.exe

然后,在设置中将DEBUG设置为启用,然后将USB插入PC。 然后我在CMD中输入了以下命令:

adb.exe启动服务器

然后,我检查了我的设备(手机)是否已连接:

adb.exe设备

他在那里。 我输入了eclipse并运行该应用程序。

在此处下载Samsung Kies,这将为您的设备安装驱动程序,然后adb将连接到您的设备,您将能够在LogCat中看到错误。 根据错误的描述,您在真实设备上的网络连接似乎很慢/不稳定,请检查它是否正常,然后重试。 与设备建立连接后,请发布错误日志。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM