mercredi 20 mai 2015

Save MYSQL DB Data into Android SQlite Database

i wanted to save a MYSQL DB record into SQLite DB on Android. but don't know how to implement it... getting Null pointer Exception in AddStops Function

JSON RECORD CODE

            for (int i = 0; i < jArray.length(); i++) {

                    jsonarray = jArray.getJSONArray(i);
                    stopid = jsonarray.getInt(0);
                    stopname = jsonarray.getString(1);
                    stoplaitude = jsonarray.getString(2);
                    stoplongitude = jsonarray.getString(3);


                _db.AddStops(stopid,stopname,stoplaitude,stoplongitude);


             //   Log.d("Record: ", jsonarray.toString());
                Log.d("Stop_id",String.valueOf(stopid));
                Log.d("Stop_name",stopname);
                Log.d("Stop_latitude",stoplaitude);
                Log.d("Stop_longitude",stoplongitude);

            }

DatabaseHandler Class Code

public void AddStops(int stopid, String Stopname, String Stoplatitude, String Stoplongitude)
    {


            SQLiteDatabase db = this.getWritableDatabase();
            ContentValues _values = new ContentValues();

        try {

            DBhelper.open();
            _values.put("Stop_id", stopid);
            _values.put("Stop_name", Stopname);
            _values.put("Stop_latitude", Stoplatitude);
            _values.put("Stop_longitude", Stoplongitude);

            db.insert(DATABASE_NAME, null, _values);
            db.close();

            Message.message(_context, "Data Inserted");
        }
        catch (SQLException e)
        {
            e.printStackTrace();
            Message.message(_context, "Failed to Inserted" + e);
        }

   }

Aucun commentaire:

Enregistrer un commentaire