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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:45:49+00:00 2026-05-30T14:45:49+00:00

I have a problem with this code. This is a tutorial code that show

  • 0

I have a problem with this code. This is a tutorial code that show how to get and show data from mysql DB. But when I try to run it I am getting a problem window that application has stopped unexpectedly. Any ideas how to fix it?

public class FoodActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    String result = null;
    InputStream input = null;
    StringBuilder sbuilder = null;
    ArrayList <NameValuePair> nameValuePairs = new ArrayList <NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("1","Avinas"));

    try{
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://ik.su.lt/~jbarzelis/Bandymas/index.php");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        input = entity.getContent();

    }
    catch(Exception e){
        Log.e("log_tag","Error in internet connection"+e.toString());
    }
    try{
        BufferedReader reader = new BufferedReader(new InputStreamReader(input,"iso-8859-1"),8);
        sbuilder = new StringBuilder();

        String line = null;

        while((line = reader.readLine()) != null){
            sbuilder.append(line + "\n");
        }
        input.close();
        result = sbuilder.toString();
    }
    catch(Exception e){
        Log.e("log_tag", "Error converting result "+e.toString());          
    }
    int fd_id;
    String fd_name;
    try{
        JSONArray jArray = new JSONArray(result);
        JSONObject json_data = null;
        for(int i=0;i<jArray.length();i++){
            json_data = jArray.getJSONObject(i);
            fd_id = json_data.getInt("FOOD_ID");
            fd_name = json_data.getString("FOOD_NAME");
        }

        }
    catch(JSONException e1){
        Toast.makeText(getBaseContext(), "No food found", Toast.LENGTH_LONG).show();
    }
    catch(ParseException e1){
        e1.printStackTrace();
    }
}

}

  • 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-30T14:45:50+00:00Added an answer on May 30, 2026 at 2:45 pm

    Try adding the following to your AndroidManifest.xml before the opening <application element…

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

    EDIT:

    The reason you’re getting warnings about fd_id and fd_name never being read is because they never are. All you do in this code…

    for(int i=0;i<jArray.length();i++){
        json_data = jArray.getJSONObject(i);
        fd_id = json_data.getInt("FOOD_ID");
        fd_name = json_data.getString("FOOD_NAME");
    }
    

    …is parse the JSON array using those variables (fd_id and fd_name) but you never do anything with them and there’s no more code after that block (except for the catch blocks which do nothing unless there’s an exception).

    Try logging those variables as follows…

    for(int i=0;i<jArray.length();i++){
        json_data = jArray.getJSONObject(i);
        fd_id = json_data.getInt("FOOD_ID");
        fd_name = json_data.getString("FOOD_NAME");
        Log.d("XYZ", "fd_id: " + fd_id);
        Log.d("XYZ", "fd_name: " + fd_name);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with this code: file = tempfile.TemporaryFile(mode='wrb') file.write(base64.b64decode(data)) file.flush() os.fsync(file) # file.seek(0)
I have this code, but I have a problem. When I update but do
I try to get this code running. I am almost there but I got
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
Hi i have problem with this code, i found it on the internet and
i am a beginner and i have a problem : this code doesnt compile
I'm a beginner with jdbc ... I have a problem running this code :
I have a problem with this is code: Set oXmlHTTP = CreateObject(Microsoft.XMLHTTP) oXmlHTTP.Open POST,
Never thought I'd have this problem :) The following snippet of code works in
Problem Hello all! I have this code which takes my jpg image loops through

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.