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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:36:26+00:00 2026-05-30T00:36:26+00:00

i build an app which get’s content from a php file which connects to

  • 0

i build an app which get’s content from a php file which connects to a MySql server. It works on every device (based on feedback) up to 4.0
When running my app ICS, it gets an parse error or cant show the items listed. Why is this?
This is the code, where i get the content from my DB, using a PHP file:

package com.fireplace.software;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.google.gson.*;
import com.google.gson.reflect.TypeToken;

public class GetContentFromDBActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listofapps);

        LoadData();
    }


    void GenData(){
        ArrayList<ItemSkel> list = new ArrayList<ItemSkel>();
        for(int i = 0; i< 10; ++i) {
            list.add(new ItemSkel("id " + i, "label " + i, "path " + i, "description " + i, "ptype " + i));
        }

        Gson gson = new Gson();
        String json = gson.toJson(list);

        Toast.makeText(GetContentFromDBActivity.this, json, Toast.LENGTH_LONG).show();
    }

    public void btnLoadData(View v) {
        LoadData();
    }


    void LoadData(){

        //TextView v = (TextView)findViewById(R.id.txtStatusError); 
        try {

            HttpClient httpClient = new DefaultHttpClient();
            HttpContext localContext = new BasicHttpContext();
            HttpGet httpGet = new HttpGet("http://www.u2worlds.com/fp/getdata.php");
            HttpResponse response = httpClient.execute(httpGet, localContext);
            String result = "";

            BufferedReader reader = new BufferedReader(
                new InputStreamReader(
                  response.getEntity().getContent()
                )
              );

            String line = null;
            while ((line = reader.readLine()) != null)
              result += line;

            Type type = new TypeToken<ArrayList<ItemSkel>>(){}.getType();
            Gson g = new Gson();
            final ArrayList<ItemSkel> list = g.fromJson(result, type);
            ArrayList<String> stringArray = new ArrayList<String>();
            for (ItemSkel item : list) 
                stringArray.add("" + item.getLabel());

            ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, stringArray);
            ListView lv = (ListView)findViewById(R.id.lwApps); 
            lv.setAdapter(modeAdapter);

            lv.setOnItemClickListener(new OnItemClickListener() {
              public void onItemClick(AdapterView<?> parent, View view,
                  int position, long id) {
                // When clicked, show a toast with the TextView text
                  ItemSkel currentItem = list.get(position);
                  Intent i = new Intent(getApplicationContext(), ViewInfoActivity.class);
                  i.putExtra("title", currentItem.getLabel());
                  i.putExtra("icon", currentItem.getIcon());
                  i.putExtra("link", currentItem.getPath());
                  i.putExtra("desc", currentItem.getDescription());
                  i.putExtra("ptype", currentItem.getPtype());
                  startActivity(i);
                  }
            });

            //Toast.makeText(GetContentFromDBActivity.this, "No Error", Toast.LENGTH_LONG).show();
        }
        catch (Exception ex) {
            //v.setText(ex.getMessage());
            Toast.makeText(GetContentFromDBActivity.this, "Could not connect!", Toast.LENGTH_LONG).show();
        }
    }
    public void updateProgress(int currentSize, int totalSize){
        //Toast.makeText(this, "Packages: " + Long.toString((currentSize/totalSize)*100)+"% Complete", Toast.LENGTH_SHORT).show();
        }
}

Thanks

  • 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-30T00:36:28+00:00Added an answer on May 30, 2026 at 12:36 am

    Android will throw a NetworkOnMainThreadException on API Level 11 (Android 3.0) and above. As its name says, you must not open a network connection on the main thread.

    The reason for this is the principle “Designing for Responsiveness“. If your server is not available or the user is on a weak connection, your app lags because it’s waiting for a server response.

    To get some help on this, you can read this: http://saigeethamn.blogspot.com/2010/05/http-connection-using-threads-handlers.html

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

Sidebar

Related Questions

I have an app which I deploy to a physical device. The build succeeds
I have an iPad app which loads a plist from a server fine on
I would like to build an app which analyses the emotional content of speech
I'm making a Django web-app which allows a user to build up a set
I have an idea for an app that I would like to build which
I've built app using wmp.dll which is Windows System File in my XP machine.
I'm using CodeIgniter (a PHP framework) to build an app, and I have an
I'm trying to build a small app which allows downloading of multiple files at
Hey i'm trying to build an app in which the user can input some
I'am build an app with an ActionBar and two Tabs below. Everything works fine

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.