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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:30:20+00:00 2026-06-03T12:30:20+00:00

I have the following code which is meant to access the local database and

  • 0

I have the following code which is meant to access the local database and return a single value (for testing purposes the value is ‘lasagna’. It should return it and make it of the name of an item in the list.
The application crashes when the activity is accessed.

Im really stuck and any help would be great.

public class RecipeMethodActivity extends ListActivity {

Intent myIntent;
String value;
TextView editvalue;
TextView buttonPressed;
Intent intent;
String result = null;
InputStream is = null;
StringBuilder sb=null;
String result2 = null;


final Recipe[] mRecipesArray = {    new Recipe("Lasagna",  new String[]{"1 Brown lean ground beef in skillet until lightly browned and cooked through. Put a few layers of paper towels in large bowl. With slotted spoon, remove browned beef from skillet draining off excess beef fat and put on top of blotting towels. After all the browned beef has been removed from the skillet, drain off and dispose of excess beef fat. Wipe skillet clean with paper towel. (If your ground beef is sufficiently lean, there will not be any excess fat to drain.)Add diced green pepper and onion to skillet. Brown for a few minutes on medium high heat. Add the garlic and cook for 30 seconds more. Add browned beef back to the skillet, lower the heat to low and continue to cook for 5 more minutes stirring frequently.", 
                                                "2 Transfer browned beef, green pepper and onions to 3 Qt. pot. Add tomato sauce, tomato paste. Open stewed tomatoes and dice, then add to 3 Qt. pot. Add oregano, parsley, Italian Spice Mix to taste, probably 2 teaspoons of each. Add a pinch of garlic powder and a pinch of garlic salt, to taste. Add a dash of white wine vinegar. Add sugar a tablespoon at a time, until desired level of sweetness, no more than 1/4 cup of sugar. Note that it is hard to follow a pure recipe when it comes to pasta sauce. One Italian spice mix is not like the other, nor is one can of tomato sauce not like the other. So you really do need to taste the sauce as you are adding the spices, sugar and vinegar. Stir and allow sauce to simmer 15-45 minutes to thicken (do not scorch bottom, stir frequently). Remove from heat.",
                                                "3 Cook lasagna noodles in 6 Qt. Pot per cooking directions (al dente). (Note noodles may be cooked in advance.) Stir often to prevent from sticking and be sure that water remains at a boil during the entire cooking to prevent noodles from sticking. I add Tbsp of salt to the water so the noodles are more flavorful. Drain in colander and place in a cool water filled pan to keep from drying out and sticking together.",
                                                "4 In dry lasagna pan, ladle one cup of sauce and spread along the bottom of the pan. Apply a layer noodles 3 length wise (edges overlapping). Ladle in sauce sparingly into center trough of 3 noodles. Apply a layer of mozzarella cheese slices on top of lasagna sauce. Place ricotta cheese dollops every 2 inches in center of noodles on top of mozzarella cheese slices, sprinkle grated parmesan cheese in thin even layer on top of ricotta cheese. Apply second layer of noodles, topping again with sauce and cheese. Finish with another layer of noodles. If you have extra sauce and cheese you can spread that over the top. Tent lasagna pan with aluminum foil (not touching noodles or sauce). Bake at 375°F for 45 minutes. Allow to cool before serving."}),
                                    new Recipe(result, new String[]{"GlaDOS' wit","Is a lie"}),
                                    new Recipe("EarthDestruction", new String[]{"Asteroid", "Kinetic energy"})};

public class Recipe{
    public String name;
    public String[] steps;

    Recipe(String name, String[] steps){
        this.name = name;
        this.steps = steps;
    }
}

public ArrayList<String> FetchRecipesRawArray(Recipe[] recipes){
    ArrayList<String> ret = new ArrayList<String>();
    for(int i=0;i<recipes.length;i++){
        ret.add(recipes[i].name);
    }
    return ret;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);    

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, FetchRecipesRawArray(mRecipesArray));
    setListAdapter(adapter); 

    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

    try{
                    HttpClient httpclient = new DefaultHttpClient();
                    HttpPost httppost = new HttpPost("http://127.0.0.1/index.php");
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                    HttpResponse response = httpclient.execute(httppost);
                    HttpEntity entity = response.getEntity();
                    is = entity.getContent();
                }catch(Exception e){
                    Log.e("log_tag", "Error in http connection"+e.toString());
                }
                //convert response to string
                try{
                    BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                    sb = new StringBuilder();
                    sb.append(reader.readLine() + "\n");
                    String line="0";
                    while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                    }
                    is.close();
                    result=sb.toString();
                    Toast.makeText(getBaseContext(), result, Toast.LENGTH_LONG).show();
                }catch(Exception e){
                    Log.e("log_tag", "Error converting result "+e.toString());
                }
                //paring data
                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_name=json_data.getString("recipename");
                    }
                }catch(JSONException e1){
                    Toast.makeText(getBaseContext(), "No Food Found", Toast.LENGTH_LONG).show();
                }catch (ParseException e1){
                    e1.printStackTrace();
                }



}

protected void onListItemClick(ListView l, View v, int position, long id){
    Intent intent = new Intent(this, MethodActivity.class);
    intent.putExtra(MethodActivity.EXTRA_RECIPEARRAY, mRecipesArray[position].steps);
    startActivity(intent);

}
}  

I am presented with the error of not retrieving data even though there is data in the database. What could the problem be?

My php is:

<?php
mysql_connect("localhost","root","michael2020");
mysql_select_db("finalyearproject");

$q=mysql_query("SELECT recipename FROM recipes WHERE     recipename>'".$_REQUEST['value']."'");
while($e=mysql_fetch_assoc($q))
    $output[]=$e;

print(json_encode($output));

mysql_close();
?>
  • 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-03T12:30:25+00:00Added an answer on June 3, 2026 at 12:30 pm

    Just Try this one .

    $q=mysql_query("SELECT recipename as recipe FROM recipes WHERE     recipename>'".$_REQUEST['value']."'");
    
    while($e=mysql_fetch_assoc($q))
        $output=$e['recipe'];
    
    print(json_encode($output));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which sometimes return as true and sometimes doesn't. Any
I have the following code which should put programs startable in Bash. if [
I have the following code which is meant to cycle through names submitted on
I have following code which works for radio buttons but need to be changed
I want to know is below code correct ? I have following code which
I'm trying to use opengl in C#. I have following code which fails with
I have following Code Block Which I tried to optimize in the Optimized section
I have the following code which throws an exception COM Exception was unhandled in
I have the following code which inserts multiple records into MySQL: foreach ($_POST AS
I have the following code which works just fine when the method is POST,

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.