android - java.lang.NullPointerException while running the app after creating layout-land folder -
i have xml working in portrait mode. created 1 more folder landscape layout-land , added same xml , made changes according landscape mode, when run app getting following error.
03-18 09:30:59.276: e/androidruntime(5753): fatal exception: main 03-18 09:30:59.276: e/androidruntime(5753): java.lang.runtimeexception: unable start activity componentinfo{com.netserv.pungry/com.netserv.pungry.restaurantdetails}: java.lang.nullpointerexception 03-18 09:30:59.276: e/androidruntime(5753): @ android.app.activitythread.performlaunchactivity(activitythread.java:2180) 03-18 09:30:59.276: e/androidruntime(5753): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 03-18 09:30:59.276: e/androidruntime(5753): @ android.app.activitythread.access$600(activitythread.java:141) 03-18 09:30:59.276: e/androidruntime(5753): @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 03-18 09:30:59.276: e/androidruntime(5753): @ android.os.handler.dispatchmessage(handler.java:99) 03-18 09:30:59.276: e/androidruntime(5753): @ android.os.looper.loop(looper.java:137) 03-18 09:30:59.276: e/androidruntime(5753): @ android.app.activitythread.main(activitythread.java:5041) 03-18 09:30:59.276: e/androidruntime(5753): @ java.lang.reflect.method.invokenative(native method) 03-18 09:30:59.276: e/androidruntime(5753): @ java.lang.reflect.method.invoke(method.java:511) 03-18 09:30:59.276: e/androidruntime(5753): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 03-18 09:30:59.276: e/androidruntime(5753): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 03-18 09:30:59.276: e/androidruntime(5753): @ dalvik.system.nativestart.main(native method) 03-18 09:30:59.276: e/androidruntime(5753): caused by: java.lang.nullpointerexception 03-18 09:30:59.276: e/androidruntime(5753): @ com.netserv.pungry.restaurantdetails.oncreate(restaurantdetails.java:44) 03-18 09:30:59.276: e/androidruntime(5753): @ android.app.activity.performcreate(activity.java:5104) 03-18 09:30:59.276: e/androidruntime(5753): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) 03-18 09:30:59.276: e/androidruntime(5753): @ android.app.activitythread.performlaunchactivity(activitythread.java:2144) 03-18 09:30:59.276: e/androidruntime(5753): ... 11 more
here xml.
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="right" android:orientation="vertical" android:weightsum="1.0" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:background="@color/headerbgcolor" android:weightsum="1.0" > <button android:id="@+id/restaurant_back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0.2" android:text="@string/back" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="0.6" android:gravity="center" android:text="@string/restauran_details" /> <button android:id="@+id/restaurant_home" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0.2" android:text="@string/home" /> </linearlayout> <relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <button android:id="@+id/refresh" android:layout_width="wrap_content" android:layout_height="20dp" android:gravity="left" android:text="@string/refresh" /> </relativelayout> <linearlayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:weightsum="1"> <textview android:layout_width="fill_parent" android:layout_height="30dp" android:text="@string/restaurant_name" /> <textview android:layout_width="fill_parent" android:layout_height="match_parent" android:text="@string/restaurant_address" /> </linearlayout> <scrollview android:layout_width="fill_parent" android:layout_height="wrap_content" > <linearlayout android:layout_width="match_parent" android:layout_height="200dp" android:orientation="vertical" android:weightsum="1" > <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/restaurant_rating" android:layout_weight="0.1" /> <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/restaurant_timings" android:layout_weight="0.1" /> <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/cost_for_two" android:layout_weight="0.1" /> <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/restaurant_cuisine" android:layout_weight="0.1" /> <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/restaurant_location" android:layout_weight="0.1" /> <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/restaurant_city" android:layout_weight="0.1" /> </linearlayout> </scrollview> <textview android:layout_width="fill_parent" android:layout_height="20dp" android:text="@string/restaurant_phone" /> <!-- <relativelayout --> <!-- android:layout_width="fill_parent" --> <!-- android:layout_height="wrap_content" > --> <!-- <imageview --> <!-- android:id="@+id/imageview1" --> <!-- android:layout_width="fill_parent" --> <!-- android:layout_height="wrap_content" --> <!-- android:layout_alignparentbottom="true" --> <!-- android:background="#808000" --> <!-- android:src="@drawable/btn_bg_cuisine" /> --> <!-- </relativelayout> --> </linearlayout>
here restaurantdetails class
protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.restaurantdetails); btnback = (button) findviewbyid(r.id.back); btnhome = (button) findviewbyid(r.id.restaurant_home); btnrefresh = (button) findviewbyid(r.id.refresh); btnrefresh.setvisibility(view.gone); restaurant_name = (textview) findviewbyid(r.id.restaurant_name); restaurant_add = (textview) findviewbyid(r.id.restaurant_add); restaurant_costfortwo = (textview) findviewbyid(r.id.restaurant_cstfortwo); restaurant_rating = (textview) findviewbyid(r.id.restaurant_rating); restaurant_timings = (textview) findviewbyid(r.id.restaurant_timings); restaurant_phone = (textview) findviewbyid(r.id.restaurant_phone); restaurant_phone.setautolinkmask(linkify.phone_numbers); restaurant_phone.setlinksclickable(true); restaurant_locationname = (textview) findviewbyid(r.id.restaurant_location); restaurant_cityname = (textview) findviewbyid(r.id.restaurant_city); restaurant_cuisinename = (textview) findviewbyid(r.id.restaurant_cuisine); imgfooter = (imageview) findviewbyid(r.id.footerimage); btnhome.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { startactivity(new intent(restaurantdetails.this, home.class)); } }); restaurant_name.settext(globvariables.restaurant_response .get(globvariables.restaurantname).restaurant_name); restaurant_add.settext(globvariables.restaurant_response .get(globvariables.restaurantname).address); restaurant_costfortwo.settext(globvariables.restaurant_response .get(globvariables.restaurantname).costoftwo); restaurant_rating.settext(globvariables.restaurant_response .get(globvariables.restaurantname).rating); restaurant_timings.settext(globvariables.restaurant_response .get(globvariables.restaurantname).timings); restaurant_phone.settext(globvariables.restaurant_response .get(globvariables.restaurantname).phone); restaurant_locationname.settext(globvariables.restaurant_response .get(globvariables.restaurantname).location_name); restaurant_cityname.settext(globvariables.restaurant_response .get(globvariables.restaurantname).city_name); restaurant_cuisinename.settext(globvariables.restaurant_response .get(globvariables.restaurantname).cuisine_name);
can know what's mistake doing?.. thanks:)
error in btnback = (button) findviewbyid(r.id.back);
.
there no button has id back
in layout xml.
i think want use restaurant_back
btnback = (button) findviewbyid(r.id.restaurant_back);
.
also textview should have id in xml layout.
restaurant_name = (textview) findviewbyid(r.id.restaurant_name); restaurant_add = (textview) findviewbyid(r.id.restaurant_add); restaurant_costfortwo = (textview) findviewbyid(r.id.restaurant_cstfortwo); restaurant_rating = (textview) findviewbyid(r.id.restaurant_rating); restaurant_timings = (textview) findviewbyid(r.id.restaurant_timings); restaurant_phone = (textview) findviewbyid(r.id.restaurant_phone); restaurant_locationname = (textview) findviewbyid(r.id.restaurant_location); restaurant_cityname = (textview) findviewbyid(r.id.restaurant_city); restaurant_cuisinename = (textview) findviewbyid(r.id.restaurant_cuisine); , image view imgfooter = (imageview) findviewbyid(r.id.footerimage);
add in xml layout android:id="@+id/...."
<.... android:id="@+id/...." . . . />
Comments
Post a Comment