androidアプリ開発にてdrawBitmapMeshで画像の変形をしようと思ったのですがエラーがでました。
どこを直せばよいのでしょうか?
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{パッケージ名/パッケージ名.MainActivity}: java.lang.InstantiationException: java.lang.Class<パッケージ名/パッケージ名.MainActivity> has no zero argument constructor at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.InstantiationException: java.lang.Class<com.example.nakayamakanta.myapplication2.MainActivity> has no zero argument constructor at java.lang.Class.newInstance(Native Method) at android.app.Instrumentation.newActivity(Instrumentation.java:1067) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
コードになります。
java
1import android.content.Context; 2import android.graphics.Bitmap; 3import android.graphics.BitmapFactory; 4import android.graphics.Canvas; 5import android.graphics.Color; 6import android.graphics.Paint; 7import android.util.AttributeSet; 8import android.view.MotionEvent; 9import android.view.View; 10 11 12public class MainActivity extends View implements View.OnTouchListener{ 13 14 private final int MESH_WIDTH = 20; 15 private final int MESH_HEIGHT = 20; 16 private final int MESH_SIZE = (MESH_WIDTH+1)*(MESH_HEIGHT+1)*2; 17 18 private Bitmap mBmp; 19 private float[] mVents; 20 private Paint mPaint; 21 22 23 public MainActivity(Context context, AttributeSet attrs) { 24 super(context, attrs); 25 mBmp = BitmapFactory.decodeResource(getResources(), R.drawable.red); 26 setInitialMesh(); 27 setOnTouchListener(this); 28 mPaint = new Paint(); 29 mPaint.setStrokeWidth(2); 30 mPaint.setColor(Color.WHITE); 31 } 32 33 34 public void setInitialMesh() { 35 mVents = new float[MESH_SIZE]; 36 37 for (int i=0;i<=MESH_HEIGHT;i++) { 38 for (int j=0;j<=MESH_WIDTH;j++) { 39 int pos = i * (MESH_WIDTH + 1) + j; 40 mVents[2 * pos] = j * mBmp.getWidth()/MESH_WIDTH; 41 mVents[2 * pos + 1] = i * mBmp.getHeight()/MESH_HEIGHT; 42 } 43 } 44 } 45 46 @Override 47 public boolean onTouch(View v, MotionEvent event) { 48 if (event.getAction()==MotionEvent.ACTION_MOVE) { 49 stepNearerTouchPoint(event.getX(), event.getY()); 50 invalidate(); 51 } 52 return true; 53 } 54 55 private void stepNearerTouchPoint(float x, float y) { 56 //メッシュの外周は固定したままにする 57 for (int i=1;i<MESH_HEIGHT;i++) { 58 for (int j=1;j<MESH_WIDTH;j++) { 59 int pos = i * (MESH_WIDTH + 1) + j; 60 float dist = (float)Math.sqrt((mVents[2 * pos] - x) * (mVents[2 * pos] - x) + (mVents[2 * pos + 1] - y) * (mVents[2 * pos + 1] - y)); 61 mVents[2 * pos] += (x - mVents[2 * pos]) / dist; 62 mVents[2 * pos + 1] += (y - mVents[2 * pos + 1]) / dist; 63 } 64 } 65 } 66 67 @Override 68 protected void onDraw(Canvas canvas) { 69 canvas.drawBitmapMesh(mBmp, MESH_WIDTH, MESH_HEIGHT-1, mVents, (MESH_WIDTH+1)*2, null, 0, null); 70 } 71}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/12/26 09:52
2016/12/26 10:06