android studioで簡単なゲームを作っているのですが、インテントでデータ受け渡してfinish()を呼び出すボタンを作った途端に実行してもstoppedがでて動かなくなりました。どこが間違っているのかもわかりません。
###MainActivity.java
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { Log.d("debug", "debug1"); super.onCreate(savedInstanceState); Intent intent = new Intent(this, wallCreate.class); int requestCode = 1001; startActivity(intent); Log.d("debug", "debug1"); Intent intent_P2 = new Intent(this, wallCreate.class); int requestCode_P2 = 1002; startActivityForResult( intent_P2, requestCode_P2 ); setContentView(R.layout.activity_main); } public void onActivityResult( int requestCode, int resultCode, Intent intent ) { // startActivityForResult()の際に指定した識別コードとの比較 if( requestCode == 1001 ){ // 返却結果ステータスとの比較 if( resultCode == Activity.RESULT_OK ){ // 返却されてきたintentから値を取り出す ArrayList<Line> lines_yoko = intent.getParcelableExtra("lines_yoko"); ArrayList<Line> lines_tate = intent.getParcelableExtra("lines_tate"); } } if( requestCode == 1002 ){ // 返却結果ステータスとの比較 if( resultCode == Activity.RESULT_OK ){ // 返却されてきたintentから値を取り出す ArrayList<Line> lines_yoko_P2 = intent.getParcelableExtra("lines_yoko"); ArrayList<Line> lines_tate_P2 = intent.getParcelableExtra("lines_tate"); } } } }
###wallCreate.java
public class wallCreate extends Activity { private wallCreate_view wallCreate_view; public void onCreate(Bundle savedInstanceState) { Log.d("debug", "debug1"); super.onCreate(savedInstanceState); setContentView(R.layout.mode_create); this.wallCreate_view = (wallCreate_view) findViewById(R.id.wallCreate_view); findViewById(R.id.delete_button).setOnClickListener(deleteDrawing); findViewById(R.id.finish_button).setOnClickListener(finish); } View.OnClickListener deleteDrawing = new View.OnClickListener() { @Override public void onClick(View view) { wallCreate_view.delete(); } }; View.OnClickListener finish = new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(); // intentへ添え字付で値を保持させる intent.putExtra("lines_yoko",wallCreate_view.getLine_yoko()); intent.putExtra("lines_tate",wallCreate_view.getLine_tate()); // 返却したい結果ステータスをセットする setResult(Activity.RESULT_OK, intent); finish(); } }; }
###mode_create.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" > <view android:id="@+id/wallCreate_view" android:layout_width="wrap_content" android:layout_height="wrap_content" class="com.example.sonekenichiro.game1.wallCreate_view" android:layout_above="@+id/delete_button" > </view> <Button android:id="@+id/finish_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="FINISH" android:layout_alignParentBottom="true" android:layout_alignParentRight="true"/> <Button android:id="@+id/delete_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerInParent="true" android:text="delete" /> </RelativeLayout>
###wallCreate_view.java
public class wallCreate_view extends View { ArrayList<Line> lines_yoko = new ArrayList<Line>(); ArrayList<Line> lines_tate = new ArrayList<Line>(); Line line[][] = new Line[6][5]; Line_tate line_tate[][] = new Line_tate[5][6]; private int w_state=0; public wallCreate_view(Context context,AttributeSet attrs) { super(context,attrs); } public void onDraw(Canvas c) { Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.BLACK); paint.setStrokeWidth(16); paint.setStyle(Paint.Style.STROKE); c.drawRect(16, 200, 1068, 1500, paint); if (w_state == 0) { for (int i = 0; i < 6; i++) { for (int j = 0; j < 5; j++) { line[i][j] = new Line(24 + i * 173, 416 + j * 216); lines_yoko.add(line[i][j]); } } for (int i = 0; i < 5; i++) { for (int j = 0; j < 6; j++) { line_tate[i][j] = new Line_tate(197 + i * 173, 208 + j * 216); lines_tate.add(line[i][j]); } } w_state++; } if(w_state ==1){ for (int i = 0; i < 6; i++) { for (int j = 0; j < 5; j++) { if(line[i][j].checkState()==0){ line[i][j].onDraw(c); }else{ line[i][j].drawOnTouch(c); } } } for (int i = 0; i < 5; i++) { for (int j = 0; j < 6; j++) { if(line_tate[i][j].checkState()==0){ line_tate[i][j].onDraw(c); } if(line_tate[i][j].checkState()==1){ line_tate[i][j].drawOnTouch(c); } } } } } public boolean onTouchEvent(MotionEvent event) { if(event.getAction()==MotionEvent.ACTION_DOWN){ Log.d("TOUCH","touch1"); for (int i = 0; i < 6; i++) { for (int j = 0; j< 5; j++) { line[i][j].checkTouch(event.getX(), event.getY()); } } for (int i = 0; i < 5; i++) { for (int j = 0; j < 6; j++) { line_tate[i][j].checkTouch(event.getX(),event.getY()); } } invalidate(); return true; } return true; } public ArrayList<Line> getLine_yoko(){ return lines_yoko; } public ArrayList<Line> getLine_tate(){ return lines_tate; } public void delete(){ for (int i = 0; i < 6; i++) { for (int j = 0; j< 5; j++) { line[i][j].stateChangeToN(); } } for (int i = 0; i < 5; i++) { for (int j = 0; j < 6; j++) { line_tate[i][j].stateChangeToN(); } } invalidate(); } }
###エラーコード
09-13 17:21:43.422 1526-1535/android.process.acore E/StrictMode﹕ A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:184)
at android.os.ParcelFileDescriptor.<init>(ParcelFileDescriptor.java:180)
at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:916)
at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:906)
at android.app.IBackupAgent$Stub.onTransact(IBackupAgent.java:57)
at android.os.Binder.execTransact(Binder.java:446)
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。