Using Toast with AndEngine? -


i'm new andengine. it's , powerful engine, however, there has been couple of frustrations such not being able draw circles (btw, there ways that?!)

but concern have board game, , want show toast message. put command after scene.attachchild() inside public scene oncreatescene(), when trying run game, ruins

public class mainactivity extends simplebasegameactivity {     private static int camera_width ;     private static int camera_height;     //  private int numrows= 8;     //  private int numcolumns= 10;      private font mfont;     private itexture mfacetexture;     private itextureregion mfacetextureregion;      private itexture boardtexture;     private itextureregion boardtextureregion;      @override     public engineoptions oncreateengineoptions() {         displaymetrics metrics = getresources().getdisplaymetrics();         camera_width = metrics.widthpixels;         camera_height = metrics.heightpixels;          final camera camera = new camera(0, 0, camera_width, camera_height);         return new engineoptions(true, screenorientation.portrait_sensor, new ratioresolutionpolicy(camera_width, camera_height), camera);     }      @override     public void oncreateresources() throws ioexception {         this.mfont = fontfactory.create(this.getfontmanager(), this.gettexturemanager(), 256, 256, typeface.create(typeface.default, typeface.bold), 16);         this.mfont.load();          this.boardtexture = new assetbitmaptexture(this.gettexturemanager(), this.getassets(), "board.png");         this.boardtextureregion = textureregionfactory.extractfromtexture(this.boardtexture);         this.boardtexture.load();          this.mfacetexture = new assetbitmaptexture(this.gettexturemanager(), this.getassets(), "graduationicon.png");         this.mfacetextureregion = textureregionfactory.extractfromtexture(this.mfacetexture);         this.mfacetexture.load();       }      @override     public scene oncreatescene() {         this.mengine.registerupdatehandler(new fpslogger());         final scene scene = new scene();         scene.getbackground().setcolor(color.black);          /* create rectangles. */         final sprite board = new sprite(camera_width/2, camera_height/2, this.boardtextureregion, this.getvertexbufferobjectmanager());         board.setscale(.5f);           /* create sprite , add scene. */         final sprite face = new sprite(camera_width/2, camera_height/2, this.mfacetextureregion, this.getvertexbufferobjectmanager());          /* draw line */         float x1=camera_width/2;         float y1=camera_height/2;         float x2=camera_width *7/8;         float y2=camera_height /2;         random random = new random(123456789);         float linewidth=2;          final line line = new line(x1+20, y1, x2, y2, linewidth, this.getvertexbufferobjectmanager());         line.setcolor(random.nextfloat(), random.nextfloat(), random.nextfloat());          /* draw text   */         final text text = new text(x2, y2 , this.mfont, "week when graduated\n (you 50!)", new textoptions(horizontalalign.center), this.getvertexbufferobjectmanager());          /*add graphics scene  */         scene.attachchild(board);         scene.attachchild(face);         scene.attachchild(line);         scene.attachchild(text);         toast.maketext(getapplicationcontext(), "msg msg", toast.length_short).show();         return scene;      }  } 

what wrong it? :?

and here logcat error

07-14 10:14:22.301: e/androidruntime(21709): fatal exception: thread-3085 07-14 10:14:22.301: e/androidruntime(21709): process: com.example.hello, pid: 21709 07-14 10:14:22.301: e/androidruntime(21709): java.lang.runtimeexception: can't create handler inside thread has not called looper.prepare() 07-14 10:14:22.301: e/androidruntime(21709):    @ android.os.handler.<init>(handler.java:200) 07-14 10:14:22.301: e/androidruntime(21709):    @ android.os.handler.<init>(handler.java:114) 07-14 10:14:22.301: e/androidruntime(21709):    @ android.widget.toast$tn.<init>(toast.java:344) 07-14 10:14:22.301: e/androidruntime(21709):    @ android.widget.toast.<init>(toast.java:100) 07-14 10:14:22.301: e/androidruntime(21709):    @ android.widget.toast.maketext(toast.java:258) 07-14 10:14:22.301: e/androidruntime(21709):    @ com.example.hello.mainactivity$1.run(mainactivity.java:143) 07-14 10:14:22.301: e/androidruntime(21709):    @ java.lang.thread.run(thread.java:818) 

try running toast in ui thread

activity.runonuithread(new runnable(){     @override     public void run(){         toast.maketext(activity, "hello", toast.length_long).show();    } } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -