Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi. Why this program go to force close ?
Java
SurfaceView srf;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Init();

    srf = (SurfaceView)findViewById(R.id.surfaceView1);
    Canvas cv = new Canvas();
    Paint pn = new Paint();
    pn.setAntiAlias(true);
    pn.setStrokeWidth(6f);
    pn.setColor(Color.BLUE);
    pn.setStyle(Paint.Style.STROKE);
    pn.setStrokeJoin(Paint.Join.ROUND);
    cv.drawLine(2, 2, 100, 100,pn);
    srf.draw(cv);

}
Posted
Updated 3-Sep-13 2:50am
v2

1 solution

When displayed, the framework will call draw on SurfaceView passing it's own Canvas and that's what you'll see, not what you draw on a Canvas in the Activitys onCreate method.

Create a new class that inherits from SurfaceView and override it's onDraw and you can see this for yourself (note that you should almost never override draw).

Hope this helps,
Fredrik
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900