textview - Null Object Preferences Edittext on Android -
i new android programming. @ bottleneck. trying chatapp. when click item these errors occur :
java.lang.nullpointerexception: attempt invoke virtual method 'void android.widget.edittext.setinputtype(int)' on null object reference @ com.senturk.fatih.chat03.chat.oncreate(chat.java:55)
and here line 55
txt.setinputtype(inputtype.type_class_text|inputtype.type_text_flag_multi_line);
and guess should add line txt=(edittext)findviewbyid(r.id.text);
thanks favor ,
private arraylist<conversation> convlist; private chatadapter adp; private edittext txt; private string buddy; private date lstmsgdate; private boolean isrunning; private static handler handler; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.chat); convlist=new arraylist<conversation>(); listview list=(listview)findviewbyid(r.id.list); adp=new chatadapter(); list.setadapter(adp); list.settranscriptmode(abslistview.transcript_mode_always_scroll); list.setstackfrombottom(true); txt=(edittext)findviewbyid(r.id.text); txt.setinputtype(inputtype.type_class_text|inputtype.type_text_flag_multi_line); settouchnclick(r.id.btnsend); buddy=getintent().getstringextra(const.extra_data); getactionbar().settitle(buddy); handler=new handler(); }
the xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout 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:orientation="vertical" android:background="@color/white"> <listview android:id="@+id/list" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:divider="@color/white" android:dividerheight="@dimen/pad_5dp" android:fastscrollenabled="true" android:paddingbottom="@dimen/pad_10dp" android:paddingtop="@dimen/pad_10dp" tools:listitem="@layout/chat_item_rcv" > </listview> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/gray_light" android:gravity="center_vertical" android:padding="@dimen/pad_5dp" tools:context=".mainactivity" > <edittext android:id="@+id/txt" style="@style/edittext_msg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:hint="@string/type_msg" > </edittext> <button android:id="@+id/btnsend" style="@style/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/send_telegram" /> </linearlayout> </linearlayout>
thanks posting layout xml. error caused fact should calling:
txt=(edittext)findviewbyid(r.id.txt);
and not
txt=(edittext)findviewbyid(r.id.text);
since don't have edittext
id in layout.
Comments
Post a Comment