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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:53:52+00:00 2026-06-01T11:53:52+00:00

I want to change my radio button text in android app with a value

  • 0

I want to change my radio button text in android app with a value from the json object…
the q_desc textView changes… but not the the text of the radio buttons…The application after changing the q_desc text view force closes….what is my error..??? I have provided my jsp page, activity as well as my log cat..

This is my jsp code….

<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="org.json.simple.JSONObject"%>
<%@page import="java.util.*,java.sql.*"%>

 <%!
 Connection con;
 PreparedStatement ps;
 ResultSet rs;
 String x;

 %>

<%
 Class.forName("oracle.jdbc.driver.OracleDriver");
 con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","pro","pro");
 ps=con.prepareStatement("select * from c_question where id=1");
 rs=ps.executeQuery();

JSONObject obj=new JSONObject();
obj.put("id",rs.getString(1));
obj.put("desc",rs.getString(2));
obj.put("a",rs.getString(3));
obj.put("b",rs.getString(4));
obj.put("c",rs.getString(5));
obj.put("d",rs.getString(6));

out.print(obj);
out.flush();
 %>

This is my activity…

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class JsonDemo extends Activity 
{
JSONObject json;
HttpClient client;
TextView q_desc;
RadioButton rb_a;
RadioButton rb_b;
RadioButton rb_c;
RadioButton rb_d;
RadioGroup rg;


final static String URL="http://10.0.2.2:7001/project/json.jsp";

@Override
protected void onCreate(Bundle savedInstanceState) {

    // TODO Auto-generated method stub

    super.onCreate(savedInstanceState);

    setContentView(R.layout.result_json);

    q_desc=(TextView)findViewById(R.id.q_desc);
        rb_a=(RadioButton)findViewById(R.id.opt_a);
        rb_b=(RadioButton)findViewById(R.id.opt_b);
        rb_c=(RadioButton)findViewById(R.id.opt_c);
        rb_d=(RadioButton)findViewById(R.id.opt_d);

        client=new DefaultHttpClient();

       new Read().execute("desc","a","b","c","d");

}
   public  JSONObject getData()throws      ClientProtocolException,IOException,JSONException
   {

    StringBuilder url=new StringBuilder(URL);
    HttpGet get=new HttpGet(url.toString());
    HttpResponse r=client.execute(get);



    int status=r.getStatusLine().getStatusCode();

    if(status == 200)
    {
        HttpEntity e=r.getEntity();
        String data=EntityUtils.toString(e);
        JSONObject last=new JSONObject(data);
        return last;

    }
    else
    {
        Toast.makeText(JsonDemo.this, "error", Toast.LENGTH_SHORT);
        return null;
    }

}



 public class Read extends AsyncTask<String,Integer,String>
 {

@Override
protected String doInBackground(String... params) {
    // TODO Auto-generated method stub
    try {

        json=getData();
        String desc=json.getString(params[0]);
        String option_a=json.getString(params[1]);
        String option_b=json.getString(params[2]);
        String option_c=json.getString(params[3]);
        String option_d=json.getString(params[4]);
        set_ques(desc);
        set_options(option_a,option_b,option_c,option_d);

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

protected void set_ques(String desc) {
    // TODO Auto-generated method stub
    q_desc.setText(desc);
}
protected void set_options(String a,String b,String c,String d) {
    // TODO Auto-generated method stub
    rb_a.setText(a);
    rb_b.setText(b);
    rb_c.setText(c);
    rb_d.setText(d);
}


}

this is the log cat….

 04-05 22:17:52.198: W/dalvikvm(445): threadid=7: thread exiting with uncaught exception (group=0x4001d800)
 04-05 22:17:52.968: E/AndroidRuntime(445): FATAL EXCEPTION: AsyncTask #1
 04-05 22:17:52.968: E/AndroidRuntime(445): java.lang.RuntimeException: An error occured while executing doInBackground()
 04-05 22:17:52.968: E/AndroidRuntime(445):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at   java.util.concurrent.FutureTask.setException(FutureTask.java:124)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at    java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at java.lang.Thread.run(Thread.java:1096)
 04-05 22:17:52.968: E/AndroidRuntime(445): Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
 04-05 22:17:52.968: E/AndroidRuntime(445):     at android.view.ViewRoot.checkThread(ViewRoot.java:2802)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at android.view.ViewRoot.invalidateChild(ViewRoot.java:607)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at android.view.ViewRoot.invalidateChildInParent(ViewRoot.java:633)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at android.view.ViewGroup.invalidateChild(ViewGroup.java:2505)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at  android.view.View.invalidate(View.java:5139)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at android.widget.TextView.checkForRelayout(TextView.java:5364)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at android.widget.TextView.setText(TextView.java:2688)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at android.widget.TextView.setText(TextView.java:2556)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at android.widget.TextView.setText(TextView.java:2531)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at com.campuspro.start.JsonDemo$Read.set_ques(JsonDemo.java:122)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at com.campuspro.start.JsonDemo$Read.doInBackground(JsonDemo.java:101)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at com.campuspro.start.JsonDemo$Read.doInBackground(JsonDemo.java:1)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
 04-05 22:17:52.968: E/AndroidRuntime(445):     at           java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
 04-05 22:17:52.968: E/AndroidRuntime(445):     ... 4 more
  • 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-01T11:53:53+00:00Added an answer on June 1, 2026 at 11:53 am

    write this in OnPostExecute(...) Because doinbackground is non UI thread

    so you cant update your view …and after you get data from URL and its done and finally OnPostExecute is called so add this….

     String desc=json.getString(params[0]);
            String option_a=json.getString(params[1]);
            String option_b=json.getString(params[2]);
            String option_c=json.getString(params[3]);
            String option_d=json.getString(params[4]);
            set_ques(desc);
            set_options(option_a,option_b,option_c,option_d);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to change the text of a radio button (HTML element), not an
I want to change the background color of the table cell when radio button
I am trying to change the text on a radio button once it's been
I am making a radio button style in XAML and I want to change
I have a form which changes the inputfields depending on a radio-button. for text
i want change the content of a UITableView when i change a button, how
I want to change some properties of a LINQ query result object without creating
I want to change the logging level depending if I'm debbugging or not, but
I have 2 labels and 2 radio button , and I want to lay
How do you make a radiobutton where you change the drawable with android:button and

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.