Note that there are some explanatory texts on larger screens.

plurals
  1. POGarabage value in list
    primarykey
    data
    text
    <p>i'm populating a list view to view my record, i've the following code...</p> <pre><code> super.onCreate(savedInstanceState); setContentView(R.layout.total); ArrayList&lt;Object&gt; results = new ArrayList&lt;Object&gt;(); // -- SQLiteOpenHelper dbHelper = new DatabaseHelper(this, SAMPLE_DB_NAME, null, 1); SQLiteDatabase myDB = this.openOrCreateDatabase(SAMPLE_DB_NAME, SQLiteDatabase.OPEN_READONLY, null); try { /* Create the Database (no Errors if it already exists) */ myDB.execSQL("PRAGMA foreign_keys = ON;"); // -- openOrCreateDatabase(name, mode, factory) // myDB = dbHelper.getReadableDatabase(); Cursor c = myDB.query(DatabaseHelper.SAMPLE_TABLE_NAME, null, null, null, null, null, null); Cursor d = myDB.query(DatabaseHelper.SAMPLE_TABLE_NAMES, null, null, null, null, null, null); /* Check if our result was valid. */ if (c != null &amp;&amp; d != null) { c.moveToFirst(); // it's very important to do this action otherwise your Cursor object did not get work d.moveToFirst(); char cust_name = (char) c.getColumnIndex("cust_name"); char pro_name = (char) d.getColumnIndex("pro_name"); int pro_price = (int) d.getColumnIndex("pro_price"); /* Check if at least one Result was returned. */ if (c.isFirst() &amp;&amp; d.isFirst()) { int i = 0; /* Loop through all Results */ do { i++; String cust_nameColumnIndex = c.getString(cust_name); String pro_nameColumnIndex = c.getString(pro_name); int pro_priceColumnIndex = c.getInt(pro_price); /* Add current Entry to results. */ results.add("" + i + ": " + cust_name + " (" + pro_name + ": " + pro_price + ")"); } while (c.moveToNext()&amp;&amp; d.moveToNext()); } } } catch (SQLiteException e) { } finally { if (myDB != null) myDB.close(); } // -- android.R.layout.simple_list_item_1 is object which belong to ListActivity itself // -- you only need to add list object in your main layout file this.setListAdapter(new ArrayAdapter&lt;Object&gt;(this, android.R.layout.simple_list_item_1, results)); } </code></pre> <p>total.xml </p> <pre><code> &lt;ListView android:id="@id/android:list" android:layout_width="fill_parent" android:layout_height="380dp" android:cacheColorHint="#00000000" &gt; &lt;/ListView&gt; </code></pre> <p>the data is successfully inserted to sqlite (confirmed from adb shell)...it gives me garbage value...can any one please figure out the issue....Thanks in advance</p> <p><img src="https://i.stack.imgur.com/u4vK4.jpg" alt="enter image description here"></p>
    singulars
    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