title: android: saving json to sqlite
body: <p>i'm a new bie in android and java i want to save a table from sql server(external database) to sqlite(internal database).
  1. my json is not getting stored and every record is same like this  "com.example.db_client.DeptTable@b3e4e9e0" when i opens the db file in sqlite browser. I don't understand what is this.</p>
  
  <ol start="2">
  <li><p>when i run my app i sometimes get this exception and sometimes i don't.</p>
  
  <p>FATAL EXCEPTION: main
  Process: com.example.db_client, PID: 1697
  java.lang.IllegalArgumentException: Activity DeptActivity does not have a parent activity name    specified. (Did you forget to add the android.support.PARENT_ACTIVITY   element in your manifest?)</p></li>
  </ol>
  
  <p>I really need help please look into my problem. thanks in advance.</p>
  
  <p>code of database helper class</p>
  
  <pre><code>    public class SqliteDB {
  
      public static final String KEY_ID = "no";
      public static final String KEY_NAME = "name";
  
      private static final String TAG = "DBAdapter";
      private static final String DATABASE_NAME = "SQLiteDB";
  
      private static final String TABLE_NAME = "Department";
      private static final int DATABASE_VERSION = 2;
  
      private static final String CREATE_TABLE = 
              "create table departmentList (id INTEGER PRIMARY KEY, name TEXT);";
      private final Context context;
      private DatabaseHelper DBHelper;
      private SQLiteDatabase db;
  
      public SqliteDB(Context ctx) {
  
          this.context = ctx;
          DBHelper = new DatabaseHelper(context);
      }
      private static class DatabaseHelper extends SQLiteOpenHelper {
          DatabaseHelper(Context context) {           
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
      }
  
      @Override
          public void onCreate(SQLiteDatabase db) {           
              try {
                      db.execSQL(CREATE_TABLE);
                  } catch (SQLException e) {
                      e.printStackTrace();
                  }
          }
  
          @Override
          public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {   
              Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
                      + newVersion + ", which will destroy all old data");
              db.execSQL("DROP TABLE IF EXISTS sample");
              onCreate(db);
              }
          }
  
    //---open SQLite DB---
      public SqliteDB open() throws SQLException {    
          db = DBHelper.getWritableDatabase();
          return this;
      }
  
      //---close SQLite DB---
      public void close() {   
          DBHelper.close();
      }
  
      //---insert data into SQLite DB---
      public long insert(String name) {
          ContentValues initialValues = new ContentValues();
          initialValues.put(KEY_NAME, name);      
          return db.insert(TABLE_NAME, null, initialValues);
      }
  
      //---Delete All Data from table in SQLite DB---
      public void deleteAll() {
          db.delete(TABLE_NAME, null, null);
      }
  
      //---Get All Contacts from table in SQLite DB---
      public Cursor getAllData() {
          return db.query(TABLE_NAME, new String[] {KEY_NAME}, 
                  null, null, null, null, null);
      }
  
  }
  </code></pre>
  
  <p>code of activity class</p>
  
  <pre><code>public class DeptActivity extends Activity{
  
  
      ArrayAdapter&lt;String&gt; adapter;
      ListView listv;
      Context context;
      ArrayList&lt;String&gt; data;
      SqliteDB sqlite;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_dept);
  
            sqlite = new SqliteDB(DeptActivity.this);
  
            setupActionBar();
            data = new ArrayList&lt;String&gt;();
            listv = (ListView) findViewById(R.id.lv_dept);
            context = this;
  
            adapter = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1, data);
            listv.setAdapter(adapter);
            Toast.makeText(this,"Loading Please Wait..",Toast.LENGTH_SHORT).show();
            new AsyncLoadDeptDetails().execute();
      }
      public class AsyncLoadDeptDetails extends
            AsyncTask&lt;Void, JSONObject, ArrayList&lt;DeptTable&gt;&gt; {
            ArrayList&lt;DeptTable&gt; deptTable = null;
  
            @Override
            public ArrayList&lt;DeptTable&gt; doInBackground(Void... params) {
                  // TODO Auto-generated method stub
  
                  RestAPI api = new RestAPI();
                  try {
                         JSONObject jsonObj = api.GetDepartmentDetails();
                         JSONParser parser = new JSONParser();
                         Log.i( "department list", jsonObj.toString()); 
                         deptTable = parser.parseDepartment(jsonObj);
                         sqlite();
  
                  } catch (Exception e) {
                  }
            return deptTable;
        }
  
  
           private void sqlite() {
              // TODO Auto-generated method stub
  
              sqlite.open();
          for(int i=0; i&lt;deptTable.size(); i++) {
  
                  sqlite.insert(deptTable.get(i).toString());
  
              }
  
              sqlite.close();
          }   
  
            @Override
            protected void onPostExecute(ArrayList&lt;DeptTable&gt; result) {
                  // TODO Auto-generated method stub
  
                  for (int i = 0; i &lt; result.size(); i++) {
                        data.add(result.get(i).getNo() + " " + result.get(i).getName());
                  }
  
                  adapter.notifyDataSetChanged();
  
                  Toast.makeText(context,"Loading Completed",Toast.LENGTH_SHORT).show();
            } }
  </code></pre>
  
  <p>and the table which i want to save in sqlite db looks like this.
  no. name
  1   engineering
  2   finance
  3   commerce</p>
  
  <p>public class DeptTable {</p>
  
  <pre><code> int no;
   String name;
  
   public DeptTable(int no, String name) {
         super();
         this.no = no;
         this.name = name;
   }
  </code></pre>
  
  <p>code of deptTable Class</p>
  
  <pre><code>public DeptTable() {
         super();
         this.no=0;
         this.name = null;
   }
  
   public int getNo() {
         return no;
   }
   public void setNo(int no) {
         this.no = no;
   }
   public String getName() {
         return name;
   }
   public void setName(String name) {
         this.name = name;
   }
  </code></pre>
  
  <p>}
  code of json parser class</p>
  
  <pre><code>public class JSONParser  {
  
  public JSONParser()
  {
  super();
  }
  
  public ArrayList&lt;DeptTable&gt; parseDepartment(JSONObject object)
  {
        ArrayList&lt;DeptTable&gt; arrayList=new ArrayList&lt;DeptTable&gt;();
        try {
              JSONArray jsonArray=object.getJSONArray("Value");
              JSONObject jsonObj=null;
              for(int i=0;i&lt;jsonArray.length();i++)
              {
                    jsonObj =jsonArray.getJSONObject(i);
                    arrayList.add(new DeptTable(jsonObj.getInt("no"), jsonObj.getString("name")));
              }
  
        } catch (JSONException e) {
              // TODO Auto-generated catch block
              Log.d("JSONParser =&gt; parseDepartment", e.getMessage());
        }
        return arrayList;
  }
  
  public boolean parseUserAuth(JSONObject object)
  {     boolean userAtuh=false;
              try {
                    userAtuh = object.getBoolean("Value");
              } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    Log.d("JSONParser =&gt; parseUserAuth", e.getMessage());
              }
  
              return userAtuh; }
  </code></pre>
  
  <p>code of manifest
      </p>
  
  <pre><code>&lt;uses-sdk
      android:minSdkVersion="8"
      android:targetSdkVersion="21" /&gt;
  
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name=".MainActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity
          android:name="com.example.db_client.DeptActivity"
          android:label="@string/app_name" &gt;
       &lt;/activity&gt;
  
  &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>enter code here</p>