Hello Every body,
I am new in this group. I am in a problem from many days and try to
resolve it. But unfortunately its difficult for me.
I am fetching data from data base and dsiplaying in the spiner.
Database created and working well but when I bind it with spiner then
it show error and force to shutdown the application.

This is the almost complete code.

import android.os.Bundle;
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.widget.TextView;
import android.widget.Spinner;
import android.widget.SimpleCursorAdapter;
import android.app.ListActivity;
import static com.servanetdatabase.Constants.Table_Name;
import static com.servanetdatabase.Constants.KEY_SensorID;
import static com.servanetdatabase.Constants.KEY_type;
import static com.servanetdatabase.Constants.KEY_ThresouldValue;
import static com.servanetdatabase.Constants.KEY_Address;
import static com.servanetdatabase.Constants.KEY_City;
import static com.servanetdatabase.Constants.KEY_State;
import static com.servanetdatabase.Constants.KEY_Latitude;
import static com.servanetdatabase.Constants.KEY_GPSNo;
import static com.servanetdatabase.Constants.KEY_SensorID;
import android.widget.SimpleCursorAdapter;
import android.widget.Spinner;
import android.widget.ArrayAdapter;




public class ServaNetDatabase extends Activity {

        private static String[] FROM = { KEY_SensorID, KEY_type,
KEY_ThresouldValue, };
        private static String ORDER_BY = KEY_SensorID + " DESC";
        public static String[] PROJECTION;
//      int[] to = new int[]{android.R.id.text1};


           private DBAdapter events;

           @Override
           public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.main);
              events = new DBAdapter(this);
              try {
                 addEvent("This is an event");
                 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(KEY_SensorID, 1);
                      values.put(KEY_type, 500);
                      values.put(KEY_ThresouldValue, 500);
                      db.insertOrThrow(Table_Name, null, values);
                   }
           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) {

                      SimpleCursorAdapter adapter =
                        new SimpleCursorAdapter(this,
android.R.layout.simple_spinner_item, cursor, FROM, null );
        
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item 
);
                      // get reference to our spinner
                      Spinner s = (Spinner) findViewById( R.id.dspiner );
                      s.setAdapter(adapter);



                   }



                }

Any body can help me to resolve this issue?

Regards,

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to