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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:14:05+00:00 2026-06-13T15:14:05+00:00

i wrote a program that get data from user and store it in database.this

  • 0

i wrote a program that get data from user and store it in database.this database store in asset folder and it exist
when i wrote the program and use break point before line

 private OnClickListener mAddListener = new OnClickListener() {}

it gives me this error:
source not found.
what should i do?

this is my main code:
//————-mainactivity class———————

public class MainActivity extends Activity
{
    BDAdapter db = new BDAdapter(this);
    EditText name;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        // Capture our button from layout
        Button setButton = (Button)findViewById(R.id.go);
        Button getButton = (Button)findViewById(R.id.genRan);
        // Register the onClick listener with the implementation above
        setButton.setOnClickListener(mAddListener);
        getButton.setOnClickListener(mAddListener);



    }
    // Create an anonymous implementation of OnClickListener
    private OnClickListener mAddListener = new OnClickListener() 
    {
        public void onClick(View v) 
        {
            switch(v.getId())
            {
            case R.id.go:
                db.open();
                long id = 0;
                // do something when the button is clicked
                try
                {
                    name = (EditText)findViewById(R.id.Quote);
                    db.insertQuote(name.getText().toString());


                    id = db.getAllEntries();

                    Context context = getApplicationContext();
                    CharSequence text = "The quote '" + name.getText() + "' was added successfully!\nQuotes Total = " + id;
                    int duration = Toast.LENGTH_LONG;

                    Toast toast = Toast.makeText(context, text, duration);
                    toast.show();
                    name.setText("");
                }
                catch (Exception ex)
                {
                    Context context = getApplicationContext();
                    CharSequence text = ex.toString() + "ID = " + id;
                    int duration = Toast.LENGTH_LONG;

                    Toast toast = Toast.makeText(context, text, duration);
                    toast.show();
                }

                db.close();
                break;
            case R.id.genRan:
                db.open();
                //long id1 = 0;
                // do something when the button is clicked
                try
                {
                    //String quote = "";
                    //quote = db.getRandomEntry();
                    //Context context = getApplicationContext();
                    //CharSequence text = quote;
                    //int duration = Toast.LENGTH_LONG;

                    //Toast toast = Toast.makeText(context, text, duration);
                    //toast.show();

                     db.open();
                        Cursor c = db.getAllTitles();
                       if (c.moveToFirst())
                       {
                          do {          
                                DisplayTitle(c);
                            } while (c.moveToNext());
                       }
                        db.close();


                }
                catch (Exception ex)
                {
                    Context context = getApplicationContext();
                    CharSequence text = ex.toString();
                    int duration = Toast.LENGTH_LONG;

                    Toast toast = Toast.makeText(context, text, duration);
                    toast.show();
                }
                db.close();
            }
        }

    };
    public void DisplayTitle(Cursor c)
    {
        Toast.makeText(this, 
                "NAME: " + c.getString(0) + "\n" ,


                Toast.LENGTH_LONG).show();        
    } 


}

//———————-DBAdapter class—————————-

public class BDAdapter extends SQLiteOpenHelper {
     private Context mycontext;
int id=0;
     private String DB_PATH = "data/data/com.example.dd20/databases/";

        private static String DB_NAME = "ff.sqlite";
        public static final String KEY_ROWID = "_id";
        public static final String KEY_QUOTE = "name";
        public static final String DATABASE_TABLE = "ff1";
        private static final String TAG = "BDAdapter";
        public static final String DATABASE_CREATE =
                "create table ff1 (_id integer primary key, "
                        + "name text );";

     //   private DatabaseHelper DBHelper;
        private SQLiteDatabase db;
       // private SQLiteDatabase db;
        // the extension may be .sqlite
        // or .db
      //  public SQLiteDatabase myDataBase;

        public BDAdapter(Context context) {
            super(context, DB_NAME, null, 1);

            this.mycontext = context;

        }

        public void createDataBase() throws IOException{

            boolean dbExist = checkDataBase();

            if(dbExist){
            //do nothing - database already exist
            }else{

            //By calling this method and empty database will be created into the default system path
            //of your application so we are gonna be able to overwrite that database with our database.
            this.getReadableDatabase();

        //  try {

        //  copyDataBase();

        //  } catch (IOException e) {
     //      
        throw new Error("Error copying database");

      //    }
            }

            }

        private boolean checkDataBase(){

            SQLiteDatabase checkDB = null;

            try{
            String myPath = DB_PATH + DB_NAME;
            checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);

            }catch(SQLiteException e){

            //database does't exist yet.

            }

            if(checkDB != null){

            checkDB.close();

            }

            return checkDB != null ? true : false;
            }

      // private void copyDataBase() throws IOException{

            //Open your local db as the input stream
      //    InputStream myInput = mycontext.getAssets().open(DB_NAME);

            // Path to the just created empty db
      //    String outFileName = DB_PATH + DB_NAME;

            //Open the empty db as the output stream
      //    OutputStream myOutput = new FileOutputStream(outFileName);

            //transfer bytes from the inputfile to the outputfile
      //    byte[] buffer = new byte[1024];
      //    int length;
      //    while ((length = myInput.read(buffer))>0){
      //    myOutput.write(buffer, 0, length);
      //    }

            //Close the streams
        //  myOutput.flush();
      //    myOutput.close();
       //   myInput.close();

        //  }

        public void open() {
            // Open the database
             String myPath = DB_PATH + DB_NAME;
             db = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);

        }

        public synchronized void close() {
             if(db != null)
                 db.close();

                 super.close();
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            // TODO Auto-generated method stub
            db.execSQL(DATABASE_CREATE);

        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
           //  TODO Auto-generated method stub
      //  Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
         //       + newVersion + ", which will destroy all old data");
     //   db.execSQL("DROP TABLE IF EXISTS ff1");
  //   onCreate(db);


        }

        public long insertQuote(String Quote) 
        {
            ContentValues initialValues = new ContentValues();
            initialValues.put(KEY_QUOTE, Quote);
            return db.insert(DATABASE_TABLE, null, initialValues);
        }

        public int getAllEntries() 
        {
             Cursor cursor = db.rawQuery(
                        "SELECT COUNT(name) FROM ff1 ", null);
                    if(cursor.moveToFirst()) {
                        return cursor.getInt(0);
                    }
                    return cursor.getInt(0);

        }

        public String getRandomEntry() 
        {

            id = getAllEntries();
            Random random = new Random();
            int rand = random.nextInt(getAllEntries());
            if(rand == 0)
                ++rand;
            Cursor cursor = db.rawQuery(
                      "SELECT name FROM ff1", null);
                    //"SELECT * FROM tblRandomQuotes",null);
                    if(cursor.moveToFirst()) {
                        return cursor.getString(0);

                    }
                    return cursor.getString(0);

        }

        public Cursor getAllTitles() 
        {
            return db.query(DATABASE_TABLE, new String[] {

                    KEY_QUOTE,
                    }, 
                    null, 
                    null, 
                    null, 
                    null, 
                    null);
        }


}
  • 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-13T15:14:06+00:00Added an answer on June 13, 2026 at 3:14 pm

    If you want to debug your onClickListener try setting the breakpoint at switch(v.getId()) to begin with

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

Sidebar

Related Questions

I am making a program that get's it's data from a site that needs
I wrote this program: #include <stdio.h> /*Part B Write a program that: defines an
A while ago, I wrote a program that outputs any localhost or network database
I wrote a little program that use activemq embedded broker. Program run on one
I'm dealing with a problem in a kernel module that get data from userspace
I have a program below that tries to take input from the user and
I've got 2 tables that I need to get data from...my users table looks
I wrote a program that creates a puzzle based on user's inputs. There is
I wrote a program that requires ~1GB of RAM zeroed at startup, and this
I'm working on a small server program that takes data received from the network

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.