java - NullPointerException on TextView using setText() -
i'm rather new android programming, , running old friend nullpointerexception...
i've been on quite while now, can't figure out wrong.
basicly gives me nullpointerexception when try call .settext() methods, maybe sees i'm doing wrong here...(though tried follow examples close possible)
public class lessonview extends activity { textview adressoflecture; textview lecturer; textview lesson; lecture lecture; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_lesson_view); bundle data = getintent().getextras(); lecture = (lecture) data.getparcelable("student"); adressoflecture = (textview)findviewbyid(r.id.lectureviewadresslabel); lecturer = (textview)findviewbyid(r.id.lectureviewlecturerlabel); lesson = (textview)findviewbyid(r.id.lectureviewtitle); updatelabels(); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_lesson_view, 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(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } private void updatelabels(){ adressoflecture.settext(lecture.getroom()); lecturer.settext(lecture.gettutor()); lesson.settext(lecture.getname()); } } also, here's 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:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" tools:context="com.coronarip7.app.stupla.lessonview"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="(ort)" android:id="@+id/lectureviewadresslabel" android:layout_centervertical="true" android:layout_tostartof="@+id/lectureviewtitle" android:layout_marginright="86dp" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="dozent" android:id="@+id/lectureviewlecturerlabel" android:layout_toendof="@+id/lectureviewtitle" android:layout_aligntop="@+id/lectureviewadresslabel" android:layout_alignparentend="true" android:layout_marginright="27dp" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/lectureviewtitle" android:gravity="center_horizontal" android:text="test" android:textsize="40dp" android:textstyle="bold" android:padding="10dp" android:layout_row="0" android:layout_column="0" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" /> and logcat i'm getting:
04-25 01:23:51.058 12236-12236/com.coronarip7.app.stupla e/androidruntime﹕ fatal exception: main process: com.coronarip7.app.stupla, pid: 12236 java.lang.runtimeexception: unable start activity componentinfo{com.coronarip7.app.stupla/com.coronarip7.app.stupla.lessonview}: java.lang.nullpointerexception @ android.app.activitythread.performlaunchactivity(activitythread.java:2215) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2265) @ android.app.activitythread.access$800(activitythread.java:145) @ android.app.activitythread$h.handlemessage(activitythread.java:1206) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5081) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:781) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:597) @ dalvik.system.nativestart.main(native method) caused by: java.lang.nullpointerexception @ com.coronarip7.app.stupla.lessonview.updatelabels(lessonview.java:59) @ com.coronarip7.app.stupla.lessonview.oncreate(lessonview.java:31) @ android.app.activity.performcreate(activity.java:5231) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1087) @ android.app.activitythread.performlaunchactivity(activitythread.java:2169) at android.app.activitythread.handlelaunchactivity(activitythread.java:2265) at android.app.activitythread.access$800(activitythread.java:145) at android.app.activitythread$h.handlemessage(activitythread.java:1206) at android.os.handler.dispatchmessage(handler.java:102) at android.os.looper.loop(looper.java:136) at android.app.activitythread.main(activitythread.java:5081) at java.lang.reflect.method.invokenative(native method) at java.lang.reflect.method.invoke(method.java:515) at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:781) at com.android.internal.os.zygoteinit.main(zygoteinit.java:597) at dalvik.system.nativestart.main(native method) seriously, out of ideas on how fix it...
first check if put in intent. use following test in oncreate method:
intent intent = getintent(); if (intent.hasextra("student")){ lecture = (lecture) intent.getparcelableextra("student"); } then test if lecture null rami wrote earlier.
Comments
Post a Comment