{"id":7215,"date":"2014-05-28T02:20:25","date_gmt":"2014-05-28T02:20:25","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/05\/28\/problem-about-android-canvas-collection-of-common-programming-errors\/"},"modified":"2014-05-28T02:20:25","modified_gmt":"2014-05-28T02:20:25","slug":"problem-about-android-canvas-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/05\/28\/problem-about-android-canvas-collection-of-common-programming-errors\/","title":{"rendered":"problem about android-canvas-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/y7nWE.jpg?s=32&amp;g=1\" \/><br \/>\nUmar Farooq<br \/>\nandroid android-canvas<br \/>\nI am new to android, I am trying to make game in android. In that game I have to draw canvas, I followed a tutorial to learn &#8220;How to draw canvas in android&#8221;. In that tutorial he is using two classes named as GFX and Main, he is not showing any XML file, so I am using its default XML which is populated by eclipse editor automatically.I have followed the tutorial, but when I try to run that application on my device a message appears on my device screen, Unfortunately,Seven has stopped. &#8220;Seven&#8221; is<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6c7be55a7a5e28c374ba30054a9ecb82?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ntheblitz<br \/>\nandroid android-canvas<br \/>\nI am getting an UnsupportedOperationException when using Canvas clipPath.This is happening on an HTC Sensation XE (4.0.3). It works perfectly on other 4.0.3 devices.This is the code:@Override protected void dispatchDraw(Canvas canvas) {canvas.save();canvas.clipPath(this._mClip);super.dispatchDraw(canvas);canvas.restore(); }It fails on the &#8220;clipPath&#8221; with the following stack:11-06 12:05:53.650: E\/AndroidRuntime(25021): FATAL EXCEPTION: main11-06 12:05:53.650: E\/AndroidRuntime(25021): java.lang.Un<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0263c4c9036955a2d9768bf6a35a8345?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nKara<br \/>\njava android multithreading android-canvas surfaceview<br \/>\nI&#8217;ve been struggling with this exception and I&#8217;ve looked around but there&#8217;s nothing to help me.Here&#8217;s the codepackage com.example.surfacetest;import android.app.Activity; import android.content.Context; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.MotionEvent; import android.view.Surface.OutOfResourcesException; import android.view.SurfaceHolder; import android.view.Sur<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0263c4c9036955a2d9768bf6a35a8345?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nKara<br \/>\nandroid multithreading segmentation-fault android-canvas surfaceview<br \/>\nI&#8217;m making a grid + tile activity where tiles need to move across the grid. The grid (and tiles) are being drawn on a surfaceView in a separate thread to the UI (UI deals with touch events and pushes them onto a queue for the grid to process). This is all fine. I have a toolbar from which I can drag tiles. The toolbar is a View which has been added to the relative layout (and runs on the UI thread). No matter how many times i use synchronize or try to safeguard the canvas from being written to a<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/681329083876f6c69048c5fa46c4936a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMikko P.<br \/>\nandroid android-canvas live-wallpaper runnable surfaceholder<br \/>\nI&#8217;m building a live wallpaper, it has a bitmap with fullHD resolution which is scaled down to the size of the users phone screen. It works perfectly on Android 2.2 and 2.3 but crashes on 4.0.EDIT :I narrowed the problem down a little bit using try\/catch and found out it starts from my run() method. With that MacGyver fix it runs about 20 seconds flooding the following error message and then crashes:05-31 20:01:22.590: E\/SurfaceTextureClient(1475): dequeueBuffer failed (No such device) 05-31 20:0<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7f05e00a95f654b429986cab66ef4414?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nChiru<br \/>\nandroid android-canvas android-custom-view<br \/>\ni have prepared paint application,my application contains one custom view for paint.when we draw any thing in custom view just collect the drawn pixels and store in array list,first it&#8217;s working fine(but it&#8217;s taking lot of time) and second time &#8221; Activity MyAlphabets(in application MyAlphabets)is not responding(force close and wait)&#8221;.My code is,public void onDraw(Canvas canvas) {if (myDrawBitmap == null) {myDrawBitmap = Bitmap.createBitmap(canvas.getWidth(),canvas.getHeight(), Bitmap.Config.ARGB<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0263c4c9036955a2d9768bf6a35a8345?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nKara<br \/>\njava android bitmap android-canvas ondraw<br \/>\nThe goal is simply to draw a bitmap and over the top of it draw shapes that ERASE the underlying area of the bitmap.I have created simple proof of concept code to try and understand how exactly I should go about this. In the various threads here I have found numerous hints about using:android.graphics.PorterDuff.Mode.CLEARThe code below simply creates a screen with a blue background and adds a custom view. This view draws on its canvas a pink background, the bitmap image (with a slight border to<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/c79b0e6f75319b0ba1d475797df131ae?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSimon Sarris<br \/>\nandroid opengl-es overlay android-canvas<br \/>\nI&#8217;m attempting to add an overlay to an Android opengl ES application, and am currently specifying an ImageView and working off code from SurfaceViewOverlay API Demo, effectively merging two applications I wrote, one that was canvas based and one with opengl ES.Due to merging two projects there was a large amount of copy paste involved and which lead to me accidentally using a null surface holder. Surprisingly this worked but threw a large number of warnings. Changing it to the surface holder of<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/52f18d50fc841a7ad833481b85a0e79f?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nOptimus<br \/>\nandroid android-canvas android-imageview<br \/>\nI want to add some text on top of an image. I read the image from the sd card and set it to a Bitmap variable.Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());Then I added it to a canvas. The code I used is given below,Canvas c = new Canvas(myBitmap);But when I added this line, the app crashed at that point. Why is it and how can i solve this ??Note : Above mention code lines are inside onActivityResult method.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/710a392a974ed826ed96407788e0df5e?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nLoktar<br \/>\nandroid exception android-canvas<br \/>\nI am using the image crop library from here https:\/\/github.com\/lvillani\/android-cropimage in my project to crop images stored on device. However, certain users are reporting crashes with the following stack tracejava.lang.UnsupportedOperationException at android.view.GLES20Canvas.clipPath(GLES20Canvas.java:413) at com.android.camera.HighlightView.draw(HighlightView.java:101) at com.android.camera.CropImageView.onDraw(CropImage.java:783) at android.view.View.draw(View.java:11006) at android.view.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/dd9a700bdfbbe624b685ad25781e5efd?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nApoz<br \/>\nandroid google-maps android-canvas google-maps-android-api-2<br \/>\nI&#8217;m displaying a GroundOverlay on my map whose image is made with a canvas on which I drew an arc, but I&#8217;m running into a few problems : first of all, the applications crashes after a little while (it&#8217;s giving me a java.lang.OutOfMemoryError), and it&#8217;s not showing the overlay. I have tried putting on a white background in the overlay&#8217;s picture and it does display it, so I guess the problem comes from the arc, but I can&#8217;t tell what I did wrong. Anyone has any idea ?Projection projection = map.get<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/85316821264d9bb9caa8041ae55de348?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJeroen van den Broek<br \/>\njava android android-canvas android-4.3<br \/>\nBefore you spend more time reading this than necessary: I will be answering this question myself. I spent a full day debugging this and thought I should share.I am the developer for an application that is basically a sort of turn-by-turn navigation on golf courses. As such, I have images that need to be rotated to make the image north-oriented. This obviously requires some matrix transformations.After Android 4.3 got pushed to the HTC One, I got a few complaints that the app was simply closing w<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6557331562a538603a77a6912abd478f?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAndreaF<br \/>\nandroid android-canvas<br \/>\nI&#8217;m trying a simple CustomView with canvas. This custom view simply change the position of an icon picture on the screen randomly when is invoked updatePosition(), and in my intention should move the image on drag, scale on pinch&#8230; and when I touch a position in the screen should appear in the clicked position.My try is the follow public class CustomView extends View {Bitmap mBmp;Random mRnd;Paint mPaint;private static final int INVALID_POINTER_ID = -1;private float mPosX;private float mPosY;p<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/52b3273d3d9b0b40675ddc359535c859?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\niappmaker<br \/>\nandroid android-canvas android-image<br \/>\nI am testing the app on my phone (size 720&#215;1280). The app runs fine when I use the sample size of 2. When I tried to use the sample size of 1 the app crashes in the line where I draw the image (code mentioned below). Please point me where my code need correction.canvas.drawBitmap(backgoundImage, 0, 0 , null); Codepublic Bitmap getAssetImage(Context context, String filename) throws IOException {AssetManager assets = getApplicationContext().getResources().getAssets();InputStream buffer = null;t<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/8865a569f94d4a96eb1f0d35ab53ce0b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nLatcie<br \/>\nandroid android-canvas surfaceview<br \/>\nI have a simple surfaceView and a thread as below.I&#8217;m trying to start simple and just paint the background of surfaceView a certain color.package com.example.surfviewtest;import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.util.AttributeSet; import android.view.SurfaceHolder; import android.view.SurfaceView;public class SView extends SurfaceView implements SurfaceHolder.Callback<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d3fdb1409cb2cffc7299b85cc96c1a09?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAnkuj<br \/>\nandroid android-canvas face-detection<br \/>\nI have this codepublic void DetectFacesInImage(View view){BitmapFactory.Options bitmapFactoryOptions=new BitmapFactory.Options();bitmapFactoryOptions.inPreferredConfig= Bitmap.Config.RGB_565;\/\/int resID = getResources().getIdentifier(picturePath , &#8220;drawable&#8221;, getPackageName());myBitmap=BitmapFactory.decodeFile(picturePath,bitmapFactoryOptions);int width=myBitmap.getWidth();int height=myBitmap.getHeight();detectedFaces=new FaceDetector.Face[number_of_faces];FaceDetector faceDetector=new FaceDetec<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/a35d1bc2b8dedd89fcda557e8a022c98?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSeraphim<br \/>\nandroid crash paint android-canvas sigsegv<br \/>\nI&#8217;m using a low cost tablet with Android 4.0.3. HEre the log:06-11 23:36:04.653: D\/SynopticElement(1583): Size changed to 200&#215;200 06-11 23:36:04.693: D\/dalvikvm(1583): GC_FOR_ALLOC freed 62K, 12% free 7275K\/8199K, paused 33ms 06-11 23:36:04.713: D\/SynopticElement(1583): Size changed to 190&#215;190 06-11 23:36:04.733: D\/dalvikvm(1583): GC_FOR_ALLOC freed 9K, 12% free 7583K\/8583K, paused 22ms 06-11 23:36:04.743: A\/libc(1583): Fatal signal 11 (SIGSEGV) at 0xc52c9d4c (code=1)Debugging my code:canvas.sca<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/52b3273d3d9b0b40675ddc359535c859?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\niappmaker<br \/>\nandroid android-canvas android-image<br \/>\nI am testing my App in the Emulator. Emulator Device Size &#8211; 480 x 854 Image size &#8211; 1280 x 720 Sample size = 1 (This is from the process explained in the Android reference &#8211; http:\/\/developer.android.com\/training\/displaying-bitmaps\/load-bitmap.html)When I trigger this activity the App goes fine, When I traverse to next activity and come back, the App crashes with OOM. I have followed the process explained in the android manual for loading the bitmap efficiently, but still it fails in the linebackg<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/ba318b431c968c4883f4f365d989abea?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\njaybee<br \/>\nandroid android-camera android-canvas android-orientation<br \/>\nI am using a SurfaceView to draw on top of the camera preview, adapting code from this tutorial. The app works at first then crashes on orientation change, sometimes on the first change, sometimes after changing two or three times. I&#8217;ve seen quite a few similar questions but none has a solution (for my case). This is the exception:05-09 22:14:48.384: D\/libEGL(829): loaded \/vendor\/lib\/egl\/libEGL_POWERVR_SGX540_120.so 05-09 22:14:48.400: D\/libEGL(829): loaded \/vendor\/lib\/egl\/libGLESv1_CM_POWERVR_S<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/c79b0e6f75319b0ba1d475797df131ae?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSimon Sarris<br \/>\nandroid bitmap edittext android-canvas<br \/>\nI have an editText, and I want what is being typed in it gets drawn on the canvas which has my resource called &#8220;ger&#8221;. I made a simple code, but In don&#8217;t get it to work. IDK what is the problem, when I run it, it stops unexpectedlythis is my class codepublic class StartActivity extends Activity {\/** Called when the activity is first created. *\/static Bitmap bmp; static EditText et; static ImageView iv;@Override public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);se<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/52b3273d3d9b0b40675ddc359535c859?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\niappmaker<br \/>\nandroid android-canvas android-mediaplayer<br \/>\nI have 2 activities. Main Activity -&gt; A and child Activity -&gt; B. Activity A uses the canvas to place some images at desired position and also it plays some background music. Activity B triggered from A where it uses a media player and viewFlipper. For every flip I used to play a flip sound.Issue : Whenever I press back while the flip is in progress, I get the following error in main Activity A. Kindly Advice. Thanks in AdvanceLogCat04-20 10:29:06.779: E\/SurfaceTextureClient(5938): dequeueBuffer<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/e9de0f92d975dcdeb9df7c21113bfc37?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nElyas369<br \/>\nandroid android-layout android-canvas android-tablelayout<br \/>\nI am trying to implement a HUD display to my cutsom keyboard. The HUD will contain pairs of key\/value. I need to programatically create a TableLayout and draw it on my canvas. In order to do this, I am overriding the keyboardview onDraw() method:@Override public void onDraw(Canvas canvas) { \/\/ In the custom MyKeyboardView classMyHUD hud = new MyHUD(getContext());super.onDraw(canvas);hud.tl.draw(canvas); \/\/tl being the TableLayout to draw }MyHUD class:public class MyHUD {public TableLayout tl<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fb72ce419fce023e91f16ae08567f0ca?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser1844130<br \/>\nandroid android-canvas<br \/>\nHere in this timer code runOnUiThread( new Runnable) is undefined in a class which extends view. Is this possible to use this code in class which extends View. Timer timer = new Timer(); timer.schedule(new TimerTask() { public void run() {runOnUiThread(new Runnable() {@Overridepublic void run() {view.invalidate;}});} }, 40);<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/710a392a974ed826ed96407788e0df5e?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nLoktar<br \/>\njava android alertdialog android-canvas looper<br \/>\nHere&#8217;s a screenshot of my AlertDialog&#8217;s unresponsive state:In the background, the green tile, the red ball inside a the black-and-white target, all three of the bitmaps are continuously rendered on a rendering thread that locks\/unlocks the background Canvas on my phone. This unresponsive action always execute when I press the OK button, regardless of what text I put into the EditText.Here&#8217;s the code:PlayActivity class:package nttu.edu.activities;import nttu.edu.graphics.RenderView; import nttu.e<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n<p>I discovery a place to host code\u3001demo\u3001 blog and websites.<br \/>\nSite access is fast but not money<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.m5zn.com\/newuploads\/2014\/01\/30\/jpg\/e7da807964b1fff.jpg\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Umar Farooq android android-canvas I am new to android, I am trying to make game in android. In that game I have to draw canvas, I followed a tutorial to learn &#8220;How to draw canvas in android&#8221;. In that tutorial he is using two classes named as GFX and Main, he is not showing any [&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-7215","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7215","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=7215"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7215\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}