بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]
پرسش و پاسخ

گرفتن اطلاعت از اینترنت در ویو پیجر

مدیریت گفتگو
umbrella931 12 سال پیش
آخرین تغییر: 12 سال پیش

با سلام خدمت بچه های سایت من داخل برنامم باید در ویوپیجر به اینترنت متصل بشم اما ارورandroid.os.NetworkOnMainThreadException میده کدها رو زیر میزارم اگه کسی تونست کمک کنه خیلی ممنونش میشم

 public class Webservice {

    public static String readUrl(String url, ArrayList<NameValuePair> params) {
        try {
            HttpClient client = new DefaultHttpClient();
            HttpPost method = new HttpPost(url);

            if (params != null) {
                method.setEntity(new UrlEncodedFormEntity(params));
            }

            HttpResponse response = client.execute(method);//ارور از این خط میگیره

            InputStream inputStream = response.getEntity().getContent();
            String result = convertInputStreamToString(inputStream);

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

        return null;
    }


    private static String convertInputStreamToString(InputStream inputStream) {
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            StringBuilder builder = new StringBuilder();

            String line = "";

            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }

            return builder.toString();
        }
        catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }
}

 

 

 

نظرات

Spirit 12 سال پیش
معلومه آموزش ها رو ندیدین یا با بی دقتی تمام دیدین ، برای اطلاعات بیشتر عبارت NetworkOnMainThreadException رو در سایتمون جستجو کنید :)
umbrella931 12 سال پیش
ممنون قبل از اینکه شما جواب بدید درست شد باید tagetsdk رو میزاشتم روی8
Spirit 12 سال پیش
برنامه تون رو چه نسخه از اندروید اجرا میشه؟

هنوز پاسخی ثبت نشده است


پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .