Ich habe eine Navigationsschublade in meiner APP.Ich möchte eine Diashow im Navigationsschublade-Header erstellen. Also, ich benutze ViewFlipper für nav_header.xml. Ich habe den folgenden Code in MainActivity verwendet. Aber die App wird gestoppt. Was sollte ich ändern?ViewFlipper funktioniert nicht, App gestoppt
diesen Fehler:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.myapp.praxi/com.myapp.praxi.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
Hier ist mein Code:
int[] resources = {R.drawable.prxi,
R.drawable.prxi1,
R.drawable.prxi2,
R.drawable.prxi3,
};
ViewFlipper imageFlipper = (ViewFlipper) this.findViewById(R.id.view_flipper);
for (int i = 0; i < resources.length; i++) {
ImageView imageView = new ImageView(this);
imageView.setImageResource(resources[i]);
imageFlipper.addView(imageView);
}
imageFlipper.setFlipInterval(4000);
imageFlipper.setInAnimation(this, android.R.anim.slide_in_left); //use either the default slide animation in sdk or create your own ones
imageFlipper.setOutAnimation(this, android.R.anim.slide_out_right);
imageFlipper.getInAnimation().setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationEnd(Animation animation) {
int displayedChild = imageFlipper.getDisplayedChild();
int childCount = imageFlipper.getChildCount();
if (displayedChild == childCount - 1) {
imageFlipper.stopFlipping();
}
}
});
imageFlipper.startFlipping();`
nav_header Datei:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="@android:dimen/thumbnail_height"
android:padding="16dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:orientation="vertical"
android:gravity="bottom"
android:background="@drawable/prxi"
android:id="@+id/linear">
<ViewFlipper
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/view_flipper">
</ViewFlipper>
</LinearLayout>