0

I'm making a agricultural app. And here is the code of the table where i am having problem.

db.execSQL("CREATE TABLE "+TABLE_FIELDINFO+"("
                + "_id INTEGER PRIMARY KEY AUTOINCREMENT,"
                + "FieldName TEXT,"
                + "Area TEXT,"
                + "Measure_Unit TEXT"
                + "CropGrown  TEXT"
                +"Growth_Date   INTEGER"
                +"Growth_Month   INTEGER"
                +"Growth_Year   INTEGER);");

In my app the values of fieldname,Area,Measure_unit are obtained from the user and i provided a NA(proxy value) to the crop grown. Here is my code for that. I have just included the fucntion.

 private void storetodatabase(String name,int area_vlaue,String type){
        String ss="NA";
        SQLiteOpenHelper AgroDatabase=new AgroDatabase(this);
        SQLiteDatabase database = AgroDatabase.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put("FieldName", name);
        values.put("Area", area_vlaue);
        values.put("Measure_Unit",type);
        values.put("CropGrown",ss);
        database.insert("fieldinfo", null, values);
        database.close();

} Now the app starts to crash when i make a database query including the CropGrown column. If i exclude this everything works fine but including this is causing my app to crash.I am using a list activity.

     @Override

        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_homescreen);
            ListView m_listview = (ListView) findViewById(R.id.list_view);

            SQLiteOpenHelper AgroDatabase = new AgroDatabase(this);
             db = AgroDatabase.getReadableDatabase();
            cursor=db.query("fieldinfo",new String[]{"_id",    "FieldName","Area","Measure_Unit","CropGrown"
,null,null,null,null,null);



            CursorAdapter listAdapter= new SimpleCursorAdapter(this,
                                                android.R.layout.simple_list_item_1,
                                                cursor,
                                                new String[]{"FieldName"},
                                                new int[]{android.R.id.text1},0);

            m_listview.setAdapter(listAdapter);
            m_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position,
                                        long id) {
                    Intent intent = new Intent(homescreenjava.this, Addition1.class);
                    final String name= cursor.getString(1);
                    final String Area=cursor.getString(2);
                    final String M_unit=cursor.getString(3);
                    final String Crop_grown=cursor.getString(4);
                Bundle extras = new Bundle();

                    extras.putString("name",name);
                    extras.putString("Area",Area);
                    extras.putString("Measurement Unit",M_unit);
                   extras.putString("Crop planted",Crop_grown);
                   intent.putExtras(extras);
                    startActivity(intent);


                }
            });


        } 
sagar.a
  • 814
  • 1
  • 8
  • 17

1 Answers1

1

You are missing commas in your SQL statement.

db.execSQL("CREATE TABLE "+TABLE_FIELDINFO+"("
                + "_id          INTEGER PRIMARY KEY AUTOINCREMENT, "
                + "FieldName    TEXT, "
                + "Area         TEXT, "
                + "Measure_Unit TEXT, "
                + "CropGrown    TEXT, "
                + "Growth_Date  INTEGER, "
                + "Growth_Month INTEGER, "
                + "Growth_Year  INTEGER);");
K Neeraj Lal
  • 6,560
  • 3
  • 21
  • 32