• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps App crash after trying to retrieve data from sqlite

iliji

Lurker
Hi guys, I'm currently facing a problem, after inserting data on activity, after pressing the send button, another activity is loaded on which the most recent data stored in the database is loaded in displayed in a TextView.
But each time I pressed the send button, when the app redirect me to the next activity it crashed and I dunno why. If you could help me, I thank you in advance.

Below the DBHelper.java

Java:
public Cursor getDataSoilData(String username){
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery("Select pH, OCarbon, nitrogen, phosphorus, potassium, zinc, temparature, date from soilData where username = ? ORDER BY id DESC LIMIT 1", new String[] {username}, null);
        return cursor;
    };

Below the activity that is fetching the data
Java:
public class StatusActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_status);

        Button viewData = (Button)findViewById(R.id.submitBtn);
        TextView pHLevel = (TextView)findViewById(R.id.phLevel);
        TextView organicCLevel = (TextView)findViewById(R.id.organicCLevel);
        TextView nitrogenLevel = (TextView)findViewById(R.id.nitrogenlevel);
        TextView phosphorusLevel = (TextView)findViewById(R.id.phosphorusLevel);
        TextView potassiumLevel = (TextView)findViewById(R.id.potassiumLevel);
        TextView  zincLevel = (TextView)findViewById(R.id.zincLevel);
        TextView temperatureLevel = (TextView)findViewById(R.id.temparatureLevel);
        TextView date1 = (TextView)findViewById(R.id.date);
        String tempMessage;
        String pHMessage;
        String organicCMessage;
        String nitrogenMessage;
        String phosphorusMessage;
        String potassiumMessage;
        String zincMessage;
        DBHelper db = new DBHelper(this);
        String username = getIntent().getStringExtra("username");
        Cursor cursor = db.getDataSoilData(username);
        StringBuilder pH = new StringBuilder();
        StringBuilder organicC1 = new StringBuilder();
        StringBuilder nitrogen1 = new StringBuilder();
        StringBuilder phosphorus1 = new StringBuilder();
        StringBuilder potassium1 = new StringBuilder();
        StringBuilder zinc1 = new StringBuilder();
        StringBuilder temp = new StringBuilder();
        StringBuilder date = new StringBuilder();;
        while(cursor.moveToNext()){
            pH.append(cursor.getDouble(2));
            organicC1.append(cursor.getDouble(3));
            nitrogen1.append(cursor.getDouble(4));
            phosphorus1.append(cursor.getDouble(5));
            potassium1.append(cursor.getDouble(6));
            zinc1.append(cursor.getDouble(7));
            temp.append(cursor.getDouble(8));
            date.append(cursor.getString(9));
        }
 
Solved by myself, one whole day wasted due to a typo in DPHelper. I mistakenly write temparature in the request while the column name is temperature
 
Back
Top Bottom