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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:48:20+00:00 2026-06-08T08:48:20+00:00

im a new in android,I want get data in db to textview. but it

  • 0

im a new in android,I want get data in db to textview.

but it has error I cannot correct this problem.

Please help me.

This is DB class

    public class blockornot1 {
     String TAG;
 private dbHelper1 ourHelper;
 private final Context ourContext;
 private SQLiteDatabase ourDatabese;

  public final static  String DATABASE_NAME1="databasename.db";
  public final String DATABASE_TABLE="numbersTable";
  public final String KEY_NAME="personname";
  public final String KEY_ID="id";
  public final int DATABASE_VERSION =2;


  public  class dbHelper1 extends SQLiteOpenHelper{

    public dbHelper1 (Context context) {
          super (context,DATABASE_NAME1,null,DATABASE_VERSION);
          }

    @Override
    public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE "+ DATABASE_TABLE+ "("+KEY_ID+ " INTEGER PRIMARY KEY AUTOINCREMENT, "               
      + KEY_NAME + "TEXT NOT NULL);");
        Log.v(TAG, "creat");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
        onCreate(db);

    }

  }``

  public blockornot1(Context c){

      ourContext = c;
  }

  public blockornot1 open() throws SQLException{
      ourHelper= new dbHelper1(ourContext);
      ourDatabese= ourHelper.getWritableDatabase();
      return this;
  }

  public void close(){
      ourHelper.close();

  }

public long creatEntry(String inputtext) {
    // TODO Auto-generated method stub
    ContentValues cv= new ContentValues();
    cv.put(KEY_NAME, inputtext);
    Log.v(inputtext, "add to database");
    return ourDatabese.insert(DATABASE_TABLE, null, cv);

}

public String getData() {
    // TODO Auto-generated method stub
    String[] columns = new String[]{ KEY_ID, KEY_NAME };
    Cursor c=ourDatabese.query(DATABASE_TABLE, columns, null, null, null, null,   null);
    String result = "";
    int iRow = c.getColumnIndex(KEY_ID);
    int iName = c.getColumnIndex(KEY_NAME);
    for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){

        result= result + c.getString(iRow) + "   " + c.getString(iName) + "/n";
    }
    return result;
   }


     }

and this is my main class

      public class Mainclass extends Activity implements OnClickListener {
      EditText et;
  String TAG;
    public void onCreate(Bundle savedInstanceState) {
        Log.v(TAG,"onCreate");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

       et=(EditText)findViewById(R.id.edittext1);
       Button bt=(Button)findViewById(R.id.button1);
        Button bt1=(Button)findViewById(R.id.button2view);
        bt.setOnClickListener(this);
        bt1.setOnClickListener(this);

    }

        public void onClick(View v) {

            switch (v.getId()) {
            case R.id.button1:
                boolean dididwork =true;
                try{
                 String inputtext=et.getText().toString();
                 blockornot1 entry= new blockornot1(Mainclass.this);
                 entry.open();
                 entry.creatEntry(inputtext);
                 entry.close();
                 Log.v(TAG," okkkkkkk hastaaaaaaa");
                break;}
                catch (Exception e){
                    String error=e.toString();
                    Dialog d= new Dialog(this);
                    d.setTitle("Heack ya!"); 
                            TextView t= new TextView(this);
                            t.setText(error);
                            d.setContentView(t);
                            d.show();
                    dididwork=false;

                }finally {
                if(dididwork){
                    Dialog d= new Dialog(this);
                    d.setTitle("Heack ya!"); 
                            TextView t= new   TextView(this);
                            t.setText("success");
                            d.setContentView(t);
                            d.show();

                }

                }

            case R.id.button2view:
                Intent i = new Intent("android.intent.action.SQLVIEW");  
                startActivity(i);
                break;

            }




                  }

}

and this class is for display DB in textview

   public class ShowDb extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sqlview);
    TextView tv=(TextView)findViewById(R.id.textViewsqlview);
    blockornot1 info= new blockornot1(this);
    info.open();
    String data= info.getData();
    info.close();
    tv.setText(data);
}

}

  • 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-08T08:48:21+00:00Added an answer on June 8, 2026 at 8:48 am

    I’m guessing that you changed the table’s create statement at some point, but until you increment the database version your app will not automatically implement any changes. Try setting the DATABASE_VERSION to 3.

    Addition

    If you are going to bind the information in your database to a ListView, Spinner, etc then you should change KEY_ID to _id. (Android is particular about the name of the primary key column.)

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

Sidebar

Related Questions

I want get data in db to listview. but it have error I cannot
I am a new developer on Android and I want store user data in
Now I find ploblem again. I want get data in db to listview. but
I have posted this problem yesterday..but unfortunately, no one has given me the solution
Hay Guys, I'm new to Android but heres what i want to do. I
Intent i= new Intent( SetTest.this, SetTest.this);// compile error there i.putExtra(question_number, questionNumber++); startActivity(i); I want
I am new to android. I want to get GPS Location in a broadcast
I am new to Android development and I want first to get the Hello
Hi guys I am new to android...I want to display a dynamic list of
Im new to android and I want to create kind of CRUD with SQLite.

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.