Note that there are some explanatory texts on larger screens.

plurals
  1. POto insert float values entered in EditText into databse of android thru sqlite helper
    primarykey
    data
    text
    <p>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....</p> <p>problem is related to typecasting.. what i think so ... </p> <pre><code>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); } </code></pre> <p>I have problem in</p> <pre><code>IngredientQuantity=(EditText)findViewById(R.id.lnrAddIngredients_edtxtQuantity); IngredientCost=(EditText)findViewById(R.id.lnrAddIngredients_edtxtCost); </code></pre> <p>These two edit boxes return Float values entered by the user...</p> <p>Following is my onsave code for button click which passes the values to the SQLHelper class here i named that "MenuManagement_SQLHelper"</p> <pre><code>private View.OnClickListener onSave=new View.OnClickListener() { @Override public void onClick(View v) { helper.insertIngredients(IngredientName.getText().toString(), IngredientQuantityfloat, IngredientUnit.getText().toString(), IngredientCostfloat); } }; </code></pre> <p>the following code is for sqlhelper class :-</p> <pre><code>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); } </code></pre> <p>problem I am facing :- IngredientQuantityfloat cannot be resolved to a variable IngredientQuantityfloat cannot be resolved to a variable</p> <p>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"</p> <p>after parsing now it is giving that</p> <p>cannot be resolved to variable ...</p> <p>sdk information(although not required)</p> <pre><code> android:versionCode="1" android:versionName="1.0" android:minSdkVersion="8" </code></pre> <p>thnx in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload