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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:41:45+00:00 2026-06-13T05:41:45+00:00

I get a small problem: I need using async task in cocos2d-x on Android.

  • 0

I get a small problem: I need using async task in cocos2d-x on Android.

private void parseJSONJava() throws ClientProtocolException, IOException, JSONException
{
    STAJSONParser jPars = new STAJSONParser();
    jPars.makeHttpRequest(String.format("%s/app/%s/json",STA_URL,STA_APP_UID)); 
}

But this code crash application with error Can't create handler inside thread that has not called Looper.prepare(). I solve this by adding runOnUiThread:

me.runOnUiThread(new Runnable(){
public void run(){
    STAJSONParser jPars = new STAJSONParser();
    jPars.makeHttpRequest(String.format("%s/app/%s/json",STA_URL,STA_APP_UID)); 
}
});

Where “me” is my Activity.
Code from STAJSONParser:

public JSONObject makeHttpRequest(String url) {
AsyncGetJson Task= new AsyncGetJson(url);
try {
     return Task.execute().get();
} catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    return null;
 } catch (ExecutionException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    return null;
 }

AsyncGetJson task its a simple AsyncTask that get JSON from server.
So, my question: is this solution is right/wrong? Or you can give me other solution?

  • 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-13T05:41:46+00:00Added an answer on June 13, 2026 at 5:41 am

    I don’t see why you couldn’t do that. You could also use libcurl like m.ding mentioned, along with pthreads and a json parser. But the problem there is that you’d need to manage the pthreads yourself. It’s “messier” than just doing it the way you’re doing it now. Then again, using the JNI isn’t exactly pretty either. It’s one big giant trade-off, probably leaning in favor of the JNI & Android Java SDK.

    On iOS and Android, pthreads are the underlying threading mechanism, which are already managed for you when you use things like iOS’s NSOperation and Android’s AsyncTask (I’m assuming..)

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

Sidebar

Related Questions

I have a small problem in my code. I'm using fetch_assoc to get data
I have a small problem that I am hoping to get some help with.
i am trying to get notifications for a small project of mine using setTimeout
I am using reflection along with linq.Dynamic, and I am having a small problem
So, i'm building a small application using Rails. I need to use XMPP proto
I'm having a small problem with embedForm using doctrine and SF1.4 I have created
I have a small problem in java while using generics. I have a class
I have this small problem with jquery: I need to do something like this:
I get a small project to do on scoring system. I found out that
I am running g++(gcc version 3.4.4) on cygwin. I can't get this small snippet

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.