【问题标题】:not working on device and not on emulator不能在设备上而不是在模拟器上工作
【发布时间】:2012-01-12 09:57:00
【问题描述】:

以下代码在 android 中不起作用

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

    HttpClient httpclient = new DefaultHttpClient();

    String url = "";
    url = "http://bouncemeinws.cloudapp.net/BounceMeInWebService.asmx/GetAllMerchantNotification";              
    String url1= "http://182.71.82.154/BounceMeInWS/BounceMeInWebService.asmx/GetAllMerchantNotification";      
    HttpPost httppost = new HttpPost(url);
    try {   
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("UserID", "130"));            
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response = httpclient.execute(httppost);
        System.out.println("status code--->"+ response.getStatusLine().getStatusCode());
        // HttpEntity responseEntity = response.getEntity();
        InputStream in = response.getEntity().getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        StringBuffer responseString = new StringBuffer("");
        String line;
        while ((line = reader.readLine()) != null) {
            responseString.append(line + "\n");
        }
        System.out.println("response is -->" + responseString.toString());

    } catch (Exception e) {
        e.printStackTrace();
    }

}

运行时错误体 {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} p {font-family:"Verdana";font-weight:normal;color:黑色;margin-top:-5px}b {font-family:"Verdana";font-weight:bold;color:black;margin-top:-5px}H1 {font-family:"Verdana";font-weight:正常;字体大小:18pt;颜色:红色 }H2 { 字体家族:“Verdana”;字体粗细:正常;字体大小:14pt;颜色:栗色 }pre {字体家族:“Lucida Console”;字体-size:.9em} .marker {字体粗细:粗体;颜色:黑色;文字装饰:无;}.version {颜色:灰色;} .error {margin-bottom: 10px;}.expandable { text-decoration:underline;字体粗细:粗体;颜色:海军蓝;光标:手; }

“/”应用程序中的服务器错误。

运行时错误

描述:服务器上出现应用程序错误。此应用程序的当前自定义错误设置可防止远程查看应用程序错误的详细信息(出于安全原因)。但是,本地服务器计算机上运行的浏览器可以查看它。

详细信息:要使此特定错误消息的详细信息可以在远程计算机上查看,请创建一个 标签位于当前 Web 应用程序的根目录中的“web.config”配置文件中。然后,该 标记应将其“模式”属性设置为“关闭”。

<pre> &lt;!-- Web.Config Configuration File --&gt; &lt;configuration&gt; &lt;system.web&gt; &lt;customErrors mode="Off"/&gt; &lt;/system.web&gt; &lt;/configuration&gt;</pre>
注意:您看到的当前错误页面可以被替换通过修改应用程序的 配置标记的“defaultRedirect”属性以指向自定义错误页面 URL 来创建自定义错误页面。

<!-- Web.Config Configuration File ->
 <configuration> <system.web><customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/></system.web> </configuration>

【问题讨论】:

  • 欢迎来到 SO! - “不工作”???来吧,我们需要更多细节。例外?日志猫?错误描述?
  • 可能是因为尝试从onCreate(...) 的网络下载东西而导致 ANR,但正如 Guillaume 所说 - 我们需要更多详细信息。

标签: android parsing


【解决方案1】:

我猜:你使用的是 Gingerbread 或 Android 3+

在这种情况下,系统只会终止您的应用,因为您在 UI 线程中进行网络 IO。

参见例如this answer.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-12
    • 1970-01-01
    • 2011-08-22
    • 1970-01-01
    • 1970-01-01
    • 2015-08-14
    • 2016-04-09
    相关资源
    最近更新 更多