Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ListView throwing NullPointerException when I try to scroll
    text
    copied!<p>Not exactly sure what is going on here so I am hoping one of you can point me in the right direction. I have a ListView within a Tab frame and for some reason, it loads but crashes when I try to scroll. </p> <p>Here is all of the information I could gather</p> <p>Here is the Activity that goes into the frame... it parses an XML file into a priority queue, gets the attached intent information, and loads the desired page. </p> <pre><code>public class QScoresFrameActivity extends ListActivity { private PriorityQueue&lt;Score&gt; mScores; private int mDifficulty; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.scoresframe); mDifficulty = getIntent().getIntExtra(getResources().getString(R.string.difficulty), getResources().getInteger(R.integer.normal_level)); mScores = QGameGlobals.ParseScoresXML(this,mDifficulty); setListAdapter(new ScoresAdapter(this)); } private class ScoresAdapter extends BaseAdapter { private LayoutInflater mInflater; public ScoresAdapter(Context context) { mInflater = LayoutInflater.from(context); } public View getView(int position, View convertView, ViewGroup parent) { Score thisScore = mScores.getByIndex(position); convertView = mInflater.inflate(R.layout.scoreview, null); TextView posT; TextView nameT; TextView scoreT; String name = thisScore.getName(); int score = thisScore.getScore(); posT = (TextView)convertView.findViewById(R.id.position); nameT = (TextView)convertView.findViewById(R.id.scorerName); scoreT= (TextView)convertView.findViewById(R.id.scorerScore); posT.setText(String.valueOf(position + 1) + ". "); nameT.setText(name); scoreT.setText(String.valueOf(score)); return convertView; } public int getCount() { return mScores.getLength(); } public Object getItem(int position) { return this; } public long getItemId(int position) { return position; } } </code></pre> <p>}</p> <p>The layout file that holds the list:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"&gt; &lt;ListView android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+android:id/list" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>The layout file for each item in the list:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearLayout1" android:padding="10dp" android:layout_width="fill_parent" android:baselineAligned="false" android:orientation="horizontal" android:layout_height="wrap_content"&gt; &lt;TextView android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView" android:paddingRight="10dp" android:id="@+id/position" android:layout_width="50dp" android:textColor="@color/teal" &gt;&lt;/TextView&gt; &lt;TextView android:id="@+id/scorerName" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="TextView" android:layout_width="wrap_content" android:layout_gravity="center_vertical"&gt;&lt;/TextView&gt; &lt;TextView android:id="@+id/scorerScore" android:text="TextView" android:textAppearance="?android:attr/textAppearanceLarge" android:paddingLeft="20dp" android:layout_height="wrap_content" android:gravity="right" android:textColor="@color/gold" android:layout_width="match_parent" android:layout_gravity="center_vertical"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>Priority Queue class....</p> <pre><code>@SuppressWarnings("rawtypes") public class PriorityQueue&lt;T extends Comparable&gt; extends Queue&lt;T&gt; { public PriorityQueue () { super(); } @SuppressWarnings("unchecked") @Override public void enqueue(T item) /* Enqueue a new object of type T into the queue based on its compareTo method. * Sorts from greatest to least. */ { TNode newNode = new TNode(item); if (root == null) { root = newNode; end = newNode; } else { TNode currNode = root; TNode lastNode = root; while (true) { int compVal = item.compareTo(currNode.get()); if (compVal == 1 || compVal == 0) { if (currNode == root) { root = newNode; } else { lastNode.next = newNode; newNode.next = currNode; } newNode.next = currNode; break; } else { if (currNode == end) { currNode.next = newNode; end = newNode; break; } else { lastNode = currNode; currNode = currNode.next; } } } } length++; } } </code></pre> <p>Appreciate the help.</p>
 

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