Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy am I getting NullPointerException here?
    primarykey
    data
    text
    <p>I have this code in one of my activity's onCreate Method</p> <pre><code> GetNews newsReporter = new GetNews(getApplicationContext()); try{ News[] allNews = newsReporter.getAllNews(); Log.d("News Count", String.valueOf(allNews.length)); String[] timestamps = new String[allNews.length]; String[] texts = new String[allNews.length]; for(int i=0;i&lt;allNews.length;i++) { // timestamps[i] = allNews[i].getNewsTime(); texts[i] = allNews[i].getNewsText(); // Log.d("TimeStamp", timestamps[i]); Log.d("Text", texts[i]); } }catch(Exception e){ Log.e("Error News", e.toString()); } </code></pre> <p>News Count Displays 6 in Logcat, which means News[] is not null.</p> <p>But I receive NullPointerException on Line texts[i] = allNews[i].getNewsTime();</p> <p>this is my News Class</p> <pre><code> public class News { private int id; private String timestamp; private String text; public News(int i,String t, String ti) { this.id=i; this.text = t; this.timestamp = ti; } public String getNewsTime() { return this.timestamp; } public String getNewsText() { return this.text; } } </code></pre> <p>P.S. News is stored in a SQLitedatabase, when i pulled the database from my DDMS, it contains all 6 rows with valid values none of them is null.</p> <p>Edit: This is my GetAllNews Method</p> <pre><code>public News[] getAllNews(){ SQLiteDatabase db = ConMan.OpenDBConnection(); try{ Cursor cursor = db.query(News_Table, Columns, null, null, null, null, null); if(cursor!=null) { cursor.moveToFirst(); } News[] allNews = new News[cursor.getCount()]; int i =0; while(cursor.isLast()){ allNews[i] = new News(Integer.parseInt(cursor.getString(0)), cursor.getString(1),cursor.getString(2)); cursor.moveToNext(); i++; } db.close(); ConMan.close(); return allNews; }catch(Exception e) { Log.e("News DB Errors", e.getMessage()); } return null; } </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.
 

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