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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:18:21+00:00 2026-06-17T15:18:21+00:00

I am totally new to database in android,and have tried to make a simple

  • 0

I am totally new to database in android,and have tried to make a simple application using sqlite in android.But i have some problem with my code or i cant find whats the problem ,that when i run my project the applicatioon stops unexpectly and also the databse is not created..Please help me..My code is as below:

MainActivity.java

package com.example.dbdemo1;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;

public class MainActivity extends Activity {
Button ins,del,upd;
ListView lv;
DbHelper dh;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ins = (Button)findViewById(R.id.button1);
        upd = (Button)findViewById(R.id.button2);
        del = (Button)findViewById(R.id.button3);

        lv = (ListView)findViewById(R.id.listView1);
        setUpList();
        dh = new DbHelper(this);
        Cursor c =getAllData();
        registerForContextMenu(lv);
       ins.setOnClickListener((OnClickListener) this);
       upd.setOnClickListener((OnClickListener) this);
       }
    public void onClick(View v) {
        // TODO Auto-generated method stub

        if(v.equals(ins))
        {
            startActivity(new Intent(MainActivity.this, insertActivity.class));
        }
        else
        {
            //startActivity(new Intent(MainActivity.this, updateActivity.class));
        }
    }
    private Cursor getAllData() {
        // TODO Auto-generated method stub
        return null;
    }

    private void setUpList() {
        // TODO Auto-generated method stub

    }

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

DBhelper.java

package com.example.dbdemo1;

import android.R.string;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DbHelper extends SQLiteOpenHelper{


    public static String db_name ="myDB.db";
    public static String fname = "first name";
    public static String lname = "last name";
    public static String contact = "contact";

    public DbHelper(Context context) {
        super(context, db_name, null, 1);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        try 

        {
            db.execSQL("CREATE TABLE register(_ID INTEGER PRIMARY KEY AUTOINCREMENT,fName TEXT,lNmae TEXT,Contact TEXT);");
        } 
        catch (Exception e) {
            // TODO: handle exception
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        android.util.Log.v("Constants", "Upgrading database which will destroy all data");
        onCreate(db);

    }

}

Logcat

01-22 07:54:40.003: W/dalvikvm(32581): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-22 07:54:40.013: E/AndroidRuntime(32581): FATAL EXCEPTION: main
01-22 07:54:40.013: E/AndroidRuntime(32581): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dbdemo1/com.example.dbdemo1.MainActivity}: java.lang.ClassCastException: com.example.dbdemo1.MainActivity
01-22 07:54:40.013: E/AndroidRuntime(32581):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-22 07:54:40.013: E/AndroidRuntime(32581):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-22 07:54:40.013: E/AndroidRuntime(32581):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-22 07:54:40.013: E/AndroidRuntime(32581):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-22 07:54:40.013: E/AndroidRuntime(32581):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-22 07:54:40.013: E/AndroidRuntime(32581):    at android.os.Looper.loop(Looper.java:123)
01-22 07:54:40.013: E/AndroidRuntime(32581):    at android.app.ActivityThread.main(ActivityThread.java:4627)
01-22 07:54:40.013: E/AndroidRuntime(32581):    at java.lang.reflect.Method.invokeNative(Native Method)
01-22 07:54:40.013: E/AndroidRuntime(32581):    at java.lang.reflect.Method.invoke(Method.java:521)
01-22 07:54:40.013: E/AndroidRuntime(32581):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-22 07:54:40.013: E/AndroidRuntime(32581):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-22 07:54:40.013: E/AndroidRuntime(32581):    at dalvik.system.NativeStart.main(Native Method)
01-22 07:54:40.013: E/AndroidRuntime(32581): Caused by: java.lang.ClassCastException: com.example.dbdemo1.MainActivity
01-22 07:54:40.013: E/AndroidRuntime(32581):    at com.example.dbdemo1.MainActivity.onCreate(MainActivity.java:33)
01-22 07:54:40.013: E/AndroidRuntime(32581):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-22 07:54:40.013: E/AndroidRuntime(32581):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-22 07:54:40.013: E/AndroidRuntime(32581):    ... 11 more

Please help me for this…thanking 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-06-17T15:18:22+00:00Added an answer on June 17, 2026 at 3:18 pm

    you need to implement OnClickListener interface to use setOnClickListener on Button.

    public class MainActivity extends Activity implements OnClickListener{
    

    or

    you can create anonymous method for particular button like

    ins.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
          }
     });
    

    without implementing OnClickListner interface.

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

Sidebar

Related Questions

im totally new when it comes to trying to make HTML code. I was
I'm using Delphi 7, totally new to database programming, and need ODBC. I am
I'm totally new to android programming. I can see that this problem has been
I'm totally new to ajax, but pretty good with PHP. I have a PHP
Probably a dead simple and idiotic question (I'm totally new to javascript): I have
I am totally new to Netty and Java, but this afternoon I have managed
I'm totally new with SQLite. I have a UITableview with contains different days in
Totally new to programming so kindly excuse the silly question. I have this URL
Totally new to Capistrano. I have a local git repository that I want to
I am totally new in appbiling service in android, and it seems to be

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.