2014-04-09 4 views
1

Android Dev 웹 사이트에서 Card Flip 튜토리얼을 진행하는 데 문제가있는 것 같습니다. 나는 따라 와서 그것을 스위트 룸에 맞게 수정하지만 충돌이 발생하고 이유가 확실하지 않습니다. 이클립스는 내 자바 코드에서 어떤 오류도주지 않는다. 누군가 시도 할 수있는 제안이 있는지 궁금합니다. 나는 java와 logcat을 포함시켰다. 시간 내 줘서 고마워.Android, 앱이 카드 뒤집기 애니메이션을 사용하여 충돌 함

자바 :

import android.support.v7.app.ActionBarActivity; 
import android.support.v7.app.ActionBar; 
import android.support.v4.app.Fragment; 
import android.os.Bundle; 
import android.os.Handler; 
import android.view.LayoutInflater; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.Toast; 
import android.os.Build; 

public class MainActivity extends ActionBarActivity { 
    /** 
    * Whether or not we're showing the back of the card (otherwise showing the front). 
    */ 
    private boolean mShowingBack = false; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     if (savedInstanceState == null) { 
      getSupportFragmentManager() 
      .beginTransaction() 
      .add(R.id.container, new CardFrontFragment()) 
      .commit(); 
     }else { 
      mShowingBack = (getFragmentManager().getBackStackEntryCount() > 0); 
     } 

      /** 
      getSupportFragmentManager().beginTransaction() 
        .add(R.id.container, new PlaceholderFragment()).commit(); 
        */ 
    } 

    private void flipCard() { 
     if (mShowingBack) { 
      getFragmentManager().popBackStack(); 
      return; 
     } 

     // Flip to the back. 

     mShowingBack = true; 

     // Create and commit a new fragment transaction that adds the fragment for the back of 
     // the card, uses custom animations, and is part of the fragment manager's back stack. 

     getSupportFragmentManager() 
       .beginTransaction() 

       // Replace the default fragment animations with animator resources representing 
       // rotations when switching to the back of the card, as well as animator 
       // resources representing rotations when flipping back to the front (e.g. when 
       // the system Back button is pressed). 
       .setCustomAnimations(
         R.animator.card_flip_right_in, R.animator.card_flip_right_out, 
         R.animator.card_flip_left_in, R.animator.card_flip_left_out) 

       // Replace any fragments currently in the container view with a fragment 
       // representing the next page (indicated by the just-incremented currentPage 
       // variable). 
       .replace(R.id.container, new CardBackFragment()) 

       // Add this transaction to the back stack, allowing users to press Back 
       // to get to the front of the card. 
       .addToBackStack(null) 

       // Commit the transaction. 
       .commit(); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 

     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 
     if (id == R.id.card_flip) { 
      flipCard(); 
      return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 

    /** 
    * A placeholder fragment containing a simple view. 
    */ 
    public static class PlaceholderFragment extends Fragment { 

     public PlaceholderFragment() { 
     } 

     @Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, 
       Bundle savedInstanceState) { 
      View rootView = inflater.inflate(R.layout.fragment_main, container, 
        false); 
      return rootView; 
     } 
    } 

    /** 
    * A fragment representing the front of the card. 
    */ 
    public static class CardFrontFragment extends Fragment { 
     @Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, 
       Bundle savedInstanceState) { 
      return inflater.inflate(R.layout.card_front, container, false); 
     } 
    } 

    /** 
    * A fragment representing the back of the card. 
    */ 
    public static class CardBackFragment extends Fragment { 
     @Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, 
       Bundle savedInstanceState) { 
      return inflater.inflate(R.layout.card_back, container, false); 
     } 
    } 

} 

로그 캣 : 당신이 Animation objectAnimator를 초기화하지 않았기 때문에

04-09 01:44:56.440: D/dalvikvm(799): Not late-enabling CheckJNI (already on) 
04-09 01:45:01.850: D/dalvikvm(799): GC_FOR_ALLOC freed 87K, 8% free 2905K/3124K, paused 37ms, total 41ms 
04-09 01:45:01.850: I/dalvikvm-heap(799): Grow heap (frag case) to 8.892MB for 6220816-byte allocation 
04-09 01:45:01.900: D/dalvikvm(799): GC_FOR_ALLOC freed 3K, 3% free 8976K/9200K, paused 43ms, total 43ms 
04-09 01:45:02.530: D/(799): HostConnection::get() New Host Connection established 0xb89a8468, tid 799 
04-09 01:45:02.660: W/EGL_emulation(799): eglSurfaceAttrib not implemented 
04-09 01:45:02.670: D/OpenGLRenderer(799): Enabling debug mode 0 
04-09 01:45:06.140: W/EGL_emulation(799): eglSurfaceAttrib not implemented 
04-09 01:45:10.960: W/EGL_emulation(799): eglSurfaceAttrib not implemented 
04-09 01:45:13.390: W/EGL_emulation(799): eglSurfaceAttrib not implemented 
04-09 01:46:59.588: D/dalvikvm(1088): GC_FOR_ALLOC freed 84K, 7% free 2905K/3120K, paused 36ms, total 38ms 
04-09 01:46:59.588: I/dalvikvm-heap(1088): Grow heap (frag case) to 8.892MB for 6220816-byte allocation 
04-09 01:46:59.638: D/dalvikvm(1088): GC_FOR_ALLOC freed 3K, 3% free 8976K/9196K, paused 40ms, total 40ms 
04-09 01:47:00.298: D/(1088): HostConnection::get() New Host Connection established 0xb8acdf90, tid 1088 
04-09 01:47:00.458: W/EGL_emulation(1088): eglSurfaceAttrib not implemented 
04-09 01:47:00.478: D/OpenGLRenderer(1088): Enabling debug mode 0 
04-09 01:47:03.968: W/EGL_emulation(1088): eglSurfaceAttrib not implemented 
04-09 01:47:08.418: W/EGL_emulation(1088): eglSurfaceAttrib not implemented 
04-09 01:48:39.118: D/dalvikvm(1145): GC_FOR_ALLOC freed 87K, 8% free 2905K/3124K, paused 41ms, total 45ms 
04-09 01:48:39.118: I/dalvikvm-heap(1145): Grow heap (frag case) to 8.892MB for 6220816-byte allocation 
04-09 01:48:39.158: D/dalvikvm(1145): GC_FOR_ALLOC freed 3K, 3% free 8976K/9200K, paused 31ms, total 32ms 
04-09 01:48:39.728: D/(1145): HostConnection::get() New Host Connection established 0xb8acdfa0, tid 1145 
04-09 01:48:39.858: W/EGL_emulation(1145): eglSurfaceAttrib not implemented 
04-09 01:48:39.888: D/OpenGLRenderer(1145): Enabling debug mode 0 
04-09 01:48:45.628: W/EGL_emulation(1145): eglSurfaceAttrib not implemented 
04-09 01:48:46.758: D/AndroidRuntime(1145): Shutting down VM 
04-09 01:48:46.758: W/dalvikvm(1145): threadid=1: thread exiting with uncaught exception (group=0xb3a87ba8) 
04-09 01:48:46.778: E/AndroidRuntime(1145): FATAL EXCEPTION: main 
04-09 01:48:46.778: E/AndroidRuntime(1145): Process: you.ca.mohawk.lab6b, PID: 1145 
04-09 01:48:46.778: E/AndroidRuntime(1145): java.lang.RuntimeException: Unknown animation name: objectAnimator 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:124) 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:114) 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:91) 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at android.view.animation.AnimationUtils.loadAnimation(AnimationUtils.java:72) 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at android.support.v4.app.FragmentManagerImpl.loadAnimation(FragmentManager.java:776) 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1011) 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at android.support.v4.app.FragmentManagerImpl.removeFragment(FragmentManager.java:1212) 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:639) 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478) 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446) 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at android.os.Handler.handleCallback(Handler.java:733) 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at android.os.Handler.dispatchMessage(Handler.java:95) 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at android.os.Looper.loop(Looper.java:136) 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at android.app.ActivityThread.main(ActivityThread.java:5017) 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at java.lang.reflect.Method.invokeNative(Native Method) 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at java.lang.reflect.Method.invoke(Method.java:515) 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
04-09 01:48:46.778: E/AndroidRuntime(1145):  at dalvik.system.NativeStart.main(Native Method) 
+0

'java.lang.RuntimeException : 알 수없는 애니메이션 이름 : objectAnimator' –

답변

0

당신은, 런타임 예외를 받고.

java.lang.RuntimeException: Unknown animation name: objectAnimator 
0

3.0 이상에서만 작동하므로 안드로이드 버전을 확인하십시오.

+0

최소 SDK가 11로 설정되었습니다. – khmer2040

0

바라건대 이것은 지금까지 해결되었지만 방금 같은 문제가 있었으며 제안이 저에게 효과적이지 않았습니다. 무엇이 작동 했습니까 (google's sample card flip code을 광산과 비교 한 후) import android.support.v4.app.Fragment;을 사용하는 것이 내 문제의 원인이었습니다. import android.app.Fragment;으로 변경하면 저의 오류를 없앨 수 있습니다. 그러나이 변경은 앱이 작동하는 버전에 영향을 미칩니다.

관련 문제