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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:23:51+00:00 2026-05-29T19:23:51+00:00

I am new to java and new to Android also… i tried to search

  • 0

I am new to java and new to Android also…
i tried to search the same problem but i am sorry if itz already there as i was not able to understand that if any….

problem is related to typecasting.. what i think so …

public class Ingredients_Add extends Activity {

    EditText IngredientName=null;
    EditText IngredientQuantity=null;
    EditText IngredientUnit=null;
    EditText IngredientCost=null;
    MenuManagement_SQLHelper helper=null;

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

        helper=new MenuManagement_SQLHelper(this);
        IngredientName=(EditText)findViewById(R.id.lnrAddIngredients_edtxtName);
        IngredientQuantity=(EditText)findViewById(R.id.lnrAddIngredients_edtxtQuantity);
        IngredientUnit=(EditText)findViewById(R.id.lnrAddIngredients_edtxtUnit);
        IngredientCost=(EditText)findViewById(R.id.lnrAddIngredients_edtxtCost);

        float IngredientQuantityfloat=Float.valueOf(IngredientQuantity.getText().toString());
        float IngredientCostfloat=Float.valueOf(IngredientCost.getText().toString()); 

        Button SaveIngredients=(Button)findViewById(R.id.lnrAddIngredients_btnSave);
        SaveIngredients.setOnClickListener(onSave);
    }

I have problem in

IngredientQuantity=(EditText)findViewById(R.id.lnrAddIngredients_edtxtQuantity);
IngredientCost=(EditText)findViewById(R.id.lnrAddIngredients_edtxtCost);

These two edit boxes return Float values entered by the user…

Following is my onsave code for button click which passes the values to the
SQLHelper class here i named that “MenuManagement_SQLHelper”

private View.OnClickListener onSave=new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            helper.insertIngredients(IngredientName.getText().toString(), IngredientQuantityfloat, IngredientUnit.getText().toString(), IngredientCostfloat);
        }
    };

the following code is for sqlhelper class :-

public class MenuManagement_SQLHelper extends SQLiteOpenHelper {

    private static final String DATABASE_NAME="menu_management.db";
    private static final int SCHEMA_VERSION=1;

    public MenuManagement_SQLHelper(Context context) {
        super(context, DATABASE_NAME,null,SCHEMA_VERSION);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL("CREATE TABLE tblIngredients (_id INTEGER PRIMARY KEY AUTOINCREMENT, Ingredient_name TEXT,Ingredient_quantity FLOAT,Ingredient_unit TEXT,Ingredient_cost FLOAT);");

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub

    }

    public void insertIngredients(String IngredientName,Float IngredientQuantity,String IngredientUnit,Float Ingredientcost){
        ContentValues cv= new ContentValues();
        cv.put("IngredientName", IngredientName);
        cv.put("IngredientQuantity", IngredientQuantity);
        cv.put("IngredientUnit", IngredientUnit);
        cv.put("Ingredientcost", Ingredientcost);
        getWritableDatabase().insert("tblIngredients","IngredientName", cv);
    }

problem I am facing :-
IngredientQuantityfloat cannot be resolved to a variable
IngredientQuantityfloat cannot be resolved to a variable

the problem is coming for float variables…
earlier it was function mismatch as i was passing strings and there in sqlhelper it was declared as float -> “that u have to convert it into float”

after parsing now it is giving that

cannot be resolved to variable …

sdk information(although not required)

 android:versionCode="1"
android:versionName="1.0" 
android:minSdkVersion="8"

thnx in advance

  • 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-29T19:23:53+00:00Added an answer on May 29, 2026 at 7:23 pm

    It looks like a scope problem to me. You defined IngredientQuantityfloat in the onCreate method of your activity, but you’re (probably) trying to reference it in your OnClickListener (onSave?).

    public void onCreate(Bundle savedInstanceState) {
        ...
        float IngredientQuantityfloat=Float.valueOf(IngredientQuantity.getText().toString());
        ...
    }
    
    public void onClick(View v) {
        ...
        helper.insertIngredients(IngredientName.getText().toString(), IngredientQuantityfloat, IngredientUnit.getText().toString(), IngredientCostfloat);
        ...
    }
    

    In other words: IngredientQuantityfloat is locally declared and only exists within the onCreate method. If you want to access it from another part of your activity, you need to make it a class variable/member:

    public class Ingredients_Add extends Activity {
    
        float IngredientQuantityfloat;
        EditText IngredientName=null;
        ...
    
        public void onCreate(Bundle savedInstanceState) {
           ...
           IngredientQuantityfloat=Float.valueOf(IngredientQuantity.getText().toString());
           ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I'm both new to Java and to creating android apps, but not new
I'm new to Java/Eclipse/Android, so this is probably an easy (if not stupid) question:
I am new to Android and also to java. in my application exactly what
I'm new to Android(and Java also) and I'm trying to understand what are Fields
I am very new to android. Also very new to java, so please feel
I have to admit that I'm new to Java and Android. db4o seems to
Firstly I am new to android and Java so this is a beginners question.
I am completely new to android, and pretty much a Java newb. I have
I'm completely new to Java/Android and am stuck with listviews. What I want is
I'm new to Android so sorry if the question is easy to answer. I

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.