I am very new to Java and android. my 1st app using canvas and paint. for some reason I get a force close whenever I try using the drawText method.. Please help.
I am basically trying to display text in a specific x,y coordinate. which will need updates throughout game play, my code:
public class MyGame extends Main {
TextView timeDisplay;
public String clock;
int x_pos = 10;
int y_pos = 100;
int radius = 20;
float x = 10;
float y = 20;
android.graphics.Paint p;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// setup Drawing view
Bitmap b = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
c.drawText("test", 30, 0,x,y, p); <-- if I comment this out, no force close...
Your help is appreciated.
initialize p as follow
and then use