I'm using a public class to save 2 pieces of information to an array (so I can easily get the name and the ID). However for some reason it doesn't seem to like it!
I'm getting the following error on the line :-
AssetDetails.ID = f.getString(f.getColumnIndex("AssetObsID"));
Null pointer access: The variable details can only be null at this location
My code that is having the error is:
public static List<clsNameID> assetHelperTypes(){
Log.e("Asset Helper Types:", "Started");
clsNameID AssetDetails = null;
List<clsNameID> mHelperNames = new ArrayList<clsNameID>();
File dbfile = new File(Global.currentDBfull);
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null);
Cursor f = db.rawQuery("select * from assetobservationtypes", null);
Log.e("Asset Helper Types:", "Cursor run");
if(f.getCount() != 0) {
f.moveToFirst();
while(!f.isAfterLast()) {
Log.e("Asset Helper Types:", "Finding Items");
AssetDetails.ID = f.getString(f.getColumnIndex("AssetObsID"));
AssetDetails.Name = f.getString(f.getColumnIndex("Observation"));
mHelperNames.add(AssetDetails);
Log.e("Asset Helper Types:", "Added Items");
}
}
f.close();
return mHelperNames;
}
Class clsNameID :-
package com.directenquiries.assessment.tool;
public class clsNameID {
public String Name;
public String ID;
}
I'm trying to call it with:
public void addCondition(View view){
List<clsNameID> mHelperNames = DBFunctions.assetHelperTypes();
final List<Integer> mSelectedItems = new ArrayList<Integer>();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("My Title")
.setMultiChoiceItems(mHelperNames.toArray(new CharSequence[mHelperNames.size()]), null,
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which, boolean isChecked) {
if (isChecked) {
mSelectedItems.add(which);
} else if (mSelectedItems.contains(which)) {
mSelectedItems.remove(Integer
.valueOf(which));
}
}
})
.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//Create onlcick method
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//Create onlcick method
}
});
builder.show();
}
AssetDetails, its null . and you are trying to accessIDon it.