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 7434747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:56:39+00:00 2026-05-29T09:56:39+00:00

Now I find ploblem again. I want get data in db to listview. but

  • 0

Now I find ploblem again.

I want get data in db to listview.

but it have error I cannot correct this problem.

Please help me

Thank!!

this my database

package com.BITS.DB;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class Database {

    public String Serach = null;
    public static final String KEY_ROWID = "_id";
    public static final String KEY_WORD = "word";
    public static final String KEY_TYPE = "type";
    public static final String KEY_EXPLANTION = "Explanation";
    public static final String TAG = "DatabasePray";
    public static final String DATABASE_NAME = "BITSonMobiles";
    public static final String DATABASE_TABLE = "pray";
    public static final int DATABASE_VERSION = 1;

    private static final String DATABASE_CREATE = "create table pray"
            + "(_id integer primary key autoincrement," + "word char(40)NOT NULL,"
            + "Explanation text NOT NULL,"+"type text NOT NULL);";

    private Context context = null;
    private DatabaseHelper DBHelper;
    private SQLiteDatabase db;



    public Database(Context ctx) {
        this.context = ctx;
        DBHelper = new DatabaseHelper(context);
    }

    public Database open() throws SQLException {
        db = DBHelper.getWritableDatabase();
        return this;
    }

    public void close() {
        DBHelper.close();
    }

    public long insertWord(String word, String type, String Explanation) {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_WORD, word);
        initialValues.put(KEY_TYPE, type);
        initialValues.put(KEY_EXPLANTION, Explanation);
        return db.replace(DATABASE_TABLE, null, initialValues);
    }

    public boolean deleteWord(long rowId) {
        return db.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;

    }

    public boolean updateWord(long rowId, String type, String word, String Explanation) {
        ContentValues args = new ContentValues();
        args.put(KEY_WORD, word);
        args.put(KEY_TYPE, type);
        args.put(KEY_EXPLANTION, Explanation);
        return db.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
    }

    public Cursor getAllWord(String type) {
        return db.query(DATABASE_TABLE, new String[] {
                KEY_ROWID,
                KEY_WORD,
                KEY_TYPE,
                KEY_EXPLANTION }, 
                KEY_TYPE + "=" + type , 
                null, 
                null, 
                null, 
                KEY_WORD);
    }

    public Cursor searchWord(String Wordcom) throws SQLException {

        Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] {
                KEY_ROWID,
                KEY_WORD,
                KEY_TYPE,
                KEY_EXPLANTION },
                KEY_WORD + "=" + Wordcom,
                null, 
                null, 
                null, 
                KEY_WORD, 
                null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;
    }


    public Cursor getWord(long rowId) throws SQLException {

        Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] {
                KEY_ROWID,
                KEY_WORD,
                KEY_TYPE,
                KEY_EXPLANTION },
                KEY_ROWID + "=" + rowId,
                null, 
                null, 
                null, 
                null, 
                null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;
    }

    private static class DatabaseHelper extends SQLiteOpenHelper {
        DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            db.execSQL(DATABASE_CREATE);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            Log.w(TAG, "Upgrading database from version" + oldVersion + " to "
                    + newVersion + ", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS titles");
            onCreate(db);
        }
    }

}

and tihs main

package com.BITS.DB;

import java.util.ArrayList;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;


public class ChoicePray extends ListActivity {

    AlertDialog dialog;
    EditText wordNameSearch;
    TextView typeShow;
    ImageView imageSearch;
    static Database db;
    static String database;
    String wordSearch = null;
    private int idWord;
    public String type="Pray";

    public static Context context;
    private static final ArrayList<String> ListviewContent = new ArrayList<String>();
    private static final ArrayList<Integer> ListID = new ArrayList<Integer>();
    ListViewAdapter listAdap;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.choicepray);
        typeShow = (TextView) findViewById(R.id.groupshow);
        wordNameSearch = (EditText) findViewById(R.id.namePraySearch);
        imageSearch = (ImageView) findViewById(R.id.imageSearch);
        context = getBaseContext();
        db = new Database(this);
        showAllword();
        typeShow.setText("Pray");
        listAdap = new ListViewAdapter(this);
        listAdap.notifyDataSetChanged();
        setListAdapter(listAdap);
        SearchOnButton();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
        }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) { 
    case R.id.add:{  
            Intent a = new Intent(getBaseContext(),Insert_Form.class);
            startActivity(a);
            break;
            }
    case R.id.pray:{
            type="A";
            typeShow.setText("A");
            showAllword();
            break;
            }
    case R.id.pray1:{
            type="B";
            typeShow.setText("B");
            showAllword();
            break;
            }
    case R.id.pray2:{
            type="C";
            typeShow.setText("C");
            showAllword();
            break;
            }
        } 
    return true; 
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
             AlertDialog dialog = new AlertDialog.Builder(this).create();
             dialog.setMessage("ARE YOU SURE EXIT ?");
             dialog.setButton(DialogInterface.BUTTON_POSITIVE, "YES",new DialogInterface.OnClickListener() { 
                 public void onClick(DialogInterface dialog, int which) {
                     {   finish();
                         android.os.Process.killProcess(android.os.Process.myPid());
                         System.exit(0);  
                        }
                     dialog.cancel();
                 } 
            });
            dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "NO", 
                     new DialogInterface.OnClickListener() {
                     public void onClick(DialogInterface dialog, int which) {
                         dialog.cancel();
                     } 
           });
            dialog.show();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    public void SearchOnButton(){
        imageSearch.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                wordSearch = wordNameSearch.getText().toString();
                ListID.clear();
                ListviewContent.clear();
                db = new Database(context);
                db.open();
                Cursor c = db.searchWord(wordSearch);
                if (c.moveToFirst()) {
                    do {
                        displayPray(c);
                    } while (c.moveToNext());
                }
                db.close();
                wordNameSearch.setText("");
                typeShow.setText("All");
                listAdap.notifyDataSetChanged();
                setListAdapter(listAdap);
            }

        });

    }

    public void ButtonAlertDialog(final int position){
         AlertDialog dialog = new AlertDialog.Builder(this).create();
         dialog.setMessage("ARE YOU SURE DELETE WORD ?");
         dialog.setButton(DialogInterface.BUTTON_POSITIVE, "YES",
                 new DialogInterface.OnClickListener() { 
                 public void onClick(DialogInterface dialog, int which) {
                     {
                            Log.v("Delete", "delete id" + ListID.get(position));
                            db.open();
                            boolean flag = db.deleteWord(ListID.get(position));
                            if (flag) {
                                Toast.makeText(context, "Delete Succeed.",
                                        Toast.LENGTH_SHORT).show();
                            } else {
                                Toast.makeText(context, "Delete Failed",
                                        Toast.LENGTH_SHORT).show();
                            }
                            db.close();
                            showAllword(); 
                        }
                     dialog.cancel();
                 } 
       });
         dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "NO", 
                 new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int which) {
                     dialog.cancel();
                 } 
       });
         dialog.show();
    }

    public  void showAllword() {
        ListID.clear();
        ListviewContent.clear();
        db = new Database(context);
        db.open();
        Cursor c = db.getAllWord(type);
        if (c.moveToFirst()) {
            do {
                displayPray(c);
            } while (c.moveToNext());
        }
        db.close();
        listAdap = new ListViewAdapter(this);
        listAdap.notifyDataSetChanged();
        setListAdapter(listAdap);
    }

    public static void displayPray(Cursor c) {
        ListviewContent.add(c.getString(1));
        ListID.add(Integer.parseInt(c.getString(0)));
    }


    private class ListViewAdapter extends BaseAdapter {
        public LayoutInflater mInflater;

        public ListViewAdapter(Context context) {
            mInflater = LayoutInflater.from(context);
        }
        @Override
        public int getCount() {
            return ListviewContent.size();
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(final int position, View convertView, ViewGroup parent) {

            ListContent holder;
            View v = convertView;
            if (v == null || (v.getTag()==null)) {
                    v = mInflater.inflate(R.layout.list_item, null);
                    holder = new ListContent();
                    holder.text = (TextView) v.findViewById(R.id.TextView01);
                    v.setTag(holder);
            }
                    else {
                holder = (ListContent) v.getTag();
            }


            v.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    Intent ex = new Intent(getBaseContext(), Explan.class);
                    idWord = ListID.get(position);
                    ex.putExtra("idWord", idWord);
                    ex.putExtra("type", type);
                    startActivity(ex);
                }
            });

            holder.text.setText(ListviewContent.get(position)); 
            v.setOnLongClickListener(new OnLongClickListener(){
                 @Override
                 public boolean onLongClick(View v) {
                     ButtonAlertDialog(position);
                        return true;
                    }
                });
                return v;
        }

        private class ListContent {
            TextView text;  
        }
    }


}

And here is the error messages from the LogCat:

02-06 01:00:01.832: ERROR/AndroidRuntime(13689): FATAL EXCEPTION: main
02-06 01:00:01.832: ERROR/AndroidRuntime(13689): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.BITS.DB/com.BITS.DB.ChoicePray}: android.database.sqlite.SQLiteException: no such column: type: , while compiling: SELECT _id, word, type, Explanation FROM pray WHERE type=Pray ORDER BY word
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.os.Looper.loop(Looper.java:123)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.app.ActivityThread.main(ActivityThread.java:4627)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at java.lang.reflect.Method.invokeNative(Native Method)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at java.lang.reflect.Method.invoke(Method.java:521)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at dalvik.system.NativeStart.main(Native Method)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689): Caused by: android.database.sqlite.SQLiteException: no such column: type: , while compiling: SELECT _id, word, type, Explanation FROM pray WHERE type=Pray ORDER BY word
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:46)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1229)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1184)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1264)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at com.BITS.DB.Database.getAllWord(Database.java:69)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at com.BITS.DB.ChoicePray.showAllword(ChoicePray.java:187)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at com.BITS.DB.ChoicePray.onCreate(ChoicePray.java:53)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-06 01:00:01.832: ERROR/AndroidRuntime(13689):     ... 11 more

So, can anybody help to get through this? Thank you in advance !

  • 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-05-29T09:56:40+00:00Added an answer on May 29, 2026 at 9:56 am

    It seems to me that your code is correct. But I think the problem is that before you have created database incorrectly. So I advice to do the following steps:

    Try to put spaces into your create statement:

    private static final String DATABASE_CREATE = "create table pray"
                + "(_id integer primary key autoincrement, " + "word char(40) NOT NULL, "
                + "Explanation text NOT NULL, "+"type text NOT NULL);";
    

    After that, delete your database from /data/data/yourpackage/databases folder and run your application.

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

Sidebar

Related Questions

I've got this problem for a while now and I cannot find a solution
I've already looked around but couldn't find the exact solution/problem I'm having right now.
I have implemented Facebook into my app but now I find that whenever I
I have used this forum for a while now to find answers to some
I searched a lot to get rid of this problem on the internet but
I searched for this but didn't find an solution that totally fixed my problem.
This originally was a problem I ran into at work, but is now something
Ive tried searching for hours now and cannot find out why my code (aka,
I recently posted my problem but neither did I get an answer here or
So, I'm using JQuery AjaxQueue to do stuff, but the problem I have is

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.