Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to read and store all the contacts to a list from contacts database?
    primarykey
    data
    text
    <p>I m trying to read the contacts from the contacts table and store all of them into a list variable..but not able to make out why it doesnt seem to work..gets a force close on execution.the contacts are needed to be send over a json object to a web server.</p> <pre><code> private static final String TABLE_CONTACTS = "contacts"; // contacts JSONArray JSONArray contacts = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); List&lt;contact&gt; l=new ArrayList&lt;contact&gt;(); String query="SELECT * FROM"+ TABLE_CONTACTS; DBHelper help= new DBHelper(getBaseContext()); SQLiteDatabase db=help.getWritableDatabase(); Cursor cursor = db.rawQuery(query, null); if(cursor.moveToFirst()) { do{ contact contact = new contact(); contact.setID(Integer.parseInt(cursor.getString(0))); contact.setName(cursor.getString(1)); contact.setPhoneNumber(cursor.getString(2)); Toast.makeText(this,contact.name,Toast.LENGTH_LONG); l.add(contact); } while(cursor.moveToNext()); } </code></pre> <p>and manifest file has 2 permissions</p> <pre><code> &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;uses-permission android:name="android.permission.READ_CONTACTS"/&gt; </code></pre> <p>and DBHelper class which is used to extend sqlitopenhelper to getWritableDatabase..</p> <pre><code> class DBHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "contactsManager"; // Contacts table name private static final String TABLE_CONTACTS = "contacts"; DBHelper(Context context) { super(context,DATABASE_NAME, null,1); } @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub } </code></pre> <p>}</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