android - Enigmatic NullPointerException -
i'm getting following null pointer exception. whenever click on button(which i've intent launch) . fc , nullpointer exception. because of use of text file?
logcat
04-25 20:02:40.762: i/adreno200-eglsub(29671): <configwindowmatch:2081>: format rgba_8888. 04-25 20:02:40.772: d/memalloc(29671): /dev/pmem: mapped buffer base:0x514e1000 size:3649536 offset:3035136 fd:56 04-25 20:02:40.982: d/memalloc(29671): /dev/pmem: mapped buffer base:0x51b08000 size:4325376 offset:3710976 fd:59 04-25 20:02:41.632: i/adreno200-eglsub(29671): <configwindowmatch:2081>: format rgba_8888. 04-25 20:02:41.632: d/memalloc(29671): /dev/pmem: mapped buffer base:0x5212e000 size:4939776 offset:4325376 fd:62 04-25 20:02:41.692: d/memalloc(29671): /dev/pmem: mapped buffer base:0x52615000 size:5554176 offset:4939776 fd:68 04-25 20:02:41.712: d/memalloc(29671): /dev/pmem: unmapping buffer base:0x514e1000 size:3649536 offset:3035136 04-25 20:02:41.712: d/memalloc(29671): /dev/pmem: unmapping buffer base:0x51b08000 size:4325376 offset:3710976 04-25 20:02:42.842: d/memalloc(29671): /dev/pmem: mapped buffer base:0x513e1000 size:4325376 offset:3710976 fd:53 04-25 20:02:42.882: w/dalvikvm(29671): threadid=1: thread exiting uncaught exception (group=0x40dbb9d8) 04-25 20:02:42.902: e/androidruntime(29671): fatal exception: main 04-25 20:02:42.902: e/androidruntime(29671): java.lang.runtimeexception: unable instantiate activity componentinfo{com.dreamgoogle.gihf/com.dreamgoogle.gihf.stories}: java.lang.nullpointerexception 04-25 20:02:42.902: e/androidruntime(29671): @ android.app.activitythread.performlaunchactivity(activitythread.java:1884) 04-25 20:02:42.902: e/androidruntime(29671): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1985) 04-25 20:02:42.902: e/androidruntime(29671): @ android.app.activitythread.access$600(activitythread.java:127) 04-25 20:02:42.902: e/androidruntime(29671): @ android.app.activitythread$h.handlemessage(activitythread.java:1151) 04-25 20:02:42.902: e/androidruntime(29671): @ android.os.handler.dispatchmessage(handler.java:99) 04-25 20:02:42.902: e/androidruntime(29671): @ android.os.looper.loop(looper.java:137) 04-25 20:02:42.902: e/androidruntime(29671): @ android.app.activitythread.main(activitythread.java:4476) 04-25 20:02:42.902: e/androidruntime(29671): @ java.lang.reflect.method.invokenative(native method) 04-25 20:02:42.902: e/androidruntime(29671): @ java.lang.reflect.method.invoke(method.java:511) 04-25 20:02:42.902: e/androidruntime(29671): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:816) 04-25 20:02:42.902: e/androidruntime(29671): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:583) 04-25 20:02:42.902: e/androidruntime(29671): @ dalvik.system.nativestart.main(native method) 04-25 20:02:42.902: e/androidruntime(29671): caused by: java.lang.nullpointerexception 04-25 20:02:42.902: e/androidruntime(29671): @ android.app.activity.findviewbyid(activity.java:1965) 04-25 20:02:42.902: e/androidruntime(29671): @ com.dreamgoogle.gihf.stories.<init>(stories.java:14) 04-25 20:02:42.902: e/androidruntime(29671): @ java.lang.class.newinstanceimpl(native method) 04-25 20:02:42.902: e/androidruntime(29671): @ java.lang.class.newinstance(class.java:1319) 04-25 20:02:42.902: e/androidruntime(29671): @ android.app.instrumentation.newactivity(instrumentation.java:1025) 04-25 20:02:42.902: e/androidruntime(29671): @ android.app.activitythread.performlaunchactivity(activitythread.java:1875)
xml file
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview android:id="@+id/jobsdes" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:text="@string/sj1" /> </relativelayout>
java file.
public class stories extends activity { textview t1 = (textview) findviewbyid(r.id.jobsdes); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_stories); mypageradapter adapter = new mypageradapter(); viewpager mypager = (viewpager) findviewbyid(r.id.pager1); mypager.setadapter(adapter); mypager.setcurrentitem(0); t1.settext(r.raw.jobs); } private class mypageradapter extends pageradapter { public int getcount() { return 4; } public object instantiateitem(view collection, int position) { layoutinflater inflater = (layoutinflater) collection.getcontext() .getsystemservice(context.layout_inflater_service); int resid = 0; switch (position) { case 0: resid = r.layout.activity_stories; break; case 1: resid = r.layout.sto2; break; case 2: resid = r.layout.sto3; break; case 3: resid = r.layout.sto4; break; } view view = inflater.inflate(resid, null); ((viewpager) collection).addview(view, 0); return view; } public void destroyitem(view arg0, int arg1, object arg2) { ((viewpager) arg0).removeview((view) arg2); } public boolean isviewfromobject(view arg0, object arg1) { return arg0 == ((view) arg1); } public parcelable savestate() { return null; } } }
here's pager xml file.
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".stories" > <android.support.v4.view.viewpager android:id="@+id/pager1" android:layout_width="match_parent" android:layout_height="match_parent" /> </relativelayout>
access textview after setcontentview , that'll it.