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 9144071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:10:45+00:00 2026-06-17T10:10:45+00:00

I am running a simple project where on clicking a button in android. A

  • 0

I am running a simple project where on clicking a button in android. A message is displayed returned from a webservice whose coding is done in java.

Here is my program in eclipse for Android:

@Override
public void onClick(View v) {
    final String url = "http://10.0.2.2:8050/WebPractice/PracticeWebServices?wsdl";
    final String namespace = "http://PracticeWebServices/";
    final String methodName = "hello";
    final String action = namespace + methodName;

    if(v.getId() == submit_btn.getId()) {
        SoapObject so = new SoapObject(namespace, methodName);
        so.addProperty("name", "Arjun");
        SoapSerializationEnvelope sse = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        sse.setOutputSoapObject(so);
        HttpTransportSE hse = new HttpTransportSE(url);

        try {
            hse.call(action, sse);
            SoapPrimitive primitive = (SoapPrimitive)sse.getResponse();
            Toast.makeText(getApplicationContext(),primitive.toString() , Toast.LENGTH_SHORT);
        } catch(IOException e) {
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        }
    }
}

Following is my code in Java:

@WebService(serviceName = "PracticeWebServices")
public class PracticeWebServices {

    @WebMethod(operationName = "hello")
    public String hello(@WebParam(name = "name") String name) {
        return "Hello " + name + " !";
    }
}

I’ve included the internet permission in manifest file….

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Now, when I’m running the file in the emulator provided in Eclipse. On clicking the button it shows me a message Unfortunately the program has stopped

When i checked the logCat….Seems like i m hitting an exception at android.os.NetworkOnMainThreadException

  • 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-17T10:10:47+00:00Added an answer on June 17, 2026 at 10:10 am

    You should put your long networking fetching operation in either a Thread or AsyncTask

    I suggest you to use AsyncTask

    you can do something like this by creating a class that extends AsyncTask

    private class LongNetworkOperation extends AsyncTask<String, Void, String> {
    
        @Override
        protected String doInBackground(String... params) {
    
            SoapObject so = new SoapObject(namespace, methodName);
            so.addProperty("name", "Arjun");
            SoapSerializationEnvelope sse = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            sse.setOutputSoapObject(so);
            HttpTransportSE hse = new HttpTransportSE(url);
    
            try {
                hse.call(action, sse);
                SoapPrimitive primitive = (SoapPrimitive)sse.getResponse();
                Toast.makeText(getApplicationContext(),primitive.toString() , Toast.LENGTH_SHORT);
            } catch(IOException e) {
                e.printStackTrace();
            } catch (XmlPullParserException e) {
                e.printStackTrace();
            }
        }
    }
    

    and you can call it on your onClick() like this

    @Override
    public void onClick(View v) {
        if(v.getId()==submit_btn.getId()) {
            new LongNetworkOperation.execute();
        }
    }
    

    Also I suggest you to show a ProgressDialog on onPreExecute() and hide it in onPostExecute() so that the user will be aware of the long background process which is highly recommended for long operations

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Eclipse, running a project is as simple as clicking the run button. In
I'm running a simple Java program with below directory structure: MyProject (A project in
I have a simple project with only one button in it,but when running,these errors
I am building a simple Android project in eclipse that uses the google-api-java-client .
Let me describe a simple use-case: Running all tests in our project may take
I am running a simple join query select count(*) from t1 join t2 on
I'm just setting up stylus on a simple project and am running this command
Using the Python templates for Xcode, I have a simple project running on one
I'm running a simple Django project on Heroku. It works, but if I get
I am running a simple hello world web server project with maven, jetty, scala,

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.