看板 AndroidDev 關於我們 聯絡資訊
開發層: (應用/框架/庫/核心) 問題: 再寫一個簡單的圖形繪製,不過模擬器那邊一直跑出The application has stopped unexpectedly.Please try again. 輸入: 預期輸出: 錯誤輸出: 錯誤訊息: 程式碼: (請多利用置底文網站) package android.com; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RectF; import android.util.AttributeSet; import android.view.View; public class myview extends View { /** Called when the activity is first created. */ public myview(Context context,AttributeSet attrs) { super(context,attrs); } protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(Color.BLACK); Paint paint=new Paint(); paint.setColor(Color.RED); canvas.drawRect(10, 10,110,110,paint); canvas.drawText("加油",10,130,paint); RectF rf1=new RectF(10,130,110,230); canvas.drawArc(rf1,0,45,true,paint); canvas.drawLine(150,10,250,110,paint); RectF rf2=new RectF(150,130,110,230); canvas.drawOval(rf2,paint); } } <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <android.com.myview android:id="@+id/vieww" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout> 我是android新手 不知道是哪裡出了問題,我也是都照著書本打上去的 請大家幫幫忙~ 感謝 參考: (書籍/網頁/...) 補充說明: -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.126.1.145 ※ 編輯: steven9374 來自: 59.126.1.145 (06/24 00:03)
chiwa:建議你先把這本書丟了 06/24 00:07
steven9374:假真,我剛買耶 06/24 00:16
jim31837:你要不要先用內建的view就好 有必要自己畫嗎? 06/24 01:40
chiwa:你用eclipse開發嗎?要不要試著自己開個新的android project 06/25 03:53
chiwa:先確定可以執行之後,再把書上的程式碼加上去 06/25 03:54
chiwa:看你PO的程式碼實在不知道要從何講起... 06/25 03:55