android - Error trying to change password hint font -
i'm trying follow advice post:
but when run code, program crashes. here code:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); /* change font password hint match of * user name field */ edittext pw = (edittext) findviewbyid(r.id.password); pw.settypeface(typeface.default); //<---crashes on line pw.settransformationmethod(new passwordtransformationmethod()); setcontentview(r.layout.activity_main); }
here xml object:
<edittext android:id="@+id/password" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/username" android:layout_alignright="@+id/appname" android:layout_below="@+id/username" android:layout_margintop="14dp" android:ems="10" android:hint="@string/password" android:inputtype="textpassword" />
and finally, here logcat output can see error:
05-09 00:30:21.408: e/trace(16987): error opening trace file: no such file or directory (2) 05-09 00:30:21.918: d/androidruntime(16987): shutting down vm 05-09 00:30:21.918: w/dalvikvm(16987): threadid=1: thread exiting uncaught exception (group=0x40a71930) 05-09 00:30:21.978: e/androidruntime(16987): fatal exception: main 05-09 00:30:21.978: e/androidruntime(16987): java.lang.runtimeexception: unable start activity componentinfo{com.mobilenicity.gen_co_event_marketing_app/com.mobilenicity.gen_co_event_marketing_app.mainactivity}: java.lang.nullpointerexception 05-09 00:30:21.978: e/androidruntime(16987): @ android.app.activitythread.performlaunchactivity(activitythread.java:2180) 05-09 00:30:21.978: e/androidruntime(16987): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 05-09 00:30:21.978: e/androidruntime(16987): @ android.app.activitythread.access$600(activitythread.java:141) 05-09 00:30:21.978: e/androidruntime(16987): @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 05-09 00:30:21.978: e/androidruntime(16987): @ android.os.handler.dispatchmessage(handler.java:99) 05-09 00:30:21.978: e/androidruntime(16987): @ android.os.looper.loop(looper.java:137) 05-09 00:30:21.978: e/androidruntime(16987): @ android.app.activitythread.main(activitythread.java:5041) 05-09 00:30:21.978: e/androidruntime(16987): @ java.lang.reflect.method.invokenative(native method) 05-09 00:30:21.978: e/androidruntime(16987): @ java.lang.reflect.method.invoke(method.java:511) 05-09 00:30:21.978: e/androidruntime(16987): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 05-09 00:30:21.978: e/androidruntime(16987): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 05-09 00:30:21.978: e/androidruntime(16987): @ dalvik.system.nativestart.main(native method) 05-09 00:30:21.978: e/androidruntime(16987): caused by: java.lang.nullpointerexception 05-09 00:30:21.978: e/androidruntime(16987): @ com.mobilenicity.gen_co_event_marketing_app.mainactivity.oncreate(mainactivity.java:26) 05-09 00:30:21.978: e/androidruntime(16987): @ android.app.activity.performcreate(activity.java:5104) 05-09 00:30:21.978: e/androidruntime(16987): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) 05-09 00:30:21.978: e/androidruntime(16987): @ android.app.activitythread.performlaunchactivity(activitythread.java:2144) 05-09 00:30:21.978: e/androidruntime(16987): ... 11 more
can't figure out going wrong. can see it? thanks!
change call of setcontentview(r.layout.activity_main);
call just after super.oncreate(savedinstancestate);
when you're doing
edittext pw = (edittext) findviewbyid(r.id.password);
, findviewbyid
"can't retrieve" edittext
have defined in layout
(because call setcontentview
after) findviewbyid
returns null , when you're doing pw.settypeface(typeface.default);
throws npe
because pw null
.
Comments
Post a Comment