android - ViewFlipper causing null pointer exception -
i have program uses view flipper getting nullpointerexception
follows when activity called. wish cycle through set of images long activity being run.
06-13 18:52:05.358: e/androidruntime(368): caused by: java.lang.nullpointerexception
activity:
import android.app.activity; import android.os.bundle; import android.os.handler; import android.view.view; import android.view.viewgroup.layoutparams; import android.view.animation.animationutils; import android.widget.imageview; import android.widget.viewflipper; public class mainmenuactivity extends activity{ handler handler; runnable runnable; viewflipper imageswitcher; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.menupage); imageswitcher= (viewflipper) new viewflipper(this).findviewbyid(r.id.sportspersons); this.viewchanger(); } public void viewchanger() { imageswitcher.setinanimation(this, r.anim.fadein); imageswitcher.setoutanimation(this, r.anim.fadeout); imageview = new imageview(this); i.setbackgrounddrawable(getresources().getdrawable(r.drawable.jowens)); imageview i2 = new imageview(this); i2.setbackgrounddrawable(getresources ().getdrawable(r.drawable.maradonna)); imageview i3 = new imageview(this); i2.setbackgrounddrawable(getresources().getdrawable(r.drawable.mjordan)); imageview i4 = new imageview(this); i2.setbackgrounddrawable(getresources().getdrawable(r.drawable.pele)); imageswitcher.addview(i); imageswitcher.addview(i2); imageswitcher.addview(i3); imageswitcher.addview(i4); runnable = new runnable() { @override public void run() { handler.postdelayed(runnable, 3000); imageswitcher.shownext(); } }; handler.postdelayed(runnable, 500); } }
xml:
<?xml version="1.0" encoding="utf-8"?> <absolutelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <imageview android:id="@+id/imageview2" android:layout_width="match_parent" android:layout_height="508dp" android:layout_x="-4dp" android:layout_y="-5dp" android:scaletype="fitxy" android:src="@drawable/mainmenu01" /> <viewflipper android:id="@+id/sportspersons" android:layout_width="86dp" android:layout_height="91dp" android:layout_x="38dp" android:layout_y="373dp" /> </absolutelayout>
you can try way:
runnable = new runnable() {
@override public void run() { handler.postdelayed(runnable, 3000); imageswitcher.setautostart(true); imageswitcher.startflipping(); } };
Comments
Post a Comment