Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Android Phone Sqlite
Hello Smile | :)
 
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
 
 
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:
 
02-25 22:06:43.290: E/AndroidRuntime(850): android.content.res.Resources$NotFoundException: String resource ID #0x8
Posted 25-Feb-12 10:14am
(unknown member)

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I found out the problem
 
I should add c1 to each line here
 
_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
 
 _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"));
  Permalink  

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

  Print Answers RSS
0 DamithSL 305
1 OriginalGriff 295
2 Sergey Alexandrovich Kryukov 207
3 Peter Leow 175
4 Afzaal Ahmad Zeeshan 154
0 OriginalGriff 7,460
1 DamithSL 5,519
2 Sergey Alexandrovich Kryukov 4,954
3 Maciej Los 4,936
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 27 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100