android - how to implement a button with a tab activity -



android - how to implement a button with a tab activity -

i have tab activity , in 1 of activities want place button take different activity. when code button (getting no errors) when launching app crashes error code:

11-14 12:50:43.783: e/androidruntime(10933): java.lang.runtimeexception: unable start activity componentinfo{com.dist.distguide/com.dist.distguide.mainactivity}: java.lang.nullpointerexception

however when remove button coding app launches fine.

here xml file:

<?xml version="1.0" encoding="utf-8"?> <tabhost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/logo1"> <linearlayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp"> <tabwidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <framelayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp" > <button android:id="@+id/distancecalc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="distance calculator" /> <button android:id="@+id/distance" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="distance calculator" /> </framelayout> </linearlayout> </tabhost>

and java:

intent intenthome = new intent().setclass(this, homeactivity.class); tabspec tabspechome = tabhost .newtabspec("home") .setindicator("", ressources.getdrawable(r.drawable.icon_home_config)) .setcontent(intenthome); button add together = (button)findviewbyid(r.id.distance1); add.bringtofront(); add.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { intent myintent = new intent(mainactivity.this,distancecalc.class); startactivity(myintent); } });

what doing wrong here? please help! give thanks you

change

button add together = (button)findviewbyid(r.id.distance1);

to

button add together = (button)findviewbyid(r.id.distancecalc);

your button id distancecalc. , you're trying initialize distance1.

android android-intent

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -