简体   繁体   English

HttpPost适用于Android的SDK 8,但不适用于SDK 17

[英]HttpPost works on Android's SDK 8, but not SDK 17

When I insert SDK 17 into the manifest file, nothing works (it does not load). 当我将SDK 17插入清单文件时,没有任何效果(无法加载)。 But when I insert SDK 8, it works. 但是,当我插入SDK 8时,它可以工作。

private void loadq(){
        DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
        HttpPost httppost = new HttpPost("http://iwindroids.ru/app/fla/getq");
        httppost.setHeader("Content-type", "application/json");
        InputStream inputStream = null;String result = null;
        try {
            HttpResponse response = httpclient.execute(httppost);           
            HttpEntity entity = response.getEntity();
            inputStream = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null){sb.append(line + "\n");}
            result = sb.toString();
            JSONObject jObject = new JSONObject(result);
            String t = jObject.getString("t").replace("--", "—");
            String a = jObject.getString("a");
            //String i = jObject.getString("i");
            TextView et = (TextView) findViewById(R.id.textView1);
            EditText at = (EditText) findViewById(R.id.editText2);
            et.setText(t+".");
            at.setText(a);
            live();
            showTimer();
        } catch (Exception e){}
        finally {try{if(inputStream != null)inputStream.close();}catch(Exception squish){}}
    }

Thank You! 谢谢!

You have a NetworkOnMainThreadException . 您有一个NetworkOnMainThreadException Look in the LogCat to see it. 在LogCat中查看以查看它。 You have to place your code in an AsyncTask or thread. 您必须将代码放在AsyncTask或线程中。

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

相关问题 Android:不建议使用.getDrawable,最低的SDK 17解决方案? - Android: .getDrawable deprecated, minimum SDK 17 solution? HttpPost适用于Java项目,而不适用于Android - HttpPost works in Java project, not in Android 适用于 iOS 和 Android 的 uGrockIT RFID SDK - Which uGrockIT RFID SDK(s) for iOS and Android 如何从 uri 为 SDK 17 或以下为 android 获取选定的 xls 文件路径? - How to get selected xls file path from uri for SDK 17 or below for android? 别名是否适用于 Quickbooks sdk? - Is Aliasing works for Quickbooks sdk? 自sdk工具更新17以来,eclipse中的Android项目引用了“普通”java项目 - Android project referencing “normal” java project in eclipse since sdk tools update 17 从 S3 下载目录适用于 Java SDK 但不适用于 AWS CLI - Downloading a directory from S3 works with Java SDK but not AWS CLI 为什么只能在Android SDK QuickBlox上进行第一个视频通话? - Why only works the first video call on Android SDK QuickBlox? Android应用程序仅在清单中未指定sdk版本时才有效 - Android apps works only when no sdk version is specified in manifest Activity.class-类文件编辑器:JAR文件c:\\ sdk \\ platforms \\ android-17 \\ android.jar没有源附件 - Activity.class - Class File Editor: The JAR file c:\sdk\platforms\android-17\android.jar has no source attachment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM