Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

test: Reply
 
LinkBack Thread Tools
Old February 28th, 2011, 04:51 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Feb 2011
Posts: 9
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default Why this app stops unexpectedly???

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!

Advertisements
assistant is offline  
Reply With Quote
sponsored links
Old March 1st, 2011, 03:15 AM   #2 (permalink)
New Member
Thread Author (OP)
 
Join Date: Feb 2011
Posts: 9
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?
assistant is offline  
Reply With Quote
Old March 2nd, 2011, 11:09 AM   #3 (permalink)
New Member
 
Join Date: Dec 2010
Posts: 9
 
Device(s):
Carrier: Not Provided

Thanks: 3
Thanked 0 Times in 0 Posts
Default

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.
scrapperstoo is offline  
Reply With Quote
Old March 2nd, 2011, 04:07 PM   #4 (permalink)
New Member
Thread Author (OP)
 
Join Date: Feb 2011
Posts: 9
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Scrapperstoo,

Thank you for your reply.
assistant is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 04:08 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.