Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Null Pointer exception when using property
    primarykey
    data
    text
    <p>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!</p> <p><strong>I'm getting the following error on the line :-</strong></p> <p><code>AssetDetails.ID = f.getString(f.getColumnIndex("AssetObsID"));</code></p> <pre><code>Null pointer access: The variable details can only be null at this location </code></pre> <p>My code that is having the error is:</p> <pre><code>public static List&lt;clsNameID&gt; assetHelperTypes(){ Log.e("Asset Helper Types:", "Started"); clsNameID AssetDetails = null; List&lt;clsNameID&gt; mHelperNames = new ArrayList&lt;clsNameID&gt;(); 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; } </code></pre> <p>Class clsNameID :-</p> <pre><code>package com.directenquiries.assessment.tool; public class clsNameID { public String Name; public String ID; } </code></pre> <p>I'm trying to call it with:</p> <pre><code> public void addCondition(View view){ List&lt;clsNameID&gt; mHelperNames = DBFunctions.assetHelperTypes(); final List&lt;Integer&gt; mSelectedItems = new ArrayList&lt;Integer&gt;(); 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(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload