I am trying to implement the animation of a card flipping on android fragments. This way i can have the front side with its own custom view and the same with the back.
My problem is when the back of the card is displayed, meaning the flip animation has been called once before. When clicking on the button to display the front fragment again it crashes the application with the below error.
07-31 20:26:14.649: E/AndroidRuntime(28575): FATAL EXCEPTION: main
07-31 20:26:14.649: E/AndroidRuntime(28575): java.lang.NullPointerException
07-31 20:26:14.649: E/AndroidRuntime(28575): at com.Pivotl.PostcardsFromAlaska.PFANewPostcard_Activity.flipCard(PFANewPostcard_Activity.java:174)
07-31 20:26:14.649: E/AndroidRuntime(28575): at com.Pivotl.PostcardsFromAlaska.PFANewPostcard_Activity.access$0(PFANewPostcard_Activity.java:168)
07-31 20:26:14.649: E/AndroidRuntime(28575): at com.Pivotl.PostcardsFromAlaska.PFANewPostcard_Activity$2.onClick(PFANewPostcard_Activity.java:99)
07-31 20:26:14.649: E/AndroidRuntime(28575): at android.view.View.performClick(View.java:4223)
07-31 20:26:14.649: E/AndroidRuntime(28575): at android.view.View$PerformClick.run(View.java:17281)
07-31 20:26:14.649: E/AndroidRuntime(28575): at android.os.Handler.handleCallback(Handler.java:615)
07-31 20:26:14.649: E/AndroidRuntime(28575): at android.os.Handler.dispatchMessage(Handler.java:92)
07-31 20:26:14.649: E/AndroidRuntime(28575): at android.os.Looper.loop(Looper.java:137)
07-31 20:26:14.649: E/AndroidRuntime(28575): at android.app.ActivityThread.main(ActivityThread.java:4898)
07-31 20:26:14.649: E/AndroidRuntime(28575): at java.lang.reflect.Method.invokeNative(Native Method)
07-31 20:26:14.649: E/AndroidRuntime(28575): at java.lang.reflect.Method.invoke(Method.java:511)
07-31 20:26:14.649: E/AndroidRuntime(28575): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
07-31 20:26:14.649: E/AndroidRuntime(28575): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
07-31 20:26:14.649: E/AndroidRuntime(28575): at dalvik.system.NativeStart.main(Native Method)
My animations were made from this tutorial: http://developer.android.com/training/animation/cardflip.html
Then i have three methods
flipCard():
private void flipCard()
{
Log.d(tag2, "Log after flipCard:" + mShowingBack);
if(mShowingBack)
{
//Check Items and Save variables
if(backMessageEdit.getText().toString() != null){
//save string
backMessage = backMessageEdit.getText().toString();
}
//show front
flipFront();
return;
}
// Flip to back
flipBack();
}
flipFront():
private void flipFront()
{
mShowingBack = false;
getFragmentManager()
.beginTransaction()
.setCustomAnimations(R.animator.card_flip_left_in, R.animator.card_flip_left_out,
R.animator.card_flip_right_in, R.animator.card_flip_right_out)
.replace(R.id.postcardFrame, new CardFrontFragment())
.addToBackStack(null)
.commit();
}
flipBack():
private void flipBack()
{
getFragmentManager()
.beginTransaction()
.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(R.id.postcardFrame, new CardBackFragment())
.addToBackStack(null)
.commit();
mShowingBack = true;
}
on a button click i call flipCard like so:
cardBackButton.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
//Check what side is showing
//Then perform flip left or right
flipCard();
}
});
Seems very straight forward but i cant seem to wrap my finger around it, i put it down the other day and am just now getting back to it.
I greatly appreciate any help on this matter!
I would need to see more code however, I would have to say that you do not have a correct reference to backMessageEdit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With