Note that there are some explanatory texts on larger screens.

plurals
  1. POError android database
    primarykey
    data
    text
    <p>There is no error in eclipse but when I run it is "forced to stop" with the following exception:</p> <pre><code>Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' </code></pre> <p>here the LogCat output</p> <pre><code>07-11 11:09:45.242: WARN/dalvikvm(590): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): FATAL EXCEPTION: main 07-11 11:09:45.303: ERROR/AndroidRuntime(590): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.example.events/org.example.events.Events}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 07-11 11:09:45.303: ERROR/AndroidRuntime(590): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): at android.os.Handler.dispatchMessage(Handler.java:99) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): at android.os.Looper.loop(Looper.java:123) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): at android.app.ActivityThread.main(ActivityThread.java:4627) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): at java.lang.reflect.Method.invokeNative(Native Method) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): at java.lang.reflect.Method.invoke(Method.java:521) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): at dalvik.system.NativeStart.main(Native Method) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 07-11 11:09:45.303: ERROR/AndroidRuntime(590): at android.app.ListActivity.onContentChanged(ListActivity.java:245) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): at android.app.Activity.setContentView(Activity.java:1647) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): at org.example.events.Events.onCreate(Events.java:23) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 07-11 11:09:45.303: ERROR/AndroidRuntime(590): ... 11 more </code></pre> <p>This is my code in eventsActivity</p> <pre><code>package org.example.events; //import android.app.Activity; import android.app.ListActivity; import android.os.Bundle; import static android.provider.BaseColumns._ID; import static org.example.events.Constants.TABLE_NAME; import static org.example.events.Constants.TIME; import static org.example.events.Constants.TITLE; //import android.app.Activity; import android.content.ContentValues; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; //import android.os.Bundle; import android.widget.TextView; public class Events extends ListActivity { /** Called when the activity is first created. */ private EventsData events; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); events = new EventsData(this); try { addEvent("Hello, Android!"); Cursor cursor = getEvents(); showEvents(cursor); } finally { events.close(); } } private void addEvent(String string) { // Insert a new record into the Events data source. // You would do something similar for delete and update. SQLiteDatabase db = events.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(TIME, System.currentTimeMillis()); values.put(TITLE, string); db.insertOrThrow(TABLE_NAME, null, values); } private static String[] FROM = { _ID, TIME, TITLE, }; private static String ORDER_BY = TIME + " DESC"; private Cursor getEvents() { // Perform a managed query. The Activity will handle closing // and re-querying the cursor when needed. SQLiteDatabase db = events.getReadableDatabase(); Cursor cursor = db.query(TABLE_NAME, FROM, null, null, null, null, ORDER_BY); startManagingCursor(cursor); return cursor; } private void showEvents(Cursor cursor) { // Stuff them all into a big string StringBuilder builder = new StringBuilder("Saved events:\n"); while (cursor.moveToNext()) { // Could use getColumnIndexOrThrow() to get indexes long id = cursor.getLong(0); long time = cursor.getLong(1); String title = cursor.getString(2); builder.append(id).append(": "); builder.append(time).append(": "); builder.append(title).append("\n"); } // Display on the screen TextView text = (TextView) findViewById(R.id.text); text.setText(builder); } /*private static int[] TO = { R.id.rowid, R.id.time, R.id.title, }; private void showEvents(Cursor cursor) { // Set up data binding SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item, cursor, FROM, TO); setListAdapter(adapter); }*/ } </code></pre> <p>Here is event manifest </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.example.events" android:versionCode="1" android:versionName="1.0"&gt; &lt;uses-sdk android:minSdkVersion="8" /&gt; &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;activity android:name=".Events" 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=".Constants" android:label="@string/app_name"&gt; &lt;/activity&gt; &lt;activity android:name=".EventsData" android:label="@string/app_name"&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>Here is my layout main.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;TextView android:id="@+id/text" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;/ScrollView&gt; </code></pre>
    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.
 

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