Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Handler NullPointerException (while sending Message)
    text
    copied!<p>I have a problem with <code>Handler</code>. This is what my app does:</p> <ol> <li>New Thread is created.</li> <li>Thread downloads data, then puts them in a message.</li> <li>Thread sends message to handler.</li> </ol> <p>And here the problem begins. According to logs app throws <code>NullPointerException</code> in this line:</p> <pre><code>replyTo.sendMessage(msg); </code></pre> <p>Sometimes everything is OK, sometimes it's not. Handler is placed before creating a new thread. This is code for handler:</p> <pre><code>Handler responseHandler = new Handler() { public void handleMessage(Message msg) { ad.dismiss(); populateListWithVideos(msg); }; }; </code></pre> <p>Do you have any ideas why is this happening?</p> <p>EDIT: Here's my Logcat. How to read it:</p> <ul> <li>"Powstała nowa biblioteka" - new ArrayList has been created</li> <li>"Array" - JSONArray has been recieved</li> <li>"Obiekt"/"Tytuł" + number - Object/String from JSONArray has been recieved (number - an object number)</li> <li>"Dodano do biblioteki" - strings recieved from Object have been added to array as Video</li> <li>"Nowa biblioteka" - new Library created from ArrayList</li> <li>"Serializable" - Library serialized into bundle</li> <li>"Otrzymano wiadomość" - Message obtained using Message.obtain()</li> <li>"Ustalono wiadomość" - Bundle put into Message using Message.setData()</li> <li><p>"Wysłano wiadomość" - Message sent to Handler</p> <pre><code>02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Powstała nowa biblioteka 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Array 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Obiekt0 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Tytuł0 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Dodano do biblioteki 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Obiekt1 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Tytuł1 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Dodano do biblioteki 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Obiekt2 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Tytuł2 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Dodano do biblioteki 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Obiekt3 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Tytuł3 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Dodano do biblioteki 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Obiekt4 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Tytuł4 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Dodano do biblioteki 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Obiekt5 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Tytuł5 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Dodano do biblioteki 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Obiekt6 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Tytuł6 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Dodano do biblioteki 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Obiekt7 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Tytuł7 02-07 13:17:13.885: D/Ignaś TV(24913): Thread-6447| Dodano do biblioteki ... 02-07 13:17:13.905: D/Ignaś TV(24913): Thread-6447| Obiekt48 02-07 13:17:13.905: D/Ignaś TV(24913): Thread-6447| Tytuł48 02-07 13:17:13.905: D/Ignaś TV(24913): Thread-6447| Dodano do biblioteki 02-07 13:17:13.905: D/Ignaś TV(24913): Thread-6447| Obiekt49 02-07 13:17:13.905: D/Ignaś TV(24913): Thread-6447| Tytuł49 02-07 13:17:13.905: D/Ignaś TV(24913): Thread-6447| Dodano do biblioteki 02-07 13:17:13.905: D/Ignaś TV(24913): Thread-6447| Nowa biblioteka 02-07 13:17:13.905: D/Ignaś TV(24913): Thread-6447| Serializable 02-07 13:17:13.905: D/Ignaś TV(24913): Thread-6447| Otrzymano wiadomość 02-07 13:17:13.905: D/Ignaś TV(24913): Thread-6447| Ustalono wiadomość 02-07 13:17:13.905: E/Ignaś TV(24913): Thread-6447| Koniec listy //Error 02-07 13:17:13.905: E/Ignaś TV(24913): java.lang.NullPointerException 02-07 13:17:13.905: E/Ignaś TV(24913): at com.ignas.ignastv.service.task.GetData.run(GetData.java:142) 02-07 13:17:13.905: E/Ignaś TV(24913): at java.lang.Thread.run(Thread.java:856) </code></pre></li> </ul>
 

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