I have a problem which i’m trying to solve, I’ve been trying to fetch my data from an intent using mRowId below which I’ve been constantly returned a NullPointerException from fetchDrug() on LogCat.
Doing some troubleshooting using debugging, I’ve realized my variable mRowId is not Null and is pointing to something but I don’t know what its pointing.
How can i check what is my variable mRowId pointing ? Or will normally such variables be gibberish that is incomprehensible?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drug_info);
//Defining the views
mDrugText = (TextView) findViewById(R.id.drug);
mContentText = (TextView) findViewById(R.id.content);
Bundle extras = getIntent().getExtras();
mRowId = extras.getLong(DrugsDbAdapter.KEY_ROWID);
if(mRowId == null) {
Log.e("mRowId is null", "ok");
} else {
Cursor drug = mDbHelper.fetchDrug(mRowId);
//Managing Cursor to pluck values to display
startManagingCursor(drug);
mDrugText.setText(drug.getString(drug.getColumnIndexOrThrow(DrugsDbAdapter.KEY_DRUG)));
mContentText.setText(drug.getString(drug.getColumnIndexOrThrow(DrugsDbAdapter.KEY_CONTENT)));
}
}
Instead of printf, use the existing log functionality in the SDK.
Output will appear in the logcat window of Eclipse (probably best option, since it’s reasonably real-time and you can filter the display), or you can pull the logs off the device/emulator manually.
For example: