null pointer exception in onPostExecute










2















I have no idea how to work out where this null pointer exception is occurring.



The crash has only happened once (so far) on a user's physical device as advised by Google Play - I haven't been able to reproduce it in a debug environment.



The Stack Trace that Google Play gives me seems a bit vague (despite me having loaded a mapping file for the release):



java.lang.NullPointerException: 
at com.nooriginalthought.amalfi.getShortURL.a (getShortURL.java:11)
at com.nooriginalthought.amalfi.getShortURL.onPostExecute (getShortURL.java:2)
at android.os.AsyncTask.finish (AsyncTask.java:695)
at android.os.AsyncTask.access$600 (AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage (AsyncTask.java:712)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:193)
at android.app.ActivityThread.main (ActivityThread.java:6806)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:873)


All I can see is that the exception appears to be being thrown by the onPostExecute function in my getShortURL class (this is an async task that calls the bitly API).



The code works fine and only a single crash has been reported.



The code in onPostExecute is very simple (incl source code line numbers):



1320 @Override
1321 protected void onPostExecute(String shortURL)
1322 super.onPostExecute(shortURL);
1323 mainActivityWeakReference.get().shortURLreturn(shortURL);
1324


(shortURLreturn is defined within my MainActivity class)



How can I work out what actually threw this error?










share|improve this question






















  • That's a tough one. The '.a' is a sure sign getShortURL was obfuscated - but evidently only partially (since onPostExecute is listed) - perhaps you're using the wrong map to deobfuscate? Can't the WeakReference.get return null whenever the GC decides?

    – Andy
    Nov 12 '18 at 18:04












  • @NonNull String shortURL

    – Martin Zeitler
    Nov 12 '18 at 18:57















2















I have no idea how to work out where this null pointer exception is occurring.



The crash has only happened once (so far) on a user's physical device as advised by Google Play - I haven't been able to reproduce it in a debug environment.



The Stack Trace that Google Play gives me seems a bit vague (despite me having loaded a mapping file for the release):



java.lang.NullPointerException: 
at com.nooriginalthought.amalfi.getShortURL.a (getShortURL.java:11)
at com.nooriginalthought.amalfi.getShortURL.onPostExecute (getShortURL.java:2)
at android.os.AsyncTask.finish (AsyncTask.java:695)
at android.os.AsyncTask.access$600 (AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage (AsyncTask.java:712)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:193)
at android.app.ActivityThread.main (ActivityThread.java:6806)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:873)


All I can see is that the exception appears to be being thrown by the onPostExecute function in my getShortURL class (this is an async task that calls the bitly API).



The code works fine and only a single crash has been reported.



The code in onPostExecute is very simple (incl source code line numbers):



1320 @Override
1321 protected void onPostExecute(String shortURL)
1322 super.onPostExecute(shortURL);
1323 mainActivityWeakReference.get().shortURLreturn(shortURL);
1324


(shortURLreturn is defined within my MainActivity class)



How can I work out what actually threw this error?










share|improve this question






















  • That's a tough one. The '.a' is a sure sign getShortURL was obfuscated - but evidently only partially (since onPostExecute is listed) - perhaps you're using the wrong map to deobfuscate? Can't the WeakReference.get return null whenever the GC decides?

    – Andy
    Nov 12 '18 at 18:04












  • @NonNull String shortURL

    – Martin Zeitler
    Nov 12 '18 at 18:57













2












2








2








I have no idea how to work out where this null pointer exception is occurring.



The crash has only happened once (so far) on a user's physical device as advised by Google Play - I haven't been able to reproduce it in a debug environment.



The Stack Trace that Google Play gives me seems a bit vague (despite me having loaded a mapping file for the release):



java.lang.NullPointerException: 
at com.nooriginalthought.amalfi.getShortURL.a (getShortURL.java:11)
at com.nooriginalthought.amalfi.getShortURL.onPostExecute (getShortURL.java:2)
at android.os.AsyncTask.finish (AsyncTask.java:695)
at android.os.AsyncTask.access$600 (AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage (AsyncTask.java:712)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:193)
at android.app.ActivityThread.main (ActivityThread.java:6806)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:873)


All I can see is that the exception appears to be being thrown by the onPostExecute function in my getShortURL class (this is an async task that calls the bitly API).



The code works fine and only a single crash has been reported.



The code in onPostExecute is very simple (incl source code line numbers):



1320 @Override
1321 protected void onPostExecute(String shortURL)
1322 super.onPostExecute(shortURL);
1323 mainActivityWeakReference.get().shortURLreturn(shortURL);
1324


(shortURLreturn is defined within my MainActivity class)



How can I work out what actually threw this error?










share|improve this question














I have no idea how to work out where this null pointer exception is occurring.



The crash has only happened once (so far) on a user's physical device as advised by Google Play - I haven't been able to reproduce it in a debug environment.



The Stack Trace that Google Play gives me seems a bit vague (despite me having loaded a mapping file for the release):



java.lang.NullPointerException: 
at com.nooriginalthought.amalfi.getShortURL.a (getShortURL.java:11)
at com.nooriginalthought.amalfi.getShortURL.onPostExecute (getShortURL.java:2)
at android.os.AsyncTask.finish (AsyncTask.java:695)
at android.os.AsyncTask.access$600 (AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage (AsyncTask.java:712)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:193)
at android.app.ActivityThread.main (ActivityThread.java:6806)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:873)


All I can see is that the exception appears to be being thrown by the onPostExecute function in my getShortURL class (this is an async task that calls the bitly API).



The code works fine and only a single crash has been reported.



The code in onPostExecute is very simple (incl source code line numbers):



1320 @Override
1321 protected void onPostExecute(String shortURL)
1322 super.onPostExecute(shortURL);
1323 mainActivityWeakReference.get().shortURLreturn(shortURL);
1324


(shortURLreturn is defined within my MainActivity class)



How can I work out what actually threw this error?







android android-asynctask nullpointerexception






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 '18 at 17:25









Fat MonkFat Monk

7931034




7931034












  • That's a tough one. The '.a' is a sure sign getShortURL was obfuscated - but evidently only partially (since onPostExecute is listed) - perhaps you're using the wrong map to deobfuscate? Can't the WeakReference.get return null whenever the GC decides?

    – Andy
    Nov 12 '18 at 18:04












  • @NonNull String shortURL

    – Martin Zeitler
    Nov 12 '18 at 18:57

















  • That's a tough one. The '.a' is a sure sign getShortURL was obfuscated - but evidently only partially (since onPostExecute is listed) - perhaps you're using the wrong map to deobfuscate? Can't the WeakReference.get return null whenever the GC decides?

    – Andy
    Nov 12 '18 at 18:04












  • @NonNull String shortURL

    – Martin Zeitler
    Nov 12 '18 at 18:57
















That's a tough one. The '.a' is a sure sign getShortURL was obfuscated - but evidently only partially (since onPostExecute is listed) - perhaps you're using the wrong map to deobfuscate? Can't the WeakReference.get return null whenever the GC decides?

– Andy
Nov 12 '18 at 18:04






That's a tough one. The '.a' is a sure sign getShortURL was obfuscated - but evidently only partially (since onPostExecute is listed) - perhaps you're using the wrong map to deobfuscate? Can't the WeakReference.get return null whenever the GC decides?

– Andy
Nov 12 '18 at 18:04














@NonNull String shortURL

– Martin Zeitler
Nov 12 '18 at 18:57





@NonNull String shortURL

– Martin Zeitler
Nov 12 '18 at 18:57












1 Answer
1






active

oldest

votes


















1














There's not much code posted, so there'll be mostly guessing.



How sure are you that the mainActivityWeakReference isn't null since it's a weak reference? Check this link on how to use weak reference activities link.
Something like:



@Override
protected void onPostExecute(String shortURL)
MainActivity mainActivity = mainActivityWeakReference.get();
if (mainActivity != null)
mainActivity.shortURLreturn(shortURL);




Also, for that kind of action, you don't actually need a weak reference to the activity (of course, only if you don't need any methods that actually belong to the Android Activity class). If you only need your public methods that you have implemented in your MainActivity, you could make an Interface, for example:



interface ShortUrlReceiveCallback 
void onReceive(String shortURL);



and then you would just have that reference saved in the constructor of getShortURL class (note that classes start with uppercase) and later on call in onPostExecute -> shortUrlReceiveCallback.onReceive(shortURL); and have your MainActivity implement that ShortActivityCallback.



For my 2nd point, bare in mind that onPostExecute happens on a different thread (IO/background thread) than MainActivity (UiThread), if you are doing anything afterwards that's supposed to be on main thread or thread safe (variables setting should be thread safe; try using locks if you aren't for example:



class MainActivity 
private String mainShortUrl;
private Lock urlReturnLock = new ReentrantLock();
...
public void shortURLReturn(String shortUrl)
urlReturnLock.lock();
try
mainShortUrl = shortUrl;
finally
urlReturnLock.unlock();








share|improve this answer























  • So, if I understand correctly, I should be able to avoid the null pointer by simply checking that my week reference still exists (is not null) before carrying out anything useful in onPostExecute? And the only reason the week reference would be null is it the garbage collector had destroyed it out the user has had like the process of something similar - in which case my async task would have nothing to return to anyway, so not running my return function would be fine. Have I understood that correctly? (And then the interface stuff is interesting for another time, thanks!)

    – Fat Monk
    Nov 12 '18 at 21:54











  • Yes, your understanding is correct.

    – mihanovak1024
    Nov 13 '18 at 6:50










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267172%2fnull-pointer-exception-in-onpostexecute%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














There's not much code posted, so there'll be mostly guessing.



How sure are you that the mainActivityWeakReference isn't null since it's a weak reference? Check this link on how to use weak reference activities link.
Something like:



@Override
protected void onPostExecute(String shortURL)
MainActivity mainActivity = mainActivityWeakReference.get();
if (mainActivity != null)
mainActivity.shortURLreturn(shortURL);




Also, for that kind of action, you don't actually need a weak reference to the activity (of course, only if you don't need any methods that actually belong to the Android Activity class). If you only need your public methods that you have implemented in your MainActivity, you could make an Interface, for example:



interface ShortUrlReceiveCallback 
void onReceive(String shortURL);



and then you would just have that reference saved in the constructor of getShortURL class (note that classes start with uppercase) and later on call in onPostExecute -> shortUrlReceiveCallback.onReceive(shortURL); and have your MainActivity implement that ShortActivityCallback.



For my 2nd point, bare in mind that onPostExecute happens on a different thread (IO/background thread) than MainActivity (UiThread), if you are doing anything afterwards that's supposed to be on main thread or thread safe (variables setting should be thread safe; try using locks if you aren't for example:



class MainActivity 
private String mainShortUrl;
private Lock urlReturnLock = new ReentrantLock();
...
public void shortURLReturn(String shortUrl)
urlReturnLock.lock();
try
mainShortUrl = shortUrl;
finally
urlReturnLock.unlock();








share|improve this answer























  • So, if I understand correctly, I should be able to avoid the null pointer by simply checking that my week reference still exists (is not null) before carrying out anything useful in onPostExecute? And the only reason the week reference would be null is it the garbage collector had destroyed it out the user has had like the process of something similar - in which case my async task would have nothing to return to anyway, so not running my return function would be fine. Have I understood that correctly? (And then the interface stuff is interesting for another time, thanks!)

    – Fat Monk
    Nov 12 '18 at 21:54











  • Yes, your understanding is correct.

    – mihanovak1024
    Nov 13 '18 at 6:50















1














There's not much code posted, so there'll be mostly guessing.



How sure are you that the mainActivityWeakReference isn't null since it's a weak reference? Check this link on how to use weak reference activities link.
Something like:



@Override
protected void onPostExecute(String shortURL)
MainActivity mainActivity = mainActivityWeakReference.get();
if (mainActivity != null)
mainActivity.shortURLreturn(shortURL);




Also, for that kind of action, you don't actually need a weak reference to the activity (of course, only if you don't need any methods that actually belong to the Android Activity class). If you only need your public methods that you have implemented in your MainActivity, you could make an Interface, for example:



interface ShortUrlReceiveCallback 
void onReceive(String shortURL);



and then you would just have that reference saved in the constructor of getShortURL class (note that classes start with uppercase) and later on call in onPostExecute -> shortUrlReceiveCallback.onReceive(shortURL); and have your MainActivity implement that ShortActivityCallback.



For my 2nd point, bare in mind that onPostExecute happens on a different thread (IO/background thread) than MainActivity (UiThread), if you are doing anything afterwards that's supposed to be on main thread or thread safe (variables setting should be thread safe; try using locks if you aren't for example:



class MainActivity 
private String mainShortUrl;
private Lock urlReturnLock = new ReentrantLock();
...
public void shortURLReturn(String shortUrl)
urlReturnLock.lock();
try
mainShortUrl = shortUrl;
finally
urlReturnLock.unlock();








share|improve this answer























  • So, if I understand correctly, I should be able to avoid the null pointer by simply checking that my week reference still exists (is not null) before carrying out anything useful in onPostExecute? And the only reason the week reference would be null is it the garbage collector had destroyed it out the user has had like the process of something similar - in which case my async task would have nothing to return to anyway, so not running my return function would be fine. Have I understood that correctly? (And then the interface stuff is interesting for another time, thanks!)

    – Fat Monk
    Nov 12 '18 at 21:54











  • Yes, your understanding is correct.

    – mihanovak1024
    Nov 13 '18 at 6:50













1












1








1







There's not much code posted, so there'll be mostly guessing.



How sure are you that the mainActivityWeakReference isn't null since it's a weak reference? Check this link on how to use weak reference activities link.
Something like:



@Override
protected void onPostExecute(String shortURL)
MainActivity mainActivity = mainActivityWeakReference.get();
if (mainActivity != null)
mainActivity.shortURLreturn(shortURL);




Also, for that kind of action, you don't actually need a weak reference to the activity (of course, only if you don't need any methods that actually belong to the Android Activity class). If you only need your public methods that you have implemented in your MainActivity, you could make an Interface, for example:



interface ShortUrlReceiveCallback 
void onReceive(String shortURL);



and then you would just have that reference saved in the constructor of getShortURL class (note that classes start with uppercase) and later on call in onPostExecute -> shortUrlReceiveCallback.onReceive(shortURL); and have your MainActivity implement that ShortActivityCallback.



For my 2nd point, bare in mind that onPostExecute happens on a different thread (IO/background thread) than MainActivity (UiThread), if you are doing anything afterwards that's supposed to be on main thread or thread safe (variables setting should be thread safe; try using locks if you aren't for example:



class MainActivity 
private String mainShortUrl;
private Lock urlReturnLock = new ReentrantLock();
...
public void shortURLReturn(String shortUrl)
urlReturnLock.lock();
try
mainShortUrl = shortUrl;
finally
urlReturnLock.unlock();








share|improve this answer













There's not much code posted, so there'll be mostly guessing.



How sure are you that the mainActivityWeakReference isn't null since it's a weak reference? Check this link on how to use weak reference activities link.
Something like:



@Override
protected void onPostExecute(String shortURL)
MainActivity mainActivity = mainActivityWeakReference.get();
if (mainActivity != null)
mainActivity.shortURLreturn(shortURL);




Also, for that kind of action, you don't actually need a weak reference to the activity (of course, only if you don't need any methods that actually belong to the Android Activity class). If you only need your public methods that you have implemented in your MainActivity, you could make an Interface, for example:



interface ShortUrlReceiveCallback 
void onReceive(String shortURL);



and then you would just have that reference saved in the constructor of getShortURL class (note that classes start with uppercase) and later on call in onPostExecute -> shortUrlReceiveCallback.onReceive(shortURL); and have your MainActivity implement that ShortActivityCallback.



For my 2nd point, bare in mind that onPostExecute happens on a different thread (IO/background thread) than MainActivity (UiThread), if you are doing anything afterwards that's supposed to be on main thread or thread safe (variables setting should be thread safe; try using locks if you aren't for example:



class MainActivity 
private String mainShortUrl;
private Lock urlReturnLock = new ReentrantLock();
...
public void shortURLReturn(String shortUrl)
urlReturnLock.lock();
try
mainShortUrl = shortUrl;
finally
urlReturnLock.unlock();









share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 '18 at 18:41









mihanovak1024mihanovak1024

1566




1566












  • So, if I understand correctly, I should be able to avoid the null pointer by simply checking that my week reference still exists (is not null) before carrying out anything useful in onPostExecute? And the only reason the week reference would be null is it the garbage collector had destroyed it out the user has had like the process of something similar - in which case my async task would have nothing to return to anyway, so not running my return function would be fine. Have I understood that correctly? (And then the interface stuff is interesting for another time, thanks!)

    – Fat Monk
    Nov 12 '18 at 21:54











  • Yes, your understanding is correct.

    – mihanovak1024
    Nov 13 '18 at 6:50

















  • So, if I understand correctly, I should be able to avoid the null pointer by simply checking that my week reference still exists (is not null) before carrying out anything useful in onPostExecute? And the only reason the week reference would be null is it the garbage collector had destroyed it out the user has had like the process of something similar - in which case my async task would have nothing to return to anyway, so not running my return function would be fine. Have I understood that correctly? (And then the interface stuff is interesting for another time, thanks!)

    – Fat Monk
    Nov 12 '18 at 21:54











  • Yes, your understanding is correct.

    – mihanovak1024
    Nov 13 '18 at 6:50
















So, if I understand correctly, I should be able to avoid the null pointer by simply checking that my week reference still exists (is not null) before carrying out anything useful in onPostExecute? And the only reason the week reference would be null is it the garbage collector had destroyed it out the user has had like the process of something similar - in which case my async task would have nothing to return to anyway, so not running my return function would be fine. Have I understood that correctly? (And then the interface stuff is interesting for another time, thanks!)

– Fat Monk
Nov 12 '18 at 21:54





So, if I understand correctly, I should be able to avoid the null pointer by simply checking that my week reference still exists (is not null) before carrying out anything useful in onPostExecute? And the only reason the week reference would be null is it the garbage collector had destroyed it out the user has had like the process of something similar - in which case my async task would have nothing to return to anyway, so not running my return function would be fine. Have I understood that correctly? (And then the interface stuff is interesting for another time, thanks!)

– Fat Monk
Nov 12 '18 at 21:54













Yes, your understanding is correct.

– mihanovak1024
Nov 13 '18 at 6:50





Yes, your understanding is correct.

– mihanovak1024
Nov 13 '18 at 6:50



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267172%2fnull-pointer-exception-in-onpostexecute%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế