Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7941019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:32:19+00:00 2026-06-03T23:32:19+00:00

I’ve created a SQLite db and I want to insert a column data in

  • 0

I’ve created a SQLite db and I want to insert a column data in a Spinner. I wrote this code below but it doesn’t work.. What is the problem?

Here is the code:

public class RemoveWorkflow2 extends Activity {

private EditText nameEditText;
private EditText classEditText;
//private EditText idEditText;
//private int mSpinnerWF;
Spinner spin;
WorkflowChoice wf = new WorkflowChoice();

MyDatabase mDB;

//MyDatabase mDB = wf.getDb();


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.remove_wf2);

    mDB = new MyDatabase(getApplicationContext()); 
    spin = (Spinner)findViewById(R.id.wf_spinner);

    fillSpinner(spin);

    Button btn = (Button)findViewById(R.id.button11);
    btn.setText("Rimuovi");
    btn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {


        }
    });
    /*
    Spinner spin = (Spinner)findViewById(R.id.wf_spinner);
    Cursor cur = mDB.fetchWfs();
    startManagingCursor(cur);

    String[] from = new String[] { WfMetaData.WF_NAME_KEY };
    int[] to = new int[] { android.R.id.text1 };
    SimpleCursorAdapter spinAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cur, from, to);
    spinAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spin.setAdapter(spinAdapter);

    spin.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            Cursor c = (Cursor)parent.getItemAtPosition(pos);
            mSpinnerWF = c.getInt(c.getColumnIndexOrThrow(WfMetaData.WF_NAME_KEY));
        }
        @Override
            public void onNothingSelected(AdapterView<?> parent) {
        }
    });*/

}

private void fillSpinner(Spinner s){

    Cursor c = mDB.fetchWfs();
    startManagingCursor(c);

    // create an array to specify which fields we want to display
    String[] from = new String[]{WfMetaData.WF_NAME_KEY};
    // create an array of the display item we want to bind our data to
    int[] to = new int[]{android.R.id.text1};
    // create simple cursor adapter
    SimpleCursorAdapter adapter =
      new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, from, to );
    adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
    // get reference to our spinner
    s.setAdapter(adapter);
    }

and here is the other MyDatabase:

    public class MyDatabase {  

    SQLiteDatabase mDb;
    DbHelper mDbHelper;
    Context mContext;
    private static final String DEBUG_TAG = "WFListDatabase";
    private static final String DB_NAME="WFListdb";//nome del db
    private static final int DB_VERSION=1; //numero di versione del nostro db

    public MyDatabase(Context ctx){
        mContext = ctx;
        mDbHelper = new DbHelper(ctx, DB_NAME, null, DB_VERSION);   //quando istanziamo questa classe, istanziamo anche l'helper (vedi sotto)     
    }

   public void open(){  //il database su cui agiamo è leggibile/scrivibile
            mDb=mDbHelper.getWritableDatabase();

    }

    public void close(){ //chiudiamo il database su cui agiamo
            mDb.close();
    }


    public void insertWf(String name,String cls){ //metodo per inserire i dati
            ContentValues cv=new ContentValues();
            cv.put(WfMetaData.WF_NAME_KEY, name);
            cv.put(WfMetaData.WF_CLASS_KEY, cls);
            mDb.insert(WfMetaData.WF_TABLE, null, cv);
    }



    public Cursor fetchAllWfs(){ //metodo per fare la query di tutti i dati
        return mDb.query(WfMetaData.WF_TABLE, new String[]{WfMetaData.WF_NAME_KEY, WfMetaData.WF_CLASS_KEY},null,null,null,null,null);               
    }

    static class WfMetaData {  // i metadati della tabella, accessibili ovunque
    static final String WF_TABLE = "wfs";
    static final String ID = "_id";
    static final String WF_NAME_KEY = "name";
    static final String WF_CLASS_KEY = "class";
    }


    private static final String WF_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS "  //codice sql di creazione della tabella
                    + WfMetaData.WF_TABLE + " (" 
                    + WfMetaData.ID+ " integer primary key autoincrement, "
                    + WfMetaData.WF_NAME_KEY + " text not null, "
                    + WfMetaData.WF_CLASS_KEY + " text not null);";

    public Cursor fetchWfs(){ //metodo per fare la query di tutti i dati
        return mDb.query(WfMetaData.WF_TABLE, null,null,null,null,null,null);               
}

    public void delete_byName(String n){
     mDb.delete(WfMetaData.WF_TABLE, WfMetaData.WF_NAME_KEY + "='" +n + "'", null);
     //mDb.delete(WfMetaData.WF_TABLE, WfMetaData.WF_NAME_KEY + "=?", new String[] { n });

    CharSequence text = "Il Workflow "+ n +" è stato rimosso con successo!";
    int duration = Toast.LENGTH_SHORT;

    Toast toast = Toast.makeText(mContext, text, duration);
    toast.show();
    }

    private class DbHelper extends SQLiteOpenHelper { //classe che ci aiuta nella creazione del db

        public DbHelper(Context context, String name, CursorFactory factory,int version) {
            super(context, name, factory, version);
        }

        @Override
        public void onCreate(SQLiteDatabase _db) { //solo quando il db viene creato, creiamo la tabella
            _db.execSQL(WF_TABLE_CREATE);
        }

        @Override
        public void onUpgrade(SQLiteDatabase _db, int oldVersion, int newVersion) {
            Log.w(DEBUG_TAG, "Upgrading database. Existing contents will be lost. ["
                    + oldVersion + "]->[" + newVersion + "]");
            _db.execSQL("DROP TABLE IF EXISTS " + WF_TABLE_CREATE);
            onCreate(_db);
        }       

    }


    public boolean isEmpty(){
        boolean isEmpty = true;
        Cursor cursor = mDb.query(WfMetaData.WF_TABLE, new String[] { WfMetaData.WF_NAME_KEY }, null, null, null, null, null);
        if (cursor != null && cursor.getCount() > 0)
        {
           isEmpty = false;
        }
        return isEmpty;
    }
}

and here is xml file:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Scegli il workflow da eliminare: "
        android:gravity="center" />


    <Spinner
        android:id="@+id/wf_spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/button11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Button" />

</LinearLayout>

And the LoGcat with the NullPointerException..

05-10 11:48:04.475: E/AndroidRuntime(24650):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1696)
05-10 11:48:04.475: E/AndroidRuntime(24650):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1721)
05-10 11:48:04.475: E/AndroidRuntime(24650):    at android.app.ActivityThread.access$1500(ActivityThread.java:124)
05-10 11:48:04.475: E/AndroidRuntime(24650):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)
05-10 11:48:04.475: E/AndroidRuntime(24650):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-10 11:48:04.475: E/AndroidRuntime(24650):    at android.os.Looper.loop(Looper.java:130)
05-10 11:48:04.475: E/AndroidRuntime(24650):    at android.app.ActivityThread.main(ActivityThread.java:3844)
05-10 11:48:04.475: E/AndroidRuntime(24650):    at java.lang.reflect.Method.invokeNative(Native Method)
05-10 11:48:04.475: E/AndroidRuntime(24650):    at java.lang.reflect.Method.invoke(Method.java:507)
05-10 11:48:04.475: E/AndroidRuntime(24650):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-10 11:48:04.475: E/AndroidRuntime(24650):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-10 11:48:04.475: E/AndroidRuntime(24650):    at dalvik.system.NativeStart.main(Native Method)
05-10 11:48:04.475: E/AndroidRuntime(24650): Caused by: java.lang.NullPointerException
05-10 11:48:04.475: E/AndroidRuntime(24650):    at com.tilab.wade.interactivity.android.client.RemoveWorkflow2.fillSpinner(RemoveWorkflow2.java:82)
05-10 11:48:04.475: E/AndroidRuntime(24650):    at com.tilab.wade.interactivity.android.client.RemoveWorkflow2.onCreate(RemoveWorkflow2.java:44)
05-10 11:48:04.475: E/AndroidRuntime(24650):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-10 11:48:04.475: E/AndroidRuntime(24650):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660)
05-10 11:48:04.475: E/AndroidRuntime(24650):    ... 11 more
05-10 11:48:04.485: W/ActivityManager(1610):   Force finishing activity com.tilab.wade.interactivity.android.client/.RemoveWorkflow2
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:32:20+00:00Added an answer on June 3, 2026 at 11:32 pm
    MyDatabase mDB = new MyDatabase(getApplicationContext());
    

    you instantiate a local variable who hides the global var, so global mDB is null.

    mDB = new MyDatabase(getApplicationContext());

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to construct a data frame in an Rcpp function, but when I
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.