내가 만드는 중일 때 Tic-Tac-Toe 앱에서 방향 변경을 처리 할 대체 화면보기를 설정했습니다. 내 주요 자바 파일에오리엔테이션 변경으로 인해 앱이 손상 될 수 있습니다.
내에서 onCreate() 메소드는 다음과 같습니다
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putCharArray("board", mGame.getBoardState());
outState.putBoolean("mGameOver", mGameOver);
outState.putInt("mHumanWins", Integer.valueOf(mHumanWins));
outState.putInt("mComputerWins", Integer.valueOf(mComputerWins));
outState.putInt("mTies", Integer.valueOf(mTies));
outState.putCharSequence("info", mInfoTextView.getText());
outState.putChar("mTurn", mTurn);
outState.putChar("mFirstMove", mFirstMove);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
mGame.setBoardState(savedInstanceState.getCharArray("board"));
mGameOver = savedInstanceState.getBoolean("mGameOver");
mInfoTextView.setText(savedInstanceState.getCharSequence("info"));
mHumanWins = savedInstanceState.getInt("mHumanWins");
mComputerWins = savedInstanceState.getInt("mComputerWins");
mTies = savedInstanceState.getInt("mTies");
mTurn = savedInstanceState.getChar("mTurn");
mFirstMove = savedInstanceState.getChar("mFirstMove");
}
모든 : 나는 다음 복원하고 국가의 절약과 같이 처리하는 두 가지 방법이
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mInfoTextView = (TextView) findViewById(R.id.information);
mHumanScoreTextView = (TextView) findViewById(R.id.player_score);
mComputerScoreTextView = (TextView) findViewById(R.id.computer_score);
mTieScoreTextView = (TextView) findViewById(R.id.tie_score);
mGame = new TicTacToeGame();
mBoardView = (BoardView) findViewById(R.id.board);
mBoardView.setGame(mGame);
mBoardView.setOnTouchListener(mTouchListener);
if (savedInstanceState == null)
startNewGame();
else {
mGame.setBoardState(savedInstanceState.getCharArray("board"));
mGameOver = savedInstanceState.getBoolean("mGameOver");
mInfoTextView.setText(savedInstanceState.getCharSequence("info"));
mHumanWins = savedInstanceState.getInt("mHumanWins");
mComputerWins = savedInstanceState.getInt("mComputerWins");
mTies = savedInstanceState.getInt("mTies");
mTurn = savedInstanceState.getChar("mTurn");
mFirstMove = savedInstanceState.getChar("mFirstMove");
}
displayScores();
}
X 및 O 문자가 보드에 나타나는 대신 X 및 O를 나타내는 그림이 표시되도록 게임을 다시 프로그래밍 할 때까지 이 작업을 수행하려면 TouchListener를 구현해야했습니다. 게임은 수직 모드에서 완벽하게 실행되지만 방향이 바뀌면 즉시 충돌합니다. 나는 뒤집힌 화면이 바뀌는 것을 보지 못한다. layout-land main.xml 파일에서 가로 레이아웃을 보면 괜찮아 보입니다. 앱 충돌없이 실제로 실행될 때 접근하기가 거의 불가능합니다.
전 초보자입니다. 어떤 원인인지 또는 더 많은 도움을 얻기 위해 관련 정보를 알 수 없습니다. 누구라도 조언을하나요?
편집 - 이것은 로그 캣 오류 로그는 다음과 같습니다 그것은 바로 프로그램이을 실행으로 충돌 에뮬레이터에서 실제 장치에 대한 방향 변경시 프로그램이 충돌, 하다니
03-22 00:27:31.739: E/Trace(1042): error opening trace file: No such file or directory (2)
03-22 00:27:31.739: W/Trace(1042): Unexpected value from nativeGetEnabledTags: 0
03-22 00:27:31.739: W/Trace(1042): Unexpected value from nativeGetEnabledTags: 0
03-22 00:27:31.749: W/Trace(1042): Unexpected value from nativeGetEnabledTags: 0
03-22 00:27:31.789: W/Trace(1042): Unexpected value from nativeGetEnabledTags: 0
03-22 00:27:31.789: W/Trace(1042): Unexpected value from nativeGetEnabledTags: 0
03-22 00:27:31.909: D/AndroidRuntime(1042): Shutting down VM
03-22 00:27:31.909: W/dalvikvm(1042): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
03-22 00:27:31.920: E/AndroidRuntime(1042): FATAL EXCEPTION: main
03-22 00:27:31.920: E/AndroidRuntime(1042): java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.joe.tictactoe/edu.joe.tictactoe.AndroidTicTacToeActivity}: java.lang.NullPointerException
03-22 00:27:31.920: E/AndroidRuntime(1042): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-22 00:27:31.920: E/AndroidRuntime(1042): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-22 00:27:31.920: E/AndroidRuntime(1042): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-22 00:27:31.920: E/AndroidRuntime(1042): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-22 00:27:31.920: E/AndroidRuntime(1042): at android.os.Handler.dispatchMessage(Handler.java:99)
03-22 00:27:31.920: E/AndroidRuntime(1042): at android.os.Looper.loop(Looper.java:137)
03-22 00:27:31.920: E/AndroidRuntime(1042): at android.app.ActivityThread.main(ActivityThread.java:5039)
03-22 00:27:31.920: E/AndroidRuntime(1042): at java.lang.reflect.Method.invokeNative(Native Method)
03-22 00:27:31.920: E/AndroidRuntime(1042): at java.lang.reflect.Method.invoke(Method.java:511)
03-22 00:27:31.920: E/AndroidRuntime(1042): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-22 00:27:31.920: E/AndroidRuntime(1042): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-22 00:27:31.920: E/AndroidRuntime(1042): at dalvik.system.NativeStart.main(Native Method)
03-22 00:27:31.920: E/AndroidRuntime(1042): Caused by: java.lang.NullPointerException
03-22 00:27:31.920: E/AndroidRuntime(1042): at edu.joe.tictactoe.AndroidTicTacToeActivity.resetButtons(AndroidTicTacToeActivity.java:194)
03-22 00:27:31.920: E/AndroidRuntime(1042): at edu.joe.tictactoe.AndroidTicTacToeActivity.displayScores(AndroidTicTacToeActivity.java:311)
03-22 00:27:31.920: E/AndroidRuntime(1042): at edu.joe.tictactoe.AndroidTicTacToeActivity.onCreate(AndroidTicTacToeActivity.java:93)
03-22 00:27:31.920: E/AndroidRuntime(1042): at android.app.Activity.performCreate(Activity.java:5104)
03-22 00:27:31.920: E/AndroidRuntime(1042): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-22 00:27:31.920: E/AndroidRuntime(1042): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-22 00:27:31.920: E/AndroidRuntime(1042): ... 11 more
03-22 00:27:32.211: D/dalvikvm(1042): GC_CONCURRENT freed 351K, 17% free 2438K/2908K, paused 109ms+3ms, total 288ms
편집 2 : displayScores() 및 resetButtons() 코드 3
192 public void resetButtons()
193 {
194 for (int i = 0; i < mBoardButtons.length; i++)
195 {
196 mBoardButtons[i].setText("");
197 mBoardButtons[i].setEnabled(true);
198 mBoardButtons[i].setOnClickListener(new ButtonClickListener(i));
199 }
200 }
304 private void displayScores() {
305 mHumanScoreTextView.setText(Integer.toString(mHumanWins));
306 mComputerScoreTextView.setText(Integer.toString(mComputerWins));
307 mTieScoreTextView.setText(Integer.toString(mTies));
308
309
310 char [] temp = mGame.getBoardState();
311 resetButtons();
312
313 for (int i = 0; i < TicTacToeGame.BOARD_SIZE; i++)
314 if (temp [i] != TicTacToeGame.OPEN_SPOT) setMove(temp [i], i);
315 }
편집 : 원래 문제점을 해결 보드 문자 x 또는 o로 채워진 사용 된 버튼. 이 아이콘을 사용하기 위해 제거했지만 resetButtons() 행과 코드를 삭제하는 것을 잊었습니다. 더 이상 존재하지 않는 무언가를 재설정하려했습니다.
글쎄, 우선 방향이 바뀌면 활동이 파괴되고 다시 생성되어 널 포인터 오류가 발생하는 것 같습니다. 아마도 오류 로그를 게시 할 수 있습니까? – cwhsu
어떻게 오류 로그를 찾을 수 있습니까? –
글쎄, 이클립스를 사용한다면 여기 공식 가이드가있다. http://developer.android.com/tools/debugging/ddms.html – cwhsu