android - Null Pointer Exception at pager.setAdapter() -
i getting null pointer exception @ pager.setadapter(tabpager);
here code please check out , let me know error
java code main activity
package com.example.prototype; import android.app.actionbar; import android.app.actionbar.tab; import android.app.actionbar.tablistener; import android.app.activity; import android.app.fragmentmanager; import android.app.fragmenttransaction; import android.os.bundle; import android.support.v4.app.actionbardrawertoggle; import android.support.v4.app.fragmentactivity; import android.support.v4.view.viewpager; import android.support.v4.widget.drawerlayout; import android.support.v4.widget.drawerlayout.drawerlistener; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.arrayadapter; import android.widget.listview; import android.widget.toast; public class mainactivity extends fragmentactivity implements actionbar.tablistener { tabspageradapter tabpager; viewpager pager; drawerlayout drawerlayout; actionbar action_bar; listview navigation_list; @suppresswarnings("deprecation") actionbardrawertoggle drawertoggle; string items[]; string tabs_list[]={"best offers","categories","near places"}; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.drawer_layout); initcomponents(); action_bar=getactionbar(); setnavigationlist(); settabs(); } @suppresswarnings("deprecation") private void settabs() { action_bar.setnavigationmode(actionbar.navigation_mode_tabs); (string tab_name : tabs_list) { action_bar.addtab(action_bar.newtab().settext(tab_name) .settablistener(this)); } try{pager.setadapter(tabpager);} catch(exception e){ e.printstacktrace(); } } @suppresswarnings("deprecation") private void setnavigationlist() { int open=r.string.navigation_open; int close=r.string.navigation_close; navigation_list.setadapter(new arrayadapter<string>(this, android.r.layout.simple_list_item_1, items)); drawertoggle=new actionbardrawertoggle(this,drawerlayout, r.drawable.ic_menu_white_18dp,open,close){ public void ondrawerclosed(view view) { super.ondrawerclosed(view); action_bar.show(); } public void ondraweropened(view drawerview) { super.ondraweropened(drawerview); action_bar.hide(); } }; drawerlayout.setdrawerlistener(drawertoggle); action_bar.setdisplayhomeasupenabled(true); action_bar.sethomebuttonenabled(true); } @override protected void onpostcreate(bundle savedinstancestate) { // todo auto-generated method stub super.onpostcreate(savedinstancestate); drawertoggle.syncstate(); } private void initcomponents() { // todo auto-generated method stub drawerlayout=(drawerlayout) findviewbyid(r.id.drawer_layout); action_bar=getactionbar(); navigation_list=(listview) findviewbyid(r.id.left_drawer); items=getresources().getstringarray(r.array.navigation_drawer); pager=(viewpager) findviewbyid(r.id.pager); android.support.v4.app.fragmentmanager m=getsupportfragmentmanager(); tabpager=new tabspageradapter(m); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { return true; } if (id == r.id.search_menu) { toast.maketext(getapplicationcontext(), "searched clicked ", toast.length_long).show(); return true; } if (id == r.id.share_menu) { toast.maketext(getapplicationcontext(), "share clicked ", toast.length_long).show(); return true; } if (id == r.id.navigation_menu) { toast.maketext(getapplicationcontext(), "navigation clicked ", toast.length_long).show(); return true; } return super.onoptionsitemselected(item); } @override public void ontabselected(tab tab, fragmenttransaction ft) { // todo auto-generated method stub } @override public void ontabunselected(tab tab, fragmenttransaction ft) { // todo auto-generated method stub } @override public void ontabreselected(tab tab, fragmenttransaction ft) { // todo auto-generated method stub } }
for adapterclass
public class tabspageradapter extends fragmentpageradapter { public tabspageradapter(fragmentmanager fm) { super(fm); // todo auto-generated constructor stub } @override public fragment getitem(int arg0) { switch(arg0){ case 0: new bestofferfragment(); break; case 1: new categoriesrfragment(); break; case 2: new nearbyplacesfragment(); break; } return null; } @override public int getcount() { // todo auto-generated method stub return 3; } }
xml file
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v4.view.viewpager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" android:focusable="true" android:focusableintouchmode="true" /> <listview android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:choicemode="singlechoice" android:divider="@android:color/transparent" android:dividerheight="5dp" android:background="#e1e1e1"/> </android.support.v4.widget.drawerlayout>
please me out
i checked object of viewer , tabadapter not null not getting why giving error while setting adapter..
here log
07-06 01:24:16.471: d/dalvikvm(20183): threadid=2: interp stack @ 0x5a6b7000 07-06 01:24:16.476: d/dalvikvm(20183): threadid=3: interp stack @ 0x5a7bf000 07-06 01:24:16.477: d/jdwp(20183): prepping jdwp on adb 07-06 01:24:16.477: d/jdwp(20183): adb transport startup 07-06 01:24:16.479: d/dalvikvm(20183): elevating priority 0 -8 07-06 01:24:16.479: d/dalvikvm(20183): threadid=4: interp stack @ 0x5a8c7000 07-06 01:24:16.480: d/jdwp(20183): jdwp: thread running 07-06 01:24:16.482: d/jdwp(20183): acceptconnection 07-06 01:24:16.483: d/jdwp(20183): trying receive file descriptor adb 07-06 01:24:16.484: d/dalvikvm(20183): threadid=5: interp stack @ 0x5cd1d000 07-06 01:24:16.484: d/dalvikvm(20183): zygote thread init done 07-06 01:24:16.484: d/dalvikvm(20183): create interp thread : stack size=32kb 07-06 01:24:16.484: d/dalvikvm(20183): create new thread 07-06 01:24:16.484: d/dalvikvm(20183): new thread created 07-06 01:24:16.485: d/dalvikvm(20183): update thread list 07-06 01:24:16.485: d/dalvikvm(20183): threadid=6: interp stack @ 0x5cd25000 07-06 01:24:16.485: d/dalvikvm(20183): threadid=6: created interp 07-06 01:24:16.485: d/dalvikvm(20183): start new thread 07-06 01:24:16.486: d/dalvikvm(20183): create interp thread : stack size=32kb 07-06 01:24:16.486: d/dalvikvm(20183): create new thread 07-06 01:24:16.487: d/dalvikvm(20183): new thread created 07-06 01:24:16.487: d/dalvikvm(20183): update thread list 07-06 01:24:16.487: d/dalvikvm(20183): threadid=6: notify debugger 07-06 01:24:16.487: d/dalvikvm(20183): threadid=6 (referencequeuedaemon): calling run() 07-06 01:24:16.487: d/dalvikvm(20183): threadid=7: interp stack @ 0x5ce2d000 07-06 01:24:16.488: d/dalvikvm(20183): threadid=7: created interp 07-06 01:24:16.488: d/dalvikvm(20183): start new thread 07-06 01:24:16.490: d/dalvikvm(20183): create interp thread : stack size=32kb 07-06 01:24:16.490: d/dalvikvm(20183): create new thread 07-06 01:24:16.490: d/jdwp(20183): received file descriptor 39 adb 07-06 01:24:16.490: d/dalvikvm(20183): new thread created 07-06 01:24:16.490: d/dalvikvm(20183): update thread list 07-06 01:24:16.490: d/dalvikvm(20183): threadid=7: notify debugger 07-06 01:24:16.490: d/dalvikvm(20183): threadid=7 (finalizerdaemon): calling run() 07-06 01:24:16.491: d/dalvikvm(20183): threadid=8: interp stack @ 0x5cf35000 07-06 01:24:16.491: d/dalvikvm(20183): threadid=8: created interp 07-06 01:24:16.491: d/dalvikvm(20183): start new thread 07-06 01:24:16.495: d/jdwp(20183): processincoming 07-06 01:24:16.495: d/jdwp(20183): processincoming 07-06 01:24:16.495: d/jdwp(20183): handlepacket : cmd=0x1, cmdset=0xc7, len=0x13, id=0x4000019f, flags=0x0, datalen=0x8 07-06 01:24:16.504: d/jdwp(20183): processincoming 07-06 01:24:16.504: d/jdwp(20183): handlepacket : cmd=0x1, cmdset=0xc7, len=0x17, id=0x400001a0, flags=0x0, datalen=0xc 07-06 01:24:16.516: d/jdwp(20183): processincoming 07-06 01:24:16.517: d/jdwp(20183): handlepacket : cmd=0x1, cmdset=0xc7, len=0x13, id=0x400001a1, flags=0x0, datalen=0x8 07-06 01:24:16.525: d/dalvikvm(20183): threadid=8: notify debugger 07-06 01:24:16.525: d/dalvikvm(20183): threadid=8 (finalizerwatchdogdaemon): calling run() 07-06 01:24:16.537: d/jdwp(20183): processincoming 07-06 01:24:16.537: d/jdwp(20183): handlepacket : cmd=0x1, cmdset=0xc7, len=0x13, id=0x400001a2, flags=0x0, datalen=0x8 07-06 01:24:16.538: d/jdwp(20183): processincoming 07-06 01:24:16.538: d/jdwp(20183): handlepacket : cmd=0x1, cmdset=0xc7, len=0x14, id=0x400001a3, flags=0x0, datalen=0x9 07-06 01:24:16.576: d/dalvikvm(20183): threadid=9: interp stack @ 0x5d33b000 07-06 01:24:16.591: d/dalvikvm(20183): threadid=10: interp stack @ 0x5d443000 07-06 01:24:16.614: d/jdwp(20183): sendbufferedrequest : len=0x3d 07-06 01:24:16.720: d/jdwp(20183): sendbufferedrequest : len=0x45 07-06 01:24:16.770: d/dalvikvm(20183): open_cached_dex_file : /data/app/com.example.prototype-2.apk /data/dalvik-cache/data@app@com.example.prototype-2.apk@classes.dex 07-06 01:24:16.807: d/skia(20183): flag not 10 07-06 01:24:16.813: d/skia(20183): flag not 10 07-06 01:24:16.817: d/skia(20183): flag not 10 07-06 01:24:16.824: d/skia(20183): flag not 10 07-06 01:24:16.825: d/skia(20183): flag not 10 07-06 01:24:16.827: d/skia(20183): flag not 10 07-06 01:24:16.828: d/skia(20183): flag not 10 07-06 01:24:16.845: d/skia(20183): flag not 10 07-06 01:24:16.857: d/dalvikvm(20183): gc_for_alloc freed 109k, 8% free 2861k/3092k, paused 11ms, total 11ms 07-06 01:24:16.859: i/dalvikvm-heap(20183): grow heap (frag case) 3.982mb 1127536-byte allocation 07-06 01:24:16.876: d/dalvikvm(20183): gc_for_alloc freed 1k, 6% free 3961k/4196k, paused 17ms, total 17ms 07-06 01:24:16.884: d/skia(20183): flag not 10 07-06 01:24:16.893: d/skia(20183): flag not 10 07-06 01:24:16.896: d/dalvikvm(20183): gc_concurrent freed 3k, 6% free 3969k/4196k, paused 2ms+1ms, total 20ms 07-06 01:24:16.899: d/skia(20183): flag not 10 07-06 01:24:16.900: d/skia(20183): flag not 10 07-06 01:24:16.901: d/skia(20183): flag not 10 07-06 01:24:16.902: d/skia(20183): flag not 10 07-06 01:24:16.904: d/abslistview(20183): checkabslistviewllogproperty invalid command 07-06 01:24:16.907: d/skia(20183): flag not 10 07-06 01:24:16.910: d/skia(20183): flag not 10 07-06 01:24:16.914: d/skia(20183): flag not 10 07-06 01:24:16.916: d/skia(20183): flag not 10 07-06 01:24:16.917: d/skia(20183): flag not 10 07-06 01:24:16.918: d/skia(20183): flag not 10 07-06 01:24:16.919: d/skia(20183): flag not 10 07-06 01:24:16.976: d/androidruntime(20183): shutting down vm 07-06 01:24:16.976: w/dalvikvm(20183): threadid=1: thread exiting uncaught exception (group=0x4126e9a8) 07-06 01:24:16.980: e/androidruntime(20183): fatal exception: main 07-06 01:24:16.980: e/androidruntime(20183): java.lang.nullpointerexception 07-06 01:24:16.980: e/androidruntime(20183): @ android.support.v4.app.backstackrecord.doaddop(backstackrecord.java:417) 07-06 01:24:16.980: e/androidruntime(20183): @ android.support.v4.app.backstackrecord.add(backstackrecord.java:412) 07-06 01:24:16.980: e/androidruntime(20183): @ android.support.v4.app.fragmentpageradapter.instantiateitem(fragmentpageradapter.java:99) 07-06 01:24:16.980: e/androidruntime(20183): @ android.support.v4.view.viewpager.addnewitem(viewpager.java:869) 07-06 01:24:16.980: e/androidruntime(20183): @ android.support.v4.view.viewpager.populate(viewpager.java:1019) 07-06 01:24:16.980: e/androidruntime(20183): @ android.support.v4.view.viewpager.populate(viewpager.java:951) 07-06 01:24:16.980: e/androidruntime(20183): @ android.support.v4.view.viewpager.onmeasure(viewpager.java:1473) 07-06 01:24:16.980: e/androidruntime(20183): @ android.view.view.measure(view.java:15609) 07-06 01:24:16.980: e/androidruntime(20183): @ android.support.v4.widget.drawerlayout.onmeasure(drawerlayout.java:868) 07-06 01:24:16.980: e/androidruntime(20183): @ android.view.view.measure(view.java:15609) 07-06 01:24:16.980: e/androidruntime(20183): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4916) 07-06 01:24:16.980: e/androidruntime(20183): @ android.widget.framelayout.onmeasure(framelayout.java:310) 07-06 01:24:16.980: e/androidruntime(20183): @ android.view.view.measure(view.java:15609) 07-06 01:24:16.980: e/androidruntime(20183): @ android.widget.linearlayout.measurevertical(linearlayout.java:850) 07-06 01:24:16.980: e/androidruntime(20183): @ android.widget.linearlayout.onmeasure(linearlayout.java:588) 07-06 01:24:16.980: e/androidruntime(20183): @ android.view.view.measure(view.java:15609) 07-06 01:24:16.980: e/androidruntime(20183): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4916) 07-06 01:24:16.980: e/androidruntime(20183): @ android.widget.framelayout.onmeasure(framelayout.java:310) 07-06 01:24:16.980: e/androidruntime(20183): @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2191) 07-06 01:24:16.980: e/androidruntime(20183): @ android.view.view.measure(view.java:15609) 07-06 01:24:16.980: e/androidruntime(20183): @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:2165) 07-06 01:24:16.980: e/androidruntime(20183): @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1249) 07-06 01:24:16.980: e/androidruntime(20183): @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1443) 07-06 01:24:16.980: e/androidruntime(20183): @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1139) 07-06 01:24:16.980: e/androidruntime(20183): @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:4879) 07-06 01:24:16.980: e/androidruntime(20183): @ android.view.choreographer$callbackrecord.run(choreographer.java:776) 07-06 01:24:16.980: e/androidruntime(20183): @ android.view.choreographer.docallbacks(choreographer.java:579) 07-06 01:24:16.980: e/androidruntime(20183): @ android.view.choreographer.doframe(choreographer.java:548) 07-06 01:24:16.980: e/androidruntime(20183): @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:762) 07-06 01:24:16.980: e/androidruntime(20183): @ android.os.handler.handlecallback(handler.java:725) 07-06 01:24:16.980: e/androidruntime(20183): @ android.os.handler.dispatchmessage(handler.java:92) 07-06 01:24:16.980: e/androidruntime(20183): @ android.os.looper.loop(looper.java:153) 07-06 01:24:16.980: e/androidruntime(20183): @ android.app.activitythread.main(activitythread.java:5297) 07-06 01:24:16.980: e/androidruntime(20183): @ java.lang.reflect.method.invokenative(native method) 07-06 01:24:16.980: e/androidruntime(20183): @ java.lang.reflect.method.invoke(method.java:511) 07-06 01:24:16.980: e/androidruntime(20183): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:833) 07-06 01:24:16.980: e/androidruntime(20183): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:600) 07-06 01:24:16.980: e/androidruntime(20183): @ dalvik.system.nativestart.main(native method) 07-06 01:24:17.008: i/process(20183): sending signal. pid: 20183 sig: 9
return fragment getitem
:
@override public fragment getitem(int arg0) { fragment fragment = null; switch(arg0){ case 0: fragment = new bestofferfragment(); break; case 1: fragment = new categoriesrfragment(); break; case 2: fragment = new nearbyplacesfragment(); break; } return fragment; }
Comments
Post a Comment