{"id":1863,"date":"2022-08-30T15:20:04","date_gmt":"2022-08-30T15:20:04","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/12\/02\/unraveling-a-user-submitted-stacktrace-mediaplayer-null-pointer-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:20:04","modified_gmt":"2022-08-30T15:20:04","slug":"unraveling-a-user-submitted-stacktrace-mediaplayer-null-pointer-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/unraveling-a-user-submitted-stacktrace-mediaplayer-null-pointer-collection-of-common-programming-errors\/","title":{"rendered":"Unraveling a user submitted stacktrace, MediaPlayer null pointer?-Collection of common programming errors"},"content":{"rendered":"<p>I have my first application up on the market and I have been liking the statistics so far. I got my first bug report which gave me the stack trace and a small description. I used the retrace tool and the trace looks like this:<\/p>\n<pre><code>java.lang.NullPointerException\nat app.koreanstudy.Alphabet.java.lang.String getNext()(Unknown Source)\n                            void play(android.content.Context)\nat app.koreanstudy.AlphabetActivity.void onClick(android.view.View)(Unknown Source)\n<\/code><\/pre>\n<p>I can&#8217;t quite tell where this NullPointerEx is coming from.. I guess the play() method due to the user&#8217;s description of the problem.<\/p>\n<p>This is my play method:<\/p>\n<pre><code>    public void play(Context context){\n    if (soundPlayer != null){\n        soundPlayer.release();\n    }\n\n    int rId = 0;\n\n    switch(aIndex){\n        case 0: rId = R.raw.c0; break;\n        case 1: rId = R.raw.c1; break;\n        case 2: rId = R.raw.c2; break;\n        case 3: rId = R.raw.c3; break;\n        case 4: rId = R.raw.c4; break;\n        case 5: rId = R.raw.c5; break;\n        case 6: rId = R.raw.c6; break;\n        case 7: rId = R.raw.c7; break;\n        case 8: rId = R.raw.c8; break;\n        case 9: rId = R.raw.c9; break;\n        case 10: rId = R.raw.c10; break;\n        case 11: rId = R.raw.c11; break;\n        case 12: rId = R.raw.c12; break;\n        case 13: rId = R.raw.c13; break;\n        case 14: rId = R.raw.v14; break;\n        case 15: rId = R.raw.v15; break;\n        case 16: rId = R.raw.v16; break;\n        case 17: rId = R.raw.v17; break;\n        case 18: rId = R.raw.v18; break;\n        case 19: rId = R.raw.v19; break;\n        case 20: rId = R.raw.v20; break;\n        case 21: rId = R.raw.v21; break;\n        case 22: rId = R.raw.v22; break;\n        case 23: rId = R.raw.v23; break;\n\n        default: rId = R.raw.error; break;\n    }\n\n    soundPlayer = MediaPlayer.create(context, rId);\n    soundPlayer.start();\n}\n}\n<\/code><\/pre>\n<p>If the error is indeed here I guess it&#8217;s from not checking the MediaPlayer returns NULL?<\/p>\n<pre><code>    soundPlayer = MediaPlayer.create(context, rId);\n    \/\/ should check if it's null here?\n    soundPlayer.start();\n<\/code><\/pre>\n<p>However, I am unsure why this would be a problem? The user is on a Verizon Droidx2 if that helps.<\/p>\n<p>For completion (and the null ptr says java.lang..)<\/p>\n<pre><code>    public String getNext(){    \n    \/*\n     * If the current index is at the end, don't increment aIndex. Instead,\n     * return the final character of the alphabet. \n     *\/\n    return aIndex == 23 ? aList.get(aIndex) : aList.get(++aIndex);\n}\n<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-12-02 21:02:19. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have my first application up on the market and I have been liking the statistics so far. I got my first bug report which gave me the stack trace and a small description. I used the retrace tool and the trace looks like this: java.lang.NullPointerException at app.koreanstudy.Alphabet.java.lang.String getNext()(Unknown Source) void play(android.content.Context) at app.koreanstudy.AlphabetActivity.void onClick(android.view.View)(Unknown [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1863","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1863"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1863\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}