Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Null Checker
    primarykey
    data
    text
    <p>I have a program that relates to a database. I start out my program by inserting a row using the following command.</p> <pre><code> long id = db.insertMajor(null, null, null, null); </code></pre> <p>it works perfect. I than alter the information but lets ignore that since for the time being I commented out all those lines. Now I want to check and see if it is null which is should be. If it is not null than I would like to check a checkbox. if it is null than I want to leave the box unchecked. So far I have this line to test.</p> <pre><code> String change = db.getMajorTitle(value).getString(1); if (change.equals(null)) { filled = false; } </code></pre> <p>the filled boolean will check the box or not. If the database field is filled or not I always get a checkmark. Whats wrong?</p> <p>UPDATE: Since no one has figure it out I will post most of my code to try and help figure it out. I have also reset my emulator to ensure there is not problems with corrupted data.</p> <pre><code> chk1.setChecked(checker(1)); chk2.setChecked(checker(2)); chk3.setChecked(checker(3)); chk4.setChecked(checker(4)); } boolean checker(int value){ DBAdapter db = new DBAdapter(this); boolean filled = false; db.open(); for (int i = 1; i &lt;= 4; i++) { String change = db.getMajorTitle(value).getString(1); if (change == null) { filled = false; }else{ filled = true; } } db.close(); return filled; } </code></pre> <p>If someone copies this and it works can you please tell me what might be wrong with my emulator or eclipse or whatever. Thanks everyone for there input.</p> <p>FINISHED: I noticed that at another part in my program I changed null to "". I would like to thank everyone for being right and showing me different ways to code it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload