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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:59:44+00:00 2026-05-28T05:59:44+00:00

my problem is, when I put something in my text fields and save that

  • 0

my problem is, when I put something in my text fields and save that to database, the ID of that row is null1
instead of 1
here is my code for creating database and putting data in database :

    private HelperDb myHelper;
    private final Context myContext;
    private SQLiteDatabase myDatabase;
    private static class HelperDb extends SQLiteOpenHelper {

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

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
        KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
        KEY_NAME + " STRING, " +
        KEY_TEKST + " TEXT, " +
        KEY_DATUM + " STRING, " +
        KEY_VREME + " STRING);"
                );


    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
        this.onCreate(db);

    }

}

public Baza(Context c){
    myContext = c;
}

public Baza open() throws SQLException {
    myHelper = new HelperDb(myContext);
    myDatabase = myHelper.getWritableDatabase();
    return this;
}

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

// this is how I put data in database
public long unesiPodatkeBaza(String ime, String napisaniTekst, String uneseniDatum, String unesenoVreme) {
    // TODO Auto-generated method stub
    ContentValues cv = new ContentValues();
    cv.put(KEY_NAME, ime);
    cv.put(KEY_TEKST, napisaniTekst);
    cv.put(KEY_DATUM, uneseniDatum);
    cv.put(KEY_VREME, unesenoVreme);

    return myDatabase.insert(DATABASE_TABLE, null, cv);

}

later that make problem for application.

This is how I collect data from database:

public String[] getData() {

    String[] kolone = new String[]{KEY_ROWID, KEY_NAME, KEY_TEKST, KEY_DATUM, KEY_VREME};

    Cursor c = myDatabase.query(DATABASE_TABLE, kolone, null, null, null, null, null);

    iRed = c.getColumnIndex(KEY_ROWID);
    iIme = c.getColumnIndex(KEY_NAME);
    iTekst = c.getColumnIndex(KEY_TEKST);
    iDatum = c.getColumnIndex(KEY_DATUM);
    iVreme = c.getColumnIndex(KEY_VREME);

    for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
        result = result + c.getString(iRed) + " " + c.getString(iIme) + " " + c.getString(iTekst) + " " + c.getString(iDatum) + " " + c.getString(iVreme) + "\n";
    }

    return result.split("\n");
}

and this is what I’m doing with data:

public class SQLPregled extends Activity{

    public String[] data;
    private ListView lv;
    private int idSend;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pregledbaze);

        lv = (ListView) findViewById(R.id.lvListaBaza);

        final Baza izlistavanje = new Baza(this);
        izlistavanje.open();
        data = izlistavanje.getData();
        izlistavanje.close();


        lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data));

        lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id){

                String tmplv = lv.getItemAtPosition(position).toString();
                String[] odvojeni = tmplv.split(" ");

                idSend = Integer.parseInt(odvojeni[0]);

                AlertDialog.Builder adb = new AlertDialog.Builder(SQLPregled.this);
                adb.setTitle("Dali zelite da obrisete izabranu poruku?");
                adb.setMessage("Id je : " + odvojeni[0]);
                adb.setPositiveButton("Obrisi", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        izlistavanje.open();
                        izlistavanje.deleteData(idSend); 
                        izlistavanje.close();
                        onCreate(null); 

                    }
                }); 

                adb.setNegativeButton("Odustani", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        dialog.cancel(); 
                    }
                });

                adb.show(); 
            }

        }); 

    } // onCreate

}
  • 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-28T05:59:44+00:00Added an answer on May 28, 2026 at 5:59 am

    it certainly can not have an ID of “null1” as the table definition has the ID defined as an INTEGER, so you would get errors when trying to set that value and the db would not store it that way.

    it’s more likely that when you’re reading / displaying it, you’re appending it to a null value so null + 1 = “null1” though some sort of string cast hocus pocus. Can you show us how you’re getting and displaying the id field? Why do you think it’s “null1”?

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

Sidebar

Related Questions

I have a ASP.Net web form that contains both text box fields and hidden
Hello I have problem to put together animations of two separate objects to second
When i put an NSOpenglView in NSSplitView, a problem occurs while dragging splitter. The
I encountered a strange problem today. Whenever i put a breakpoint in one of
I need to put an alpha blended gradient border around an image. My problem
Problem: I have an address field from an Access database which has been converted
Problem: I have two spreadsheets that each serve different purposes but contain one particular
Problem (simplified to make things clearer): 1. there is one statically-linked static.lib that has
Problem: Ajax suggest-search on [ n ] ingredients in recipes. That is: match recipes
I have a form with a text area field. I put some text information

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.