Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8882675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:38:17+00:00 2026-06-14T20:38:17+00:00

Hi I tried to Read Any Data From A Web-Service Using Android But Every

  • 0

Hi I tried to Read Any Data From A Web-Service Using Android
But Every Time Tried I Face A problem

Today I Try To Read A Web-Service From 3schools site

use this Code

package com.example.lo2i03;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
//import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

public class MainActivity extends Activity {

    private static String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
    private static String NAMESPACE = "http://tempuri.org/";
    private static String METHOD_NAME = "CelsiusToFahrenheit";
    private static String URL = "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL";
    TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         tv = (TextView)findViewById(R.id.txt);
         SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);             
         request.addProperty("Celsius","32"); 
         SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
         envelope.setOutputSoapObject(request);
         envelope.dotNet = true;
         try
         {
               HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);          
               androidHttpTransport.call(SOAP_ACTION, envelope);             
               SoapObject result = (SoapObject)envelope.getResponse();
               tv.setText(result.getProperty(0).toString());
         }
         catch (Exception e) 
         {
              tv.setText("Error");
         }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

With Knowledge that I Added The Permission to Manifest To Access The Internet

It GOES Directly To A catch Block …

The Manifest File

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.lo2i03"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.lo2i03.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
        <uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>

Android Version : 4.2 – 4.2


LogCat Error Looks Like

11-24 01:28:29.065: E/Trace(13408): error opening trace file: No such file or directory (2)
11-24 01:28:29.195: D/AndroidRuntime(13408): Shutting down VM
11-24 01:28:29.195: W/dalvikvm(13408): threadid=1: thread exiting with uncaught exception (group=0x412862a0)
11-24 01:28:29.195: E/AndroidRuntime(13408): FATAL EXCEPTION: main
11-24 01:28:29.195: E/AndroidRuntime(13408): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lo2i03/com.example.lo2i03.MainActivity}: android.os.NetworkOnMainThreadException
11-24 01:28:29.195: E/AndroidRuntime(13408):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at android.os.Looper.loop(Looper.java:137)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at android.app.ActivityThread.main(ActivityThread.java:4898)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at java.lang.reflect.Method.invokeNative(Native Method)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at java.lang.reflect.Method.invoke(Method.java:511)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at dalvik.system.NativeStart.main(Native Method)
11-24 01:28:29.195: E/AndroidRuntime(13408): Caused by: android.os.NetworkOnMainThreadException
11-24 01:28:29.195: E/AndroidRuntime(13408):    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at java.net.InetAddress.getAllByName(InetAddress.java:214)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:76)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:146)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at com.example.lo2i03.MainActivity.onCreate(MainActivity.java:35)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at android.app.Activity.performCreate(Activity.java:5191)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
11-24 01:28:29.195: E/AndroidRuntime(13408):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
11-24 01:28:29.195: E/AndroidRuntime(13408):    ... 11 more

NEW LOGCAT (1.0)

11-24 16:28:28.850: E/Trace(25195): error opening trace file: No such file or directory (2)
11-24 16:28:28.995: D/libEGL(25195): loaded /system/lib/egl/libEGL_mali.so
11-24 16:28:28.995: D/libEGL(25195): loaded /system/lib/egl/libGLESv1_CM_mali.so
11-24 16:28:29.000: D/libEGL(25195): loaded /system/lib/egl/libGLESv2_mali.so
11-24 16:28:29.000: D/(25195): Device driver API match
11-24 16:28:29.000: D/(25195): Device driver API version: 10
11-24 16:28:29.000: D/(25195): User space API version: 10 
11-24 16:28:29.000: D/(25195): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Wed Sep 12 17:53:53 KST 2012 
11-24 16:28:29.030: D/OpenGLRenderer(25195): Enabling debug mode 0
11-24 16:28:31.215: D/dalvikvm(25195): GC_CONCURRENT freed 214K, 10% free 12330K/13575K, paused 13ms+13ms, total 40ms
11-24 16:28:39.615: W/IInputConnectionWrapper(25195): getSelectedText on inactive InputConnection
11-24 16:28:39.615: W/IInputConnectionWrapper(25195): setComposingText on inactive InputConnection
11-24 16:28:39.615: W/IInputConnectionWrapper(25195): getExtractedText on inactive InputConnection

With knowledge That I Use (WiFi) TO Access The Internet .

Any Advice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:38:19+00:00Added an answer on June 14, 2026 at 8:38 pm

    NetworkOnMainThreadException means that you is running http request code inside a UI thread.

    try something like this:

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
             tv = (TextView)findViewById(R.id.txt);
             final SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);             
             request.addProperty("Celsius","32"); 
             final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
             envelope.setOutputSoapObject(request);
             envelope.dotNet = true;
             new AsyncTask<Void, Void, Boolean>() {
                SoapObject obj;
    
                @Override
                protected Boolean doInBackground(Void... params) {
                       //here you can do your background network job
                    try
                     {
                           HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);          
                           androidHttpTransport.call(SOAP_ACTION, envelope);             
                           obj = (SoapObject)envelope.getResponse();
    
                           return true;
                     }
                     catch (Exception e) 
                     {
                         e.printStackTrace();   
                             return false;                    
                     }
                }
                @Override
                protected void onPostExecute(Boolean result) {
                 //here you can do your UI job
                    if (!result) 
                        tv.setText("Error");
                    else 
                        tv.setText(obj.getProperty(0).toString());
                    super.onPostExecute(result);
                }
            }.execute();
    
        } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using C# to read data from a Java-webservice. I've created a Service reference
Can I read an excel file without using any module? I tried like just
I tried to implement this example to write and read data from internal storage,
I tried implementing a simple web service into an asp.net application using the tutorial
I am using python's beautiful stone soup to extract data from this web page
My application gets most of its data from a php web server. My problem
HI all, When I tried to read the record of all peoples from the
I have recently tried to write an application in c# using EWS to read
All, I am trying to download the weather data history from Wunderground. The problem
My web service hosted on Play! framework. I have few image files uploaded from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.