Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Getting bundle string to create sqlite database table
    primarykey
    data
    text
    <p>Thanks for your time in reading my question. </p> <p>I plan to write an app that allow the user to select the table columns to perform a full text search. Therefore, I get the user input into bundle string and try to pass this into the SQLiteOpenHelper. However, the SQLOpenHelper is unable to get the string. My code snippet is as follows:</p> <pre><code>ActivityA.java public class ActivityA extends Activity { ... //get the selected dropdown list value public void addListenerOnButton(final Spinner sp1, final Spinner sp2, final MultiSpinner msp1, final MultiSpinner msp2) { btnSubmit = (Button) findViewById(R.id.btnSubmit); btnSubmit.setOnClickListener(new OnClickListener() { //@Override public void onClick(View v) { strpkey = String.valueOf(sp1.getSelectedItem()); strskey = String.valueOf(sp2.getSelectedItem()); stronscreen = String.valueOf(msp1.getSelectedItem()); strwhenclick = String.valueOf(msp2.getSelectedItem()); Intent intent = new Intent(); intent.setClass(ActivityA.this, ActivityB.class); Bundle bundle = new Bundle(); bundle.putString("Pkey", strpkey); bundle.putString("Skey", strskey); bundle.putString("Onscreen", stronscreen); bundle.putString("Whenclick", strwhenclick); intent.putExtras(bundle); startActivity(intent); } </code></pre> <p>Note: I am able to get the bundle string in ActivityB so I don't think the problem lies in ActivityA.</p> <pre><code>ActivityB.java public class ActivityB extends Activity { public String strpkey, strskey; public String stronscreen; private DbAdapter dbHelper; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.countsheet); strpkey = getfilepath("Pkey"); strskey = getfilepath("Skey"); stronscreen = getfilepath("Onscreen"); Toast.makeText(this, strpkey + " " + strskey + " " + stronscreen, Toast.LENGTH_LONG).show(); dbHelper = new DbAdapter(this); dbHelper.open(); public String getfilepath(String strbundletext) { Bundle bundle = this.getIntent().getExtras(); String csvpath = bundle.getString(strbundletext); return csvpath; } ... } </code></pre> <p>DBAdapter.java</p> <pre><code>import com.ksgrp.stocktake.ActivityB; public class DbAdapter { public static class DatabaseHelper extends SQLiteOpenHelper { public ListDesign csobj2 = new ListDesign(); public String pkey = csobj2.strpkey; private String skey = csobj2.strskey; public String onscreen = csobj2.stronscreen; private String getstr(String pkey, String skey) { ActivityB csobj = new ActivityB(); String pkey = csobj.strpkey; String skey = csobj.strskey; String onscreen = csobj.stronscreen; String sqlstr = "CREATE VIRTUAL TABLE " + vdb_tbl + " USING fts3(" + sqlstr + ")"; return sqlstr; } //@Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub String strsql = getstr(this.pkey, this.skey); db.execSQL("DROP TABLE IF EXISTS " + vdb_tbl); db.execSQL(strsql); Log.w("TAG", strsql); } } </code></pre> <p>I get a java null pointer exception when I click the button in ActivityA:</p> <pre><code>03-08 14:04:31.569: E/AndroidRuntime(29573): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ksgrp.stocktake/com.ksgrp.stocktake.ActivityB}: android.database.sqlite.SQLiteException: vtable constructor failed: stocklist2: CREATE VIRTUAL TABLE stocklist2 USING fts3(null, null) </code></pre> <p>I believe I am unable to get the value in the bundle string into the DBAdapter class. Can anyone give me a hand on this? I can provide the full code (but it is lengthy so I have just extracted the relevant bits above). </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload