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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:48:30+00:00 2026-05-29T11:48:30+00:00

I am new to Android. What I am trying to do is to get

  • 0

I am new to Android. What I am trying to do is to get a String via a web service when I press a button and write the String in a text field.

Manifext.xml:

<?xml version="1.0" encoding="utf-8"?>

<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".AndroidClientActivity"
        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>

main.xml:

<?xml version="1.0" encoding="utf-8"?>

<EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="text" >

    <requestFocus />
</EditText>

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="myClickHandler"
    android:text="Button" />
</LinearLayout>

strings.xml:

<?xml version="1.0" encoding="utf-8"?>

<string name="hello">Hello World, AndroidClientActivity!</string>
<string name="app_name">AndroidClient</string>
<string name="button">Message</string>
<string name="myClickHandler">myClickHandler</string>

AndroidClientActivity.class:

package com.maze.client;

import javax.ws.rs.core.MediaType;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;

public class AndroidClientActivity extends Activity {

private EditText text;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    text = (EditText) findViewById(R.id.editText1);
}

public void myClickHandler(View view){
    switch (view.getId()) {
    case R.id.button1:

        WebResource wbr;
        Client client = Client.create();
        wbr = client.resource("http://my.ip.address:8080/MazeService/rest/service/hello");  
        String result = wbr.queryParam("number", "10").accept(MediaType.APPLICATION_JSON).get(String.class);
            text.setText(result);
        break;
    }

}

}

This doesn’t work. I get this error in the LogCat(please help me edit it right):

02-08 23:39:04.423: E/AndroidRuntime(660): FATAL EXCEPTION: main
02-08 23:39:04.423: E/AndroidRuntime(660): java.lang.IllegalStateException: Could not execute method of the activity
02-08 23:39:04.423: E/AndroidRuntime(660):  at android.view.View$1.onClick(View.java:3044)
02-08 23:39:04.423: E/AndroidRuntime(660):  at android.view.View.performClick(View.java:3511)
02-08 23:39:04.423: E/AndroidRuntime(660):  at android.view.View$PerformClick.run(View.java:14105)
02-08 23:39:04.423: E/AndroidRuntime(660):  at android.os.Handler.handleCallback(Handler.java:605)
02-08 23:39:04.423: E/AndroidRuntime(660):  at android.os.Handler.dispatchMessage(Handler.java:92)
02-08 23:39:04.423: E/AndroidRuntime(660):  at android.os.Looper.loop(Looper.java:137)
02-08 23:39:04.423: E/AndroidRuntime(660):  at android.app.ActivityThread.main(ActivityThread.java:4424)
02-08 23:39:04.423: E/AndroidRuntime(660):  at java.lang.reflect.Method.invokeNative(Native Method)
02-08 23:39:04.423: E/AndroidRuntime(660):  at java.lang.reflect.Method.invoke(Method.java:511)
02-08 23:39:04.423: E/AndroidRuntime(660):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-08 23:39:04.423: E/AndroidRuntime(660):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-08 23:39:04.423: E/AndroidRuntime(660):  at dalvik.system.NativeStart.main(Native Method)
02-08 23:39:04.423: E/AndroidRuntime(660): Caused by: java.lang.reflect.InvocationTargetException
02-08 23:39:04.423: E/AndroidRuntime(660):  at java.lang.reflect.Method.invokeNative(Native Method)
02-08 23:39:04.423: E/AndroidRuntime(660):  at java.lang.reflect.Method.invoke(Method.java:511)
02-08 23:39:04.423: E/AndroidRuntime(660):  at android.view.View$1.onClick(View.java:3039)
02-08 23:39:04.423: E/AndroidRuntime(660):  ... 11 more
02-08 23:39:04.423: E/AndroidRuntime(660): Caused by: com.sun.jersey.api.client.ClientHandlerException: android.os.NetworkOnMainThreadException
02-08 23:39:04.423: E/AndroidRuntime(660):  at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:149)
02-08 23:39:04.423: E/AndroidRuntime(660):  at com.sun.jersey.api.client.Client.handle(Client.java:648)
02-08 23:39:04.423: E/AndroidRuntime(660):  at com.sun.jersey.api.client.WebResource.handle(WebResource.java:670)
02-08 23:39:04.423: E/AndroidRuntime(660):  at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
02-08 23:39:04.423: E/AndroidRuntime(660):  at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:503)
02-08 23:39:04.423: E/AndroidRuntime(660):  at com.maze.client.AndroidClientActivity.myClickHandler(AndroidClientActivity.java:32)
02-08 23:39:04.423: E/AndroidRuntime(660):  ... 14 more
02-08 23:39:04.423: E/AndroidRuntime(660): Caused by: android.os.NetworkOnMainThreadException
02-08 23:39:04.423: E/AndroidRuntime(660):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
02-08 23:39:04.423: E/AndroidRuntime(660):  at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
02-08 23:39:04.423: E/AndroidRuntime(660):  at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
02-08 23:39:04.423: E/AndroidRuntime(660):  at libcore.io.IoBridge.connect(IoBridge.java:112)
02-08 23:39:04.423: E/AndroidRuntime(660):  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
02-08 23:39:04.423: E/AndroidRuntime(660):  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
02-08 23:39:04.423: E/AndroidRuntime(660):  at java.net.Socket.connect(Socket.java:842)
02-08 23:39:04.423: E/AndroidRuntime(660):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:77)
02-08 23:39:04.423: E/AndroidRuntime(660):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
02-08 23:39:04.423: E/AndroidRuntime(660):  at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
02-08 23:39:04.423: E/AndroidRuntime(660):  at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
02-08 23:39:04.423: E/AndroidRuntime(660):  at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
02-08 23:39:04.423: E/AndroidRuntime(660):  at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
02-08 23:39:04.423: E/AndroidRuntime(660):  at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
02-08 23:39:04.423: E/AndroidRuntime(660):  at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
02-08 23:39:04.423: E/AndroidRuntime(660):  at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
02-08 23:39:04.423: E/AndroidRuntime(660):  at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
02-08 23:39:04.423: E/AndroidRuntime(660):  at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:479)
02-08 23:39:04.423: E/AndroidRuntime(660):  at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:240)
02-08 23:39:04.423: E/AndroidRuntime(660):  at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:147)
02-08 23:39:04.423: E/AndroidRuntime(660):  ... 19 more
02-08 23:39:08.343: I/Process(660): Sending signal. PID: 660 SIG: 9
  • 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-05-29T11:48:31+00:00Added an answer on May 29, 2026 at 11:48 am

    Buried in the stack trace is Caused by: com.sun.jersey.api.client.ClientHandlerException: android.os.NetworkOnMainThreadException on Android 3.x and up, you can’t do network I/O on the main thread (which is what you’re trying to do). You’ll want to do the network request with an AsyncTask.

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

Sidebar

Related Questions

I am new to Android. I'm trying to consume a web service that's response
I'm new in Android Programming. I'm trying to write an app that uses USB
I'm trying to share some text using an intent: Intent i = new Intent(android.content.Intent.ACTION_SEND);
I'm new to Android and SQLite, too. I'm trying to write a method where
I'm new to Android development. I'm trying to get a simple HelloWorld app going
I am trying to get the custom dialog to close on button press //set
I'm new to android and I'm trying to figure out how to get the
I'm trying to get my options menu to show up in the new Android
I am very new to Android development, and I am trying to get a
I am trying to get a random string from an array when I press

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.