Click here to Skip to main content
15,886,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello :)

I have a problem when I try to retrieve some data from SQLite in android

the emulator stop working during the execution,

this is my code

Java
public class StartTest extends Activity {
	
	// Objects And Variables
	public HtTester _testclass;
	private CommentsDataSource datasource2;
	private SQLiteDatabase db;
	private String _select;
	// User Information Variables
	String _c1;
	String _c2;
	String _c3;
	String _c4;
	String _c5;
	String _c6;
	String _pregnant;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.starttest);
        
        // Casting Controls To variables
        Button _strattest = (Button) findViewById(R.id.btnsendtest);
        final EditText _systolic = (EditText) findViewById(R.id.etsystolic);
        final EditText _diastolic = (EditText) findViewById(R.id.etdiastolic);
        //CheckBox _pregnant = (CheckBox) findViewById(R.id.cbpregnant);
        final TextView _result = (TextView) findViewById(R.id.tvresult);
        
        //Start Test Button Operation
        _strattest.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {

				datasource2 = new CommentsDataSource();
				db = datasource2.SQLiteDatabaseget(StartTest.this);
				_select = "SELECT * FROM USERSTABLE WHERE _id=" + getIntent().getExtras().getString("USERID");
				Cursor c1 = db.rawQuery(_select, null);
				_c1 = getString(c1.getColumnIndex("USERC1"));
				_c2 = getString(c1.getColumnIndex("USERC2"));
				_c3 = getString(c1.getColumnIndex("USERC3"));
				_c4 = getString(c1.getColumnIndex("USERC4"));
				_c5 = getString(c1.getColumnIndex("USERC5"));
				_c6 = getString(c1.getColumnIndex("USERC6"));
				_result.setText(_c1 + "," +_c2 + "," +_c3 + "," +_c4 + "," +_c5+ "," +_c6 );
			}
		});
	}
}


the error is:

Java
02-25 22:06:43.290: E/AndroidRuntime(850): android.content.res.Resources$NotFoundException: String resource ID #0x8
Posted

1 solution

I found out the problem

I should add c1 to each line here

C#
_c1 = getString(c1.getColumnIndex("USERC1"));
                _c2 = getString(c1.getColumnIndex("USERC2"));
                _c3 = getString(c1.getColumnIndex("USERC3"));
                _c4 = getString(c1.getColumnIndex("USERC4"));
                _c5 = getString(c1.getColumnIndex("USERC5"));
                _c6 = getString(c1.getColumnIndex("USERC6"));

to look like this

C#
_c1 = getString(c1.getColumnIndex("USERC1"));
               _c2 = c1.getString(c1.getColumnIndex("USERC2"));
               _c3 = c1.getString(c1.getColumnIndex("USERC3"));
               _c4 = c1.getString(c1.getColumnIndex("USERC4"));
               _c5 = c1.getString(c1.getColumnIndex("USERC5"));
               _c6 = c1.getString(c1.getColumnIndex("USERC6"));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900