Why this app stops unexpectedly???


  1. assistant

    assistant Member

    This is the code:


    Code:
    package com.Database2;
    
    import java.util.Locale;
    
    import android.app.Activity;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.os.Bundle;
    import android.widget.AutoCompleteTextView;
    import android.widget.CursorAdapter;
    import android.widget.SimpleCursorAdapter;
    import android.widget.TextView;
    
    public class Database2 extends Activity {
        AutoCompleteTextView textView;
        SimpleCursorAdapter adapter;
        CursorAdapter adapter2;
        //private static final String TAG = "test2";
        
        
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            TextView view = (TextView) findViewById(R.id.hello);
    
            
            SQLiteDatabase db;
            db = openOrCreateDatabase("TestingData.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
            
            db.setVersion(1);
            db.setLocale(Locale.getDefault());
            db.setLockingEnabled(true);
            
            final String CREATE_TABLE_USERS = "CREATE TABLE IF NOT EXISTS tblUsers (" + "id INTEGER PRIMARY KEY AUTOINCREMENT," + "name TEXT, lastName TEXT);";
            
            db.execSQL(CREATE_TABLE_USERS);
            
            
           
            Cursor cur = db.query("tblUsers", null, null, null, null, null, null);
            
            String[] from = new String[] { "name", "lastName" };
            int[] to = new int[] { R.id.txtName, R.id.txtLastName};
            
            
            
                textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_users);
                
                SimpleCursorAdapter sac = new SimpleCursorAdapter (this, R.layout.list_item, cur, from, to);
                textView.setAdapter(sac);
            
        }
    
    }
    
    list_item.xml

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:stretchColumns="0" 
        android:padding="5dp"> 
        <TableRow android:padding="5dp">
            <LinearLayout android:orientation="horizontal">
                <ImageView android:id="@+id/imgFotka"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
                <TextView android:id="@+id/txtIme"
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    android:textColor="#000000"   
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="18px"/> 
                <TextView android:id="@+id/txtPrezime"
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    android:textColor="#000000"   
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingLeft="5px"
                    android:textSize="18px"/> 
            </LinearLayout>
        </TableRow>
    </TableLayout>
    
    main.xml

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/hello"
        />
    <TextView  
        android:id="@+id/hello"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        
        />
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Nastavnik:" />
    <AutoCompleteTextView android:id="@+id/autocomplete_users"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:completionThreshold="1"/>
    
    </LinearLayout>
    
    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

    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

    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

    Scrapperstoo,

    Thank you for your reply.

Share This Page