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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:15:57+00:00 2026-06-02T05:15:57+00:00

Hello I am new for the android,so please let me know where I am

  • 0

Hello I am new for the android,so please let me know where I am wrong.

I want convert the jsonarray into custom listview.I tried much but I don’t get the solution.
I got the value that I want into strValue1(please check the below code ,Activites_Activity.java).
Now ,I want to pass this strValue1 into the listview.
but I am not able to convert it into listview.

so Please let me know what i should do?

I got the error

04-17 12:52:55.795: E/AndroidRuntime(765): FATAL EXCEPTION: AsyncTask #1
04-17 12:52:55.795: E/AndroidRuntime(765): java.lang.RuntimeException: An error occured               while executing doInBackground()
04-17 12:52:55.795: E/AndroidRuntime(765):  at android.os.AsyncTask$3.done(AsyncTask.java:200)
04-17 12:52:55.795: E/AndroidRuntime(765):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
04-17 12:52:55.795: E/AndroidRuntime(765):  at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
04-17 12:52:55.795: E/AndroidRuntime(765):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
04-17 12:52:55.795: E/AndroidRuntime(765):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-17 12:52:55.795: E/AndroidRuntime(765):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
04-17 12:52:55.795: E/AndroidRuntime(765):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
04-17 12:52:55.795: E/AndroidRuntime(765):  at java.lang.Thread.run(Thread.java:1096)
04-17 12:52:55.795: E/AndroidRuntime(765): Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
04-17 12:52:55.795: E/AndroidRuntime(765):  at android.view.ViewRoot.checkThread(ViewRoot.java:2802)
04-17 12:52:55.795: E/AndroidRuntime(765):  at android.view.ViewRoot.focusableViewAvailable(ViewRoot.java:1596)
04-17 12:52:55.795: E/AndroidRuntime(765):  at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:451)
04-17 12:52:55.795: E/AndroidRuntime(765):  at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:451)
04-17 12:52:55.795: E/AndroidRuntime(765):  at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:451)
04-17 12:52:55.795: E/AndroidRuntime(765):  at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:451)
04-17 12:52:55.795: E/AndroidRuntime(765):  at android.view.View.setFlags(View.java:4474)
04-17 12:52:55.795: E/AndroidRuntime(765):  at android.view.View.setFocusableInTouchMode(View.java:3104)
04-17 12:52:55.795: E/AndroidRuntime(765):  at android.widget.AdapterView.checkFocus(AdapterView.java:694)
04-17 12:52:55.795: E/AndroidRuntime(765):  at android.widget.ListView.setAdapter(ListView.java:437)
04-17 12:52:55.795: E/AndroidRuntime(765):  at com.rahul.cheerfoolz.activites.Activites_Activity$activites.doInBackground(Activites_Activity.java:141)
04-17 12:52:55.795: E/AndroidRuntime(765):  at com.rahul.cheerfoolz.activites.Activites_Activity$activites.doInBackground(Activites_Activity.java:1)
04-17 12:52:55.795: E/AndroidRuntime(765):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-17 12:52:55.795: E/AndroidRuntime(765):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-17 12:52:55.795: E/AndroidRuntime(765):  ... 4 more

Thanks.

Activites_Activity.java

public class Activites_Activity extends CheerfoolznativeActivity {

 TextView txtactivity;
 ListView list;
 LazyAdapter adapter;
 ImageView img;
 ProgressBar pgb;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_activites);
    setHeader("Activites");

/*
     list=(ListView)findViewById(R.id.activity_listView);
    adapter=new LazyAdapter(this, mImages,mTitle);
    list.setAdapter(adapter);
*/
    txtactivity = (TextView) findViewById(R.id.activity_textView);
    img=(ImageView)findViewById(R.id.activity_image);
    pgb = (ProgressBar)findViewById(R.id.activity_progressBar);
    new activites().execute();
}

public class activites extends AsyncTask<Void, Void, Void> {
    String parsedString = "\n";  
    String strValue1 ;
    public int i=0;

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
         pgb.setVisibility(View.VISIBLE);
    }

    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub
        String url = " Here my json URL ";

        String strResponse = util.makeWebCall(url);

        try {
            JSONObject objResponse = new JSONObject(strResponse);

            JSONArray jsonnodes = objResponse.getJSONArray(API.cheerfoolz_activities.NODES);
            Log.i(" NO of entries===>" +Activites_Activity.class.getName(),"Number of entries " + jsonnodes.length());

            ArrayList<String> items = new ArrayList<String>();

            for (i = 0; i < jsonnodes.length(); i++) 
            {
                String str = Integer.toString(i); 
                Log.i("Value of i",str);

                JSONObject jsonnode = jsonnodes.getJSONObject(i); 

                JSONObject jsonnodevalue = jsonnode.getJSONObject(API.cheerfoolz_activities.NODE);

                strValue1 = jsonnodevalue.getString(API.cheerfoolz_activities.TITLE);

                Log.i("JSONArray", strValue1);
                //parsedString += " \n\n Value of stored parse :  => " + strValue1;
                parsedString = parsedString.trim(); //this will remove the blank white space

                items.add(strValue1);

                parsedString += " \n Value added in list  => " + items;

                Log.i("Value of items : ", parsedString);



            }


            //List<String> list = Arrays.asList((String[])jsonnodes.toString());
            //String[] values= new String[]{items.toString()};
            //myListView.setListAdapter(

            /* list=(ListView)findViewById(R.id.activity_listView);
               // adapter=new LazyAdapter((Activity) getApplicationContext(), mImages,mTitle);
                list.setAdapter(adapter);*/

            ListView myListView = (ListView)findViewById(R.id.activity_listView);
            myListView.setAdapter(new ArrayAdapter(getApplicationContext(), android.R.layout.simple_expandable_list_item_1, items));

    //      ArrayAdapter<String> adapter= new ArrayAdapter<String>(Activites_Activity.this, android.R.layout.simple_list_item_1,items);
    //      myListView.setAdapter(adapter);
            //Log.i("contact", items1 );

        }
        catch (JSONException e) {

            e.printStackTrace();
            txtactivity.setText(e.getMessage());

        }

        return null;
    }

    @Override
    protected void onProgressUpdate(Void... values) {
        // TODO Auto-generated method stub
        super.onProgressUpdate(values);
    }

    @Override
    public void onPostExecute(Void result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);

        txtactivity.setText(parsedString);
        pgb.setVisibility(View.GONE);
        //img.setImageResource(parsedString);
    }
}

}

LazyAdapter.java

public class LazyAdapter extends BaseAdapter{

private Activity context;
private String[] title;
private String[] images;
private LayoutInflater inflater;


public LazyAdapter(Activity context,String[] img ,String[] title) {  
    super();  

    this.context = context;  
    this.title = title;  
    this.images = img; 

    this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
}  

@Override  
public int getCount() {  
    // TODO Auto-generated method stub  
    return title.length;  
}  

@Override  
public Object getItem(int position) {  
    // TODO Auto-generated method stub  
    return null;  
}  

@Override  
public long getItemId(int position) {  
    // TODO Auto-generated method stub  
    return 0;  
}  

public static class ViewHolder  
{  
    ImageView imgViewLogo;  
    TextView txtViewTitle;  

}  

@Override  
public View getView(int position, View convertView, ViewGroup parent) {  
    // TODO Auto-generated method stub  

    ViewHolder holder;  
    if(convertView==null)  
    {  
        holder = new ViewHolder();  
        convertView = inflater.inflate(R.layout.activity_listitem, null);  

        holder.imgViewLogo = (ImageView) convertView.findViewById(R.id.activity_list_logo);  
        holder.txtViewTitle = (TextView) convertView.findViewById(R.id.activity_list_title);  

        convertView.setTag(holder);  
    }  
    else  
        holder=(ViewHolder)convertView.getTag();  

 //  holder.imgViewLogo.setImageResource(images[position]);  
    holder.txtViewTitle.setText(title[position]);  


    return convertView;  
}   

}

makeWebCall.class

public static String makeWebCall(String url) {

    DefaultHttpClient client = new DefaultHttpClient();

    HttpGet httpRequest = new HttpGet(url);

    try {

        HttpResponse httpResponse = client.execute(httpRequest);

         final int statusCode = httpResponse.getStatusLine().getStatusCode();

         if (statusCode != HttpStatus.SC_OK) {
          /*  Log.i(getClass().getSimpleName(),
                "Error => " + statusCode + " => for URL " + url);*/
            return null;
         }

         HttpEntity entity = httpResponse.getEntity();
            InputStream is = entity.getContent();
            return iStream_to_String(is);
    }
    catch (IOException e) {
        httpRequest.abort();
      // Log.w(getClass().getSimpleName(), "Error for URL =>" + url, e);
    }

    return null;

 }


public static String iStream_to_String(InputStream is1)
{
     BufferedReader rd = new BufferedReader(new InputStreamReader(is1), 4096);
     String line;
     StringBuilder sb =  new StringBuilder();
     try {
        while ((line = rd.readLine()) != null) {
                sb.append(line);
         }
         rd.close();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     String contentOfMyInputStream = sb.toString();
     return contentOfMyInputStream;
}
  • 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-02T05:15:58+00:00Added an answer on June 2, 2026 at 5:15 am

    Assuming your ListView modifications are right, then move this code:

    ListView myListView = (ListView)findViewById(R.id.activity_listView);
                myListView.setAdapter(new ArrayAdapter(getApplicationContext(), android.R.layout.simple_expandable_list_item_1, items));
    

    from the AsyncTask‘s doInBackground method into the onPostExecute function. You can’t modify any Views from inside doInBackground, you must do it in one of the callback functions that are guaranteed to be run on the event dispatch thread.

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

Sidebar

Related Questions

Hello everyone please help me out regarding menu in android . i want to
Hello I am new to android. I want to calculate amount in my application.
I am new to Android development and I want first to get the Hello
Hello i am new in android and i really need help with something. I
Hello StackOverflow Users, I am new to android and trying to develop a game
Hello I am new to Android programming and I am a bit rusty with
Im very new to this android development.I just started to create a hello world
Hello I am new to android programming, I haven't started writing the code for
Hello i m new to android and working on Radio application i gt stuck
I'm new to Android, I've followed the hello world tutorial through and have a

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.