Why this app stops unexpectedly???


Last Updated:

  1. assistant

    assistant Member This Topic's Starter

    Joined:
    Feb 20, 2011
    Messages:
    9
    Likes Received:
    0
    This is the code:


    Code (Text):
    1.  
    2. package com.Database2;
    3.  
    4. import java.util.Locale;
    5.  
    6. import android.app.Activity;
    7. import android.database.Cursor;
    8. import android.database.sqlite.SQLiteDatabase;
    9. import android.os.Bundle;
    10. import android.widget.AutoCompleteTextView;
    11. import android.widget.CursorAdapter;
    12. import android.widget.SimpleCursorAdapter;
    13. import android.widget.TextView;
    14.  
    15. public class Database2 extends Activity {
    16.     AutoCompleteTextView textView;
    17.     SimpleCursorAdapter adapter;
    18.     CursorAdapter adapter2;
    19.     //private static final String TAG = "test2";
    20.    
    21.    
    22.     /** Called when the activity is first created. */
    23.     @Override
    24.     public void onCreate(Bundle savedInstanceState)
    25.     {
    26.         super.onCreate(savedInstanceState);
    27.         setContentView(R.layout.main);
    28.         TextView view = (TextView) findViewById(R.id.hello);
    29.  
    30.        
    31.         SQLiteDatabase db;
    32.         db = openOrCreateDatabase("TestingData.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
    33.        
    34.         db.setVersion(1);
    35.         db.setLocale(Locale.getDefault());
    36.         db.setLockingEnabled(true);
    37.        
    38.         final String CREATE_TABLE_USERS = "CREATE TABLE IF NOT EXISTS tblUsers (" + "id INTEGER PRIMARY KEY AUTOINCREMENT," + "name TEXT, lastName TEXT);";
    39.        
    40.         db.execSQL(CREATE_TABLE_USERS);
    41.        
    42.        
    43.        
    44.         Cursor cur = db.query("tblUsers", null, null, null, null, null, null);
    45.        
    46.         String[] from = new String[] { "name", "lastName" };
    47.         int[] to = new int[] { R.id.txtName, R.id.txtLastName};
    48.        
    49.        
    50.        
    51.             textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_users);
    52.            
    53.             SimpleCursorAdapter sac = new SimpleCursorAdapter (this, R.layout.list_item, cur, from, to);
    54.             textView.setAdapter(sac);
    55.        
    56.     }
    57.  
    58. }
    59.  
    list_item.xml

    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    4.     android:layout_width="fill_parent"
    5.     android:layout_height="wrap_content"
    6.     android:stretchColumns="0"
    7.     android:padding="5dp">
    8.     <TableRow android:padding="5dp">
    9.         <LinearLayout android:orientation="horizontal">
    10.             <ImageView android:id="@+id/imgFotka"
    11.                 android:layout_width="wrap_content"
    12.                 android:layout_height="wrap_content"/>
    13.             <TextView android:id="@+id/txtIme"
    14.                 xmlns:android="http://schemas.android.com/apk/res/android"
    15.                 android:textColor="#000000"  
    16.                 android:layout_width="wrap_content"
    17.                 android:layout_height="wrap_content"
    18.                 android:textSize="18px"/>
    19.             <TextView android:id="@+id/txtPrezime"
    20.                 xmlns:android="http://schemas.android.com/apk/res/android"
    21.                 android:textColor="#000000"  
    22.                 android:layout_width="wrap_content"
    23.                 android:layout_height="wrap_content"
    24.                 android:paddingLeft="5px"
    25.                 android:textSize="18px"/>
    26.         </LinearLayout>
    27.     </TableRow>
    28. </TableLayout>
    29.  
    main.xml

    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    4.     android:orientation="vertical"
    5.     android:layout_width="fill_parent"
    6.     android:layout_height="fill_parent"
    7.     >
    8. <TextView  
    9.     android:layout_width="fill_parent"
    10.     android:layout_height="wrap_content"
    11.     android:text="@string/hello"
    12.     />
    13. <TextView  
    14.     android:id="@+id/hello"
    15.     android:layout_width="fill_parent"
    16.     android:layout_height="wrap_content"
    17.    
    18.     />
    19. <TextView
    20.         android:layout_width="wrap_content"
    21.         android:layout_height="wrap_content"
    22.         android:text="Nastavnik:" />
    23. <AutoCompleteTextView android:id="@+id/autocomplete_users"
    24.         android:layout_width="fill_parent"
    25.         android:layout_height="wrap_content"
    26.         android:layout_marginLeft="5dp"
    27.         android:completionThreshold="1"/>
    28.  
    29. </LinearLayout>
    30.  
    Under the error log windows says:

    "Error Mon Feb 28 23:49:37 CET 2011 No command output when running: 'am start -n com.Database2/com.Database2.Database2 -a android.intent.action.MAIN -c android.intent.category.LAUNCHER' on device emulator-5554"

    I am desperate because it used to work. Please HELP.

    Thanks in advance!
     

    Advertisement
  2. assistant

    assistant Member This Topic's Starter

    Joined:
    Feb 20, 2011
    Messages:
    9
    Likes Received:
    0
    I've found out what is causing the problems:

    I've remember that I've renamed the first column (id) in my database from "_id" to "id".

    Now, when I've rename it again to "_id" it works.


    Does anyone knows why?
     
  3. scrapperstoo

    scrapperstoo Member

    Joined:
    Dec 6, 2010
    Messages:
    9
    Likes Received:
    0
    SimpleCursorAdaptor needs to have the _id column to work. If you change its name, it doesn't realise it's there and throws an exception.
     
  4. assistant

    assistant Member This Topic's Starter

    Joined:
    Feb 20, 2011
    Messages:
    9
    Likes Received:
    0
    Scrapperstoo,

    Thank you for your reply.
     

Share This Page

Loading...