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

  • Home
  • SEARCH
  • 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 8181877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:40:04+00:00 2026-06-07T00:40:04+00:00

In this app I want that as I click on button the data from

  • 0

In this app I want that as I click on button the data from my database display on List View and by using OnItemClick() it should show another activity But Unfortunately my application is is being stopped as I click on Button Plzz tell me where m I getting wrong Here is my activity class `

public class DictionaryActivity extends Activity {
protected EditText searchText;
protected DatabaseHelper d;
protected Cursor cursor;
protected ListAdapter adapter;
   protected ListView wordList;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    d = new DatabaseHelper(this);

    d.addWord(new Contact("Apple", "Fruit"));
    d.addWord(new Contact("Ape", "Animal"));
    d.addWord(new Contact("Boy", "Male"));
    d.addWord(new Contact("Bat", "Playing Object"));

    searchText = (EditText) findViewById(R.id.word);
    wordList = (ListView) findViewById(R.id.list);

    final Button button = (Button) findViewById(R.id.search);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            searchword(v);
        }
    });

}

public void searchword(View view) {

    // || is the concatenation operation in SQLite
    cursor = d.getData(searchText);
    adapter = new SimpleCursorAdapter(this, R.layout.word_list, cursor,
            new String[] { "word" }, new int[] { R.id.word });
    wordList.setAdapter(adapter);

    wordList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(getApplicationContext(),
                    WordDetails.class);
            Cursor cursor = (Cursor) adapter.getItem(position);
            intent.putExtra("Word_ID",
                    cursor.getInt(cursor.getColumnIndex("id")));
            startActivity(intent);
        }

    });
}}`

Here is DataBaseHelper Class

public class DatabaseHelper extends SQLiteOpenHelper {
protected SQLiteDatabase db;
private static final int DATABASE_VERSION = 1;

// Database Name
private static final String DATABASE_NAME = "Word_Meanings";

// Contacts table name
private static final String TABLE_NAME = "Meanings";

// Contacts Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_WORD = "word";
private static final String KEY_MEAN = "mean";

private Contact contact;

public DatabaseHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
    String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_NAME + "("
            + KEY_ID + " INTEGER PRIMARY KEY," + KEY_WORD + " TEXT,"
            + KEY_MEAN + " TEXT" + ")";
    db.execSQL(CREATE_CONTACTS_TABLE);
}

// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // Drop older table if existed
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);

    // Create tables again
    onCreate(db);
}

// Adding new contact
void addWord(Contact contact) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_WORD, contact.getword()); // Contact Name
    values.put(KEY_MEAN, contact.getmean()); // Contact Phone

    // Inserting Row
    db.insert(TABLE_NAME, null, values);
    db.close(); // Closing database connection
}

// Updating single contact
public int updateWord(Contact contact) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_WORD, contact.getword());
    values.put(KEY_MEAN, contact.getmean());

    // updating row
    return db.update(TABLE_NAME, values, KEY_ID + " = ?",
            new String[] { String.valueOf(contact.getID()) });
}

// Deleting single contact
public void deleteWord(Contact contact) {
    this.contact = contact;
    SQLiteDatabase db = this.getWritableDatabase();
    db.delete(TABLE_NAME, KEY_ID + " = ?",
            new String[] { String.valueOf(contact.getID()) });
    db.close();
}

// Getting contacts Count
public int getCount() {
    String countQuery = "SELECT  * FROM " + TABLE_NAME;
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(countQuery, null);
    cursor.close();

    // return count
    return cursor.getCount();
}

public Cursor getData(EditText s) {
    // TODO Auto-generated method stub


    String sql = "SELECT id, word FROM Meanings WHERE word LIKE ?";


    String sqlArgs[] = new String[] { s.getText().toString() + "%" };


    Cursor c = db.rawQuery(sql, sqlArgs);


    return c;

}}

here is logcat:

E/AndroidRuntime(543): FATAL EXCEPTION: main E/AndroidRuntime(543): java.lang.NullPointerException 
E/AndroidRuntime(543): at com.Dictionary.DatabaseHelper.getData(DatabaseHelper.java:107) 
E/AndroidRuntime(543): at com.Dictionary.DictionaryActivity.searchword(DictionaryActivity.java:56) 
E/AndroidRuntime(543): at com.Dictionary.DictionaryActivity$1.onClick(DictionaryActivity.java:47) 
E/AndroidRuntime(543): at android.view.View.performClick(View.java:3511) 
E/AndroidRuntime(543): at android.view.View$PerformClick.run(View.java:14105) 
E/AndroidRuntime(543): at android.os.Handler.handleCallback(Handler.java:605) 
E/AndroidRuntime(543): at android.os.Handler.dispatchMessage(Handler.java:92) 
E/AndroidRuntime(543): at android.os.Looper.loop(Looper.java:137) 
E/AndroidRuntime(543): at android.app.ActivityThread.main(ActivityThread.java:4424) 
E/AndroidRuntime(543): at java.lang.reflect.Method.invokeNative(Native Method) 
E/AndroidRuntime(543): at java.lang.reflect.Method.invoke(Method.java:511) 
E/AndroidRuntime(543): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
E/AndroidRuntime(543): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) E/AndroidRuntime(543): at dalvik.system.NativeStart.main(Native Method)
  • 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-07T00:40:06+00:00Added an answer on June 7, 2026 at 12:40 am

    When using a Cursor to populate an Adapter, the Cursor must contain a column called _id (note the preceding _ character).

    Either change your database CREATE to use _id instead of id or change the SELECT to alias id to _id. For example…

    String sql = "SELECT id as _id, word FROM Meanings WHERE word LIKE ?";
    

    NOTE: if you need to do things like SELECT * ... you won’t be able to alias the id column obviously. In that case it is usually better to create the database table with an _id column.

    EDIT: By the way, your getCount() method will fail as you are calling cursor.close() before attempting to use return cursor.getCount(). When you close a Cursor, its resources are released and the Cursor is invalidated meaning cursor.getCount() won’t work.

    EDIT: Also, as mentioned, use SQLiteDatabase db = getReadableDatabase() before calling db.rawQuery(...) in your getData(...) method.

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

Sidebar

Related Questions

in my app when i click a button i am getting some data from
I want to port a python app that uses mechanize for the iPhone. This
I have a JavaScript app that produces a string. I want to transfer this
I want build a sketch pad app on iPhone, I assume that this type
I want to know if this web app are using long polling or anything
Actually i want to know how to store data from my app in the
im making an app that interacs with a webservie which then gets data from
I don't want to submit this app to AppStore. I've tried for many times
I want to implement tomb-stoning in my WP7 app and this app is not
In my app I want to call to selected number. For this I have

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.