Always java.lang.NullPointerException with android device (Lenovo and NEC and all devices running android 2.3.x) -
always java.lang.nullpointerexception android device (lenovo , nec , devices running android 2.3.x)
i wondering why game error @ java.lang.nullpointerexception android device(lenovo , nec , devices running android 2.3.x). it's working very samsung device tested.
please see attached print screen captured crashes & anrs in play store, , game link in play store: https://play.google.com/store/apps/details?id=kids.iq.kidsiqpicturesquestionfull
here full code(color_q_easy_1.java)
package kids.iq.kidsiqpicturesquestionfull; import java.sql.date; import java.text.simpledateformat; import java.util.calendar; import java.util.random; import java.util.timer; import java.util.timertask; import android.annotation.suppresslint; import android.annotation.targetapi; import android.app.activity; import android.app.dialog; import android.content.clipdata; import android.content.intent; import android.graphics.color; import android.graphics.typeface; import android.graphics.drawable.colordrawable; import android.graphics.drawable.drawable; import android.media.mediaplayer; import android.os.build; import android.os.bundle; import android.os.countdowntimer; import android.view.dragevent; import android.view.motionevent; import android.view.view; import android.view.view.dragshadowbuilder; import android.view.view.onclicklistener; import android.view.view.ondraglistener; import android.view.view.ontouchlistener; import android.view.window; import android.view.windowmanager; import android.view.animation.animation; import android.view.animation.animationutils; import android.widget.button; import android.widget.imageview; import android.widget.relativelayout; import android.widget.textview; import com.google.ads.adrequest; import com.google.ads.adsize; import com.google.ads.adview; import com.google.analytics.tracking.android.easytracker; @suppresslint("newapi") public class color_q_easy_1 extends activity{ private adview adview; //sqlite method private sqliteadapter mysqliteadapter; private button score_board = null; dialog mydialog; private countdowntimer acounter = null; private mediaplayer ohmygod; private mediaplayer win; private imageview play_home, play_now, play_again; private textview l_title; textview timer, l_timer, l_q, q; private int screen; private relativelayout drag; private relativelayout drop; //score private textview txtscore = null; private textview txtscore_incorrect = null; private int correct = 0; private int incorrect = 0; private animation end_time, in; private textview red, blue, yellow, black, white, pink, chocolate, gray; private textview red_target, blue_target, yellow_target, black_target, white_target, gray_target, pink_target, chocolate_target; public charsequence dragdata; @targetapi(build.version_codes.honeycomb) @suppresslint({ "newapi", "simpledateformat" }) @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); getwindow().addflags(windowmanager.layoutparams.flag_keep_screen_on); random rnd = new random(); screen = (int) rnd.nextint(6)+1; switch(screen) { case 1: setcontentview(r.layout.color_q_easy_1); break; case 2: setcontentview(r.layout.color_q_easy_1_a); break; case 3: setcontentview(r.layout.color_q_easy_1_b); break; case 4: setcontentview(r.layout.color_q_easy_1_c); break; case 5: setcontentview(r.layout.color_q_easy_1_d); break; case 6: setcontentview(r.layout.color_q_easy_1_e); break; } adview = new adview(this, adsize.banner, "96ffc9a995384d59"); final adview ad = (adview) findviewbyid(r.id.adsview); ad.loadad(new adrequest()); typeface typeface = typeface.createfromasset(getassets(),"fonts/triforce.ttf"); typeface typeface1 = typeface.createfromasset(getassets(),"fonts/chiller.ttf"); end_time = animationutils.loadanimation(this, r.anim.time_up); in = animationutils.makeinanimation(color_q_easy_1.this, true); drag = (relativelayout) findviewbyid(r.id.drag); drop = (relativelayout) findviewbyid(r.id.drop); final mediaplayer time_up = mediaplayer.create(this, r.raw.time_up); ohmygod = mediaplayer.create(getbasecontext(), r.raw.ohmygod); win = mediaplayer.create(getbasecontext(), r.raw.kid_cheerring); //speakwords("well done."); final mediaplayer dragdrop = mediaplayer.create(getbasecontext(), r.raw.dragcolorboxdropintocolorname); int timeout = 300; new timer().schedule(new timertask() { @override public void run() { color_q_easy_1.this.runonuithread(new runnable() { public void run() { dragdrop.start(); } }); } }, timeout); score_board = (button) findviewbyid(r.id.sore_baord); score_board.setvisibility(view.gone); l_title = (textview) findviewbyid(r.id.l_title); l_title.settypeface(typeface); //hide play again, go home button final relativelayout gameend = (relativelayout) findviewbyid(r.id.game_ended); gameend.setvisibility(view.gone); play_home = (imageview) findviewbyid(r.id.play_home); play_home.setvisibility(view.gone); play_again = (imageview) findviewbyid(r.id.play_again); play_again.setvisibility(view.gone); play_now = (imageview) findviewbyid(r.id.play_now); play_now.setvisibility(view.gone); if(screen == 1) { //views drag red = (textview)findviewbyid(r.id.red); blue = (textview)findviewbyid(r.id.blue); black = (textview)findviewbyid(r.id.black); white = (textview)findviewbyid(r.id.white); //views drop onto blue_target = (textview)findviewbyid(r.id.blue_target); black_target = (textview)findviewbyid(r.id.black_target); white_target = (textview)findviewbyid(r.id.white_target); //set touch listeners red.setontouchlistener(new choicetouchlistener()); blue.setontouchlistener(new choicetouchlistener()); black.setontouchlistener(new choicetouchlistener()); white.setontouchlistener(new choicetouchlistener()); //set drag listeners blue_target.setondraglistener(new choicedraglistener()); black_target.setondraglistener(new choicedraglistener()); white_target.setondraglistener(new choicedraglistener()); } if(screen == 2) { //views drag red = (textview)findviewbyid(r.id.red); blue = (textview)findviewbyid(r.id.blue); black = (textview)findviewbyid(r.id.black); white = (textview)findviewbyid(r.id.white); //views drop onto red_target = (textview)findviewbyid(r.id.red_target); blue_target = (textview)findviewbyid(r.id.blue_target); black_target = (textview)findviewbyid(r.id.black_target); //set touch listeners red.setontouchlistener(new choicetouchlistener()); blue.setontouchlistener(new choicetouchlistener()); black.setontouchlistener(new choicetouchlistener()); white.setontouchlistener(new choicetouchlistener()); //set drag listeners red_target.setondraglistener(new choicedraglistener()); blue_target.setondraglistener(new choicedraglistener()); black_target.setondraglistener(new choicedraglistener()); } if(screen == 3) { //views drag red = (textview)findviewbyid(r.id.red); blue = (textview)findviewbyid(r.id.blue); yellow = (textview)findviewbyid(r.id.yellow); white = (textview)findviewbyid(r.id.white); //views drop onto blue_target = (textview)findviewbyid(r.id.blue_target); red_target = (textview)findviewbyid(r.id.red_target); yellow_target = (textview)findviewbyid(r.id.yellow_target); //set touch listeners red.setontouchlistener(new choicetouchlistener()); blue.setontouchlistener(new choicetouchlistener()); yellow.setontouchlistener(new choicetouchlistener()); white.setontouchlistener(new choicetouchlistener()); //set drag listeners blue_target.setondraglistener(new choicedraglistener()); red_target.setondraglistener(new choicedraglistener()); yellow_target.setondraglistener(new choicedraglistener()); } if(screen == 4) { red = (textview)findviewbyid(r.id.red); blue = (textview)findviewbyid(r.id.blue); yellow = (textview)findviewbyid(r.id.yellow); gray = (textview)findviewbyid(r.id.gray); //views drop onto red_target = (textview)findviewbyid(r.id.red_target); gray_target = (textview)findviewbyid(r.id.gray_target); yellow_target = (textview)findviewbyid(r.id.yellow_target); //set touch listeners red.setontouchlistener(new choicetouchlistener()); blue.setontouchlistener(new choicetouchlistener()); yellow.setontouchlistener(new choicetouchlistener()); gray.setontouchlistener(new choicetouchlistener()); //set drag listeners red_target.setondraglistener(new choicedraglistener()); gray_target.setondraglistener(new choicedraglistener()); yellow_target.setondraglistener(new choicedraglistener()); } if(screen == 5) { red = (textview)findviewbyid(r.id.red); yellow = (textview)findviewbyid(r.id.yellow); pink = (textview)findviewbyid(r.id.pink); gray = (textview)findviewbyid(r.id.gray); //views drop onto yellow_target = (textview)findviewbyid(r.id.yellow_target); gray_target = (textview)findviewbyid(r.id.gray_target); pink_target = (textview)findviewbyid(r.id.pink_target); //set touch listeners red.setontouchlistener(new choicetouchlistener()); yellow.setontouchlistener(new choicetouchlistener()); pink.setontouchlistener(new choicetouchlistener()); gray.setontouchlistener(new choicetouchlistener()); //set drag listeners yellow_target.setondraglistener(new choicedraglistener()); gray_target.setondraglistener(new choicedraglistener()); pink_target.setondraglistener(new choicedraglistener()); } if(screen == 6) { red = (textview)findviewbyid(r.id.red); pink = (textview)findviewbyid(r.id.pink); chocolate = (textview)findviewbyid(r.id.chocolate); gray = (textview)findviewbyid(r.id.gray); //views drop onto chocolate_target = (textview)findviewbyid(r.id.chocolate_target); gray_target = (textview)findviewbyid(r.id.gray_target); pink_target = (textview)findviewbyid(r.id.pink_target); //set touch listeners red.setontouchlistener(new choicetouchlistener()); pink.setontouchlistener(new choicetouchlistener()); chocolate.setontouchlistener(new choicetouchlistener()); gray.setontouchlistener(new choicetouchlistener()); //set drag listeners chocolate_target.setondraglistener(new choicedraglistener()); gray_target.setondraglistener(new choicedraglistener()); pink_target.setondraglistener(new choicedraglistener()); } textview scoretext1 = (textview)findviewbyid(r.id.scoretext1); scoretext1.settypeface(typeface1); textview scoretext2 = (textview)findviewbyid(r.id.scoretext2); scoretext2.settypeface(typeface1); txtscore = (textview) findviewbyid(r.id.score_correct); txtscore.settypeface(typeface1); txtscore_incorrect = (textview) findviewbyid(r.id.score_incorrect); txtscore_incorrect.settypeface(typeface1); //timer l_q = (textview) findviewbyid(r.id.l_q); q = (textview) findviewbyid(r.id.q); l_q.settypeface(typeface1); q.settypeface(typeface1); timer = (textview) findviewbyid(r.id.timer); timer.settypeface(typeface1); l_timer = (textview) findviewbyid(r.id.l_timer); l_timer.settypeface(typeface1); acounter = new countdowntimer(20000, 1000) { public void ontick(long millisuntilfinished) { timer.settext("" +new simpledateformat("ss").format(new date(millisuntilfinished))); if((millisuntilfinished / 1000)<=5 ) { timer.settextcolor(color.red); time_up.start(); } } public void onfinish() { //timer.settext("time's up!"); timer.setvisibility(view.gone); l_timer.setvisibility(view.gone); drag.setvisibility(view.gone); drop.setvisibility(view.gone); relativelayout gameend = (relativelayout) findviewbyid(r.id.game_ended); gameend.setvisibility(view.visible); play_home.setvisibility(view.visible); play_home.startanimation(in); play_again.setvisibility(view.visible); play_again.startanimation(in); //l_title.settextcolor(color.red); l_title.settext("a"); l_title.settextcolor(color.argb(0, 255, 0, 0)); l_title.setbackgroundresource(r.drawable.time_up); l_title.startanimation(end_time); ohmygod.start(); //insert db mysqliteadapter = new sqliteadapter(color_q_easy_1.this); mysqliteadapter.opentowrite(); // data del trov insert string level = "easy"; string failed = "fail"; int = 0; int b = 0; int level_step_a = 1; int level_step_b = 0; int percentage = 0; ////string correct = txtscore.gettext().tostring(); ////string incorrect = txtscore_incorrect.gettext().tostring(); //get date & time calendar c = calendar.getinstance(); system.out.println("current time => " + c.gettime()); simpledateformat df = new simpledateformat("dd-mmm-yyyy hh:mm"); string formatteddate = df.format(c.gettime()); mysqliteadapter.insert_color(level, a, b, formatteddate, percentage, failed, level_step_a, level_step_b); mysqliteadapter.close(); play_home.setonclicklistener(new onclicklistener() //show score board if tested picture { @override public void onclick(view v) { intent = new intent(); i.setclassname("kids.iq.kidsiqpicturesquestionfull", "kids.iq.kidsiqpicturesquestionfull.color_level_selection_q_easy"); i.addflags(intent.flag_activity_clear_top); i.addflags(intent.flag_activity_new_task); startactivity(i); } }); play_again.setonclicklistener(new onclicklistener() //show score board if tested picture { @override public void onclick(view v) { intent = new intent(); i.setclassname("kids.iq.kidsiqpicturesquestionfull", "kids.iq.kidsiqpicturesquestionfull.color_q_easy_1"); i.addflags(intent.flag_activity_clear_top); i.addflags(intent.flag_activity_new_task); startactivity(i); } }); } }; acounter.start(); } /** * choicetouchlistener handle touch events on draggable views * */ private final class choicetouchlistener implements ontouchlistener { @suppresslint("newapi") @override public boolean ontouch(view view, motionevent motionevent) { if (motionevent.getaction() == motionevent.action_down) { /* * drag details: need default behavior * - clip data set pass data part of drag * - shadow can tailored */ clipdata data = clipdata.newplaintext("", ""); dragshadowbuilder shadowbuilder = new view.dragshadowbuilder(view); //start dragging item touched view.startdrag(data, shadowbuilder, view, 0); return true; } else { return false; } } } /** * draglistener handle dragged views being dropped on drop area * - drop action have processing added not * - amending default behavior other parts of drag process * */ @suppresslint("newapi") private class choicedraglistener implements ondraglistener { @suppresslint("simpledateformat") @suppresswarnings("deprecation") @override public boolean ondrag(view v, dragevent event) { switch (event.getaction()) { case dragevent.action_drag_started: //no action necessary //speech drag object //view textspeech = (view) event.getlocalstate(); //textview drag_speech = (textview) textspeech; //speakwords(drag_speech.gettext().tostring()); break; case dragevent.action_drag_entered: //no action necessary break; case dragevent.action_drag_exited: //no action necessary break; case dragevent.action_drop: //handle dragged view being dropped on drop view view view = (view) event.getlocalstate(); //view dragged item being dropped on textview droptarget = (textview) v; //view being dragged , dropped textview dropped = (textview) view; //checking whether first character of droptarget equals first character of dropped // if(droptarget.gettext().tostring().charat(0) == dropped.gettext().tostring().charat(0)) if(droptarget.gettext().tostring() == dropped.gettext().tostring()) { view.setvisibility(view.invisible); drawable txt = (drawable) dropped.getbackground(); droptarget.setbackgrounddrawable(txt); droptarget.settext(droptarget.gettext().tostring()); droptarget.settypeface(typeface.default_bold); object tag = droptarget.gettag(); if(tag!=null) { int existingid = (integer)tag; findviewbyid(existingid).setvisibility(view.visible);; } droptarget.settag(dropped.getid()); droptarget.setondraglistener(null); if(screen == 1 || screen == 4) { if(droptarget.gettext().tostring().equals("black") || droptarget.gettext().tostring().equals("yellow")) { //speakwords("good job."); mediaplayer mp = mediaplayer.create(getbasecontext(), r.raw.yousosmart); mp.start(); } if(droptarget.gettext().tostring().equals("blue") || droptarget.gettext().tostring().equals("gray")) { //speakwords("good job."); mediaplayer mp = mediaplayer.create(getbasecontext(), r.raw.welldone); mp.start(); } if(droptarget.gettext().tostring().equals("white") || droptarget.gettext().tostring().equals("red")) { //speakwords("well done."); mediaplayer mp = mediaplayer.create(getbasecontext(), r.raw.yousogood); mp.start(); } } if(screen == 2 || screen == 5) { if(droptarget.gettext().tostring().equals("black") || droptarget.gettext().tostring().equals("yellow")) { //speakwords("good job."); mediaplayer mp = mediaplayer.create(getbasecontext(), r.raw.yousosmart); mp.start(); } if(droptarget.gettext().tostring().equals("blue") || droptarget.gettext().tostring().equals("gray")) { //speakwords("good job."); mediaplayer mp = mediaplayer.create(getbasecontext(), r.raw.welldone); mp.start(); } if(droptarget.gettext().tostring().equals("red") || droptarget.gettext().tostring().equals("pink")) { //speakwords("well done."); mediaplayer mp = mediaplayer.create(getbasecontext(), r.raw.yousogood); mp.start(); } } if(screen == 3 || screen == 6) { if(droptarget.gettext().tostring().equals("yellow") || droptarget.gettext().tostring().equals("chocolate")) { //speakwords("good job."); mediaplayer mp = mediaplayer.create(getbasecontext(), r.raw.yousosmart); mp.start(); } if(droptarget.gettext().tostring().equals("blue") || droptarget.gettext().tostring().equals("gray")) { //speakwords("good job."); mediaplayer mp = mediaplayer.create(getbasecontext(), r.raw.welldone); mp.start(); } if(droptarget.gettext().tostring().equals("red") || droptarget.gettext().tostring().equals("pink")) { //speakwords("well done."); mediaplayer mp = mediaplayer.create(getbasecontext(), r.raw.yousogood); mp.start(); } }
view.setondraglistener added in api 11 (honeycomb) , not available on android 2.3.x devices, hence why need suppresslint("newapi")
annotations (which trying warn apis expecting not exist on devices, causing runtime errors when attempt call them).
Comments
Post a Comment