Note that there are some explanatory texts on larger screens.

plurals
  1. POApp crashes when opening a class which contains a ListView
    primarykey
    data
    text
    <p>I have the following class which as you can see contains a EditText, Button and list. I want the user to type in the EditText some text,click Search and Show up the results from </p> <pre><code>SQLite database in the list below the button/edittext field. public class FindOrder extends ListActivity { private List&lt;String&gt; arr; private ListView listView; Button search; EditText search_field; String search_val; SQLiteDatabase db = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.find_order); // TODO Auto-generated method stub Log.e("myTag","in func"); search = (Button) findViewById(R.id.search_button); search_field = (EditText) findViewById(R.id.search_field); search.setOnClickListener( new View.OnClickListener() { public void onClick(View view) { search_val=search_field.getText().toString(); //getOrder(search_val); } }); } public void getOrder(String val) { Log.e("myTag","in func"); String query; String[] s_arr = new String[1]; listView = (ListView) findViewById(R.id.listView); ArrayAdapter&lt;String&gt; adapter; arr = new ArrayList&lt;String&gt;(); db = this.openOrCreateDatabase( "DBname", MODE_PRIVATE, null); query="SELECT OrderName, OrderLink, DateYear, DateMonth, DateDay, OrderPrice FROM Orders where OrderName=?"; s_arr[0]=val; Cursor c = db.rawQuery(query, s_arr); if (c != null ) { if (c.moveToFirst()) { do { arr.add(c.getString(c.getColumnIndex(DatabaseHelper.colName))); Log.e("myTag",c.getString(c.getColumnIndex(DatabaseHelper.colName))); } while (c.moveToNext()); } } c.close(); //setListAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1,arr)); adapter = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1, arr); listView.setAdapter(adapter); TextView textview = new TextView(this); LinearLayout ll2 = (LinearLayout)findViewById(R.id.linearLayout2); ll2.addView(textview); } } </code></pre> <p>Currently whenever i click on the button in Main Menu which leads to this activity, i get an FC. One of the errors i can see i the log is :</p> <pre><code>06-02 10:32:18.387: E/AndroidRuntime(1904): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Sagi.MyOrders/com.Sagi.MyOrders.FindOrder}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' </code></pre> <p>Together with many other errors . <strong>But i couldn't really understand why should i have .list attribute ...</strong></p> <p>XML :</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;LinearLayout android:id = "@+id/linearLayout1" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt; &lt;EditText android:id="@+id/search_field" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="10" &gt; &lt;/EditText&gt; &lt;Button android:id="@+id/search_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Search" /&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:id = "@+id/linearLayout2" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt; &lt;/LinearLayout&gt; &lt;ListView android:id="@+id/listView" android:layout_width="fill_parent" android:layout_height="wrap_content"/&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>Thanks !</strong></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