Note that there are some explanatory texts on larger screens.

plurals
  1. POsqlIte exception:table not found Exception in android
    primarykey
    data
    text
    <p>I am new to android.I am trying to read the database and put result into the List activity.following is entry activity.</p> <pre><code> package com.sanjay.listdemo; import android.app.ListActivity; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.ListAdapter; import android.widget.SimpleCursorAdapter; import android.widget.ListView; import android.widget.Toast; public class MainActivity extends ListActivity { protected EditText searchText; protected SQLiteDatabase db; protected Cursor cursor; protected ListAdapter adapter; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); searchText = (EditText) findViewById(R.id.searchText); db = (new DatabaseHelper(this)).getWritableDatabase(); } // public void onListItemClick(ListView parent, View view, int position, long id) { // Intent intent = new Intent(this, ); // Cursor cursor = (Cursor) adapter.getItem(position); // intent.putExtra("EMPLOYEE_ID", cursor.getInt(cursor.getColumnIndex("_id"))); // startActivity(intent); // } public void search(View view) { // || is the concatenation operation in SQLite cursor = db.rawQuery("SELECT _id, firstName, lastName, title FROM employees WHERE firstName || ' ' || lastName LIKE ?", new String[]{"%" + searchText.getText().toString() + "%"}); adapter = new SimpleCursorAdapter( this, R.layout.simple_list_item, cursor, new String[] {"firstName", "lastName", "title"}, new int[] {R.id.firstname, R.id.lastname, R.id.title}); setListAdapter(adapter); } } </code></pre> <p><strong>DatabaseHelper.java</strong></p> <pre><code>package samples.employeedirectory; import java.io.InputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.widget.Toast; public class DatabaseHelper extends SQLiteOpenHelper { public static final String DATABASE_NAME = "employee_directory2"; protected Context context; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, 1); this.context = context; } @Override public void onCreate(SQLiteDatabase db) { String s; try { Toast.makeText(context, "1", 2000).show(); InputStream in = context.getResources().openRawResource(R.raw.sql); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.parse(in, null); NodeList statements = doc.getElementsByTagName("statement"); for (int i=0; i&lt;statements.getLength(); i++) { s = statements.item(i).getChildNodes().item(0).getNodeValue(); db.execSQL(s); db.close(); } } catch (Throwable t) { Toast.makeText(context, t.toString(), 50000).show(); } } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS employees"); onCreate(db); } } </code></pre> <p><strong>sql.xml</strong></p> <pre><code>&lt;sql&gt; &lt;statement&gt; CREATE TABLE IF NOT EXISTS employees ( _id INTEGER PRIMARY KEY AUTOINCREMENT, firstName VARCHAR(50), lastName VARCHAR(50), title VARCHAR(50), department VARCHAR(50), managerId INTEGER, city VARCHAR(50), officePhone VARCHAR(30), cellPhone VARCHAR(30), email VARCHAR(30), picture VARCHAR(200)) &lt;/statement&gt; &lt;statement&gt;INSERT INTO employees VALUES(1,'Ryan','Howard','Vice President, North East', 'Management', NULL, 'Scranton','570-999-8888','570-999-8887','ryan@dundermifflin.com','howard.jpg')&lt;/statement&gt; &lt;statement&gt;INSERT INTO employees VALUES(2,'Michael','Scott','Regional Manager','Management',1,'Scranton','570-888-9999','570-222-3333','michael@dundermifflin.com','scott.jpg')&lt;/statement&gt; &lt;statement&gt;INSERT INTO employees VALUES(3,'Dwight','Schrute','Assistant Regional Manager','Management',2,'Scranton','570-444-4444','570-333-3333','dwight@dundermifflin.com','schrute.jpg')&lt;/statement&gt; &lt;statement&gt;INSERT INTO employees VALUES(4,'Jim','Halpert','Assistant Regional Manager','Manage',2,'Scranton','570-222-2121','570-999-1212','jim@dundermifflin.com','halpert.jpg')&lt;/statement&gt; &lt;statement&gt;INSERT INTO employees VALUES(5,'Pamela','Beesly','Receptionist','',2,'Scranton','570-999-5555','570-999-7474','pam@dundermifflin.com','beesly.jpg')&lt;/statement&gt; &lt;statement&gt;INSERT INTO employees VALUES(6,'Angela','Martin','Senior Accountant','Accounting',2,'Scranton','570-555-9696','570-999-3232','angela@dundermifflin.com','martin.jpg')&lt;/statement&gt; &lt;statement&gt;INSERT INTO employees VALUES(7,'Kevin','Malone','Accountant','Accounting',6,'Scranton','570-777-9696','570-111-2525','kmalone@dundermifflin.com','malone.jpg')&lt;/statement&gt; &lt;statement&gt;INSERT INTO employees VALUES(8,'Oscar','Martinez','Accountant','Accounting',6,'Scranton','570-321-9999','570-585-3333','oscar@dundermifflin.com','martinez.jpg')&lt;/statement&gt; &lt;statement&gt;INSERT INTO employees VALUES(9,'Creed','Bratton','Quality Assurance','Customer Services',2,'Scranton','570-222-6666','333-8585','creed@dundermifflin.com','bratton.jpg')&lt;/statement&gt; &lt;statement&gt;INSERT INTO employees VALUES(10,'Andy','Bernard','Sales Director','Sales',2,'Scranton','570-555-0000','570-546-9999','andy@dundermifflin.com','bernard.jpg')&lt;/statement&gt; &lt;statement&gt;INSERT INTO employees VALUES(11,'Phyllis','Lapin','Sales Representative','Sales',10,'Scranton','570-141-3333','570-888-6666','phyllis@dundermifflin.com','lapin.jpg')&lt;/statement&gt; &lt;statement&gt;INSERT INTO employees VALUES(12,'Stanley','Hudson','Sales Representative','Sales',10,'Scranton','570-700-6666','570-777-6666','shudson@dundermifflin.com','hudson.jpg')&lt;/statement&gt; &lt;statement&gt;INSERT INTO employees VALUES(13,'Meredith','Palmer','Supplier Relations','Customer Services',2,'Scranton','570-555-8888','570-777-2222','meredith@dundermifflin.com','palmer.jpg')&lt;/statement&gt; &lt;statement&gt;INSERT INTO employees VALUES(14,'Kelly','Kapoor','Customer Service Rep.','Customer Services',2,'Scranton','570-123-9654','570-125-3666','kelly@dundermifflin.com','kapoor.jpg')&lt;/statement&gt; &lt;/sql&gt; </code></pre> <p>I am getting "No such table found:emplyees".please can anyone suggest me where I am wrong.since 48 hours I am trying to solve this.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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