Android will crash depending on layout positioning -


here's layout works :

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/mainlayout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".mainactivity" >  <linearlayout     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:orientation="vertical" >      <com.astuetz.viewpager.extensions.pagerslidingtabstrip         android:id="@+id/tabs"         android:layout_width="match_parent"         android:layout_height="48dip" >     </com.astuetz.viewpager.extensions.pagerslidingtabstrip>      <android.support.v4.view.viewpager         android:id="@+id/pager"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_weight="1"         tools:context=".mainactivity" >     </android.support.v4.view.viewpager>  </linearlayout> 

and here activity oncreate method:

protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      pager = (viewpager) findviewbyid(r.id.pager);      adapter = new mypageradapter(getsupportfragmentmanager());      pager.setadapter(adapter);      tabs = (pagerslidingtabstrip) findviewbyid(r.id.tabs);     tabs.setviewpager(pager);     tabs.setdividercolor(color.blue);     tabs.setbackgroundcolor(color.dkgray);     tabs.settextcolor(color.white);     tabs.setindicatorcolor(color.green);  } 

if in layout inverse pagerslidingtabstrip , viewpager, project crash @ startup, while in first implementation, work fine.

here's error :

05-19 16:50:11.636: e/androidruntime(305): fatal exception: main 05-19 16:50:11.636: e/androidruntime(305): java.lang.runtimeexception: unable start activity componentinfo{com.hsware.peeem/com.hsware.peeem.mainactivity}: java.lang.classcastexception: android.support.v4.view.viewpager 05-19 16:50:11.636: e/androidruntime(305):  @ android.app.activitythread.performlaunchactivity(activitythread.java:2663) 05-19 16:50:11.636: e/androidruntime(305):  @ android.app.activitythread.handlelaunchactivity(activitythread.java:2679) 05-19 16:50:11.636: e/androidruntime(305):  @ android.app.activitythread.access$2300(activitythread.java:125) 05-19 16:50:11.636: e/androidruntime(305):  @ android.app.activitythread$h.handlemessage(activitythread.java:2033) 05-19 16:50:11.636: e/androidruntime(305):  @ android.os.handler.dispatchmessage(handler.java:99) 05-19 16:50:11.636: e/androidruntime(305):  @ android.os.looper.loop(looper.java:123) 05-19 16:50:11.636: e/androidruntime(305):  @ android.app.activitythread.main(activitythread.java:4627) 05-19 16:50:11.636: e/androidruntime(305):  @ java.lang.reflect.method.invokenative(native method) 05-19 16:50:11.636: e/androidruntime(305):  @ java.lang.reflect.method.invoke(method.java:521) 05-19 16:50:11.636: e/androidruntime(305):  @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:868) 05-19 16:50:11.636: e/androidruntime(305):  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:626) 05-19 16:50:11.636: e/androidruntime(305):  @ dalvik.system.nativestart.main(native method) 05-19 16:50:11.636: e/androidruntime(305): caused by: java.lang.classcastexception: android.support.v4.view.viewpager 05-19 16:50:11.636: e/androidruntime(305):  @ com.hsware.peeem.mainactivity.oncreate(mainactivity.java:41) 05-19 16:50:11.636: e/androidruntime(305):  @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1047) 05-19 16:50:11.636: e/androidruntime(305):  @ android.app.activitythread.performlaunchactivity(activitythread.java:2627) 

it appears can't retrieve de r.id.pager, i'm not sure.

i've noticed when making small ordering changes, compiler not pick up. classcastexception occurring because findviewbyid returning wrong view given r.id.pager, or more accurately - r.id.pager not referring correct view.

the way fix clean , re-build project.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -