I'm trying to update the text of a TextView through a function, but I'm getting an error just after the line Log.i ("UPDATE", "- 1 -"); (line 12) The code should work perfectly when I called the update () function but for some reason the error.
public void atualizar(){
Log.i("ATUALIZAR","-0-"+Usuario.retorneINFO());
if(Usuario.retorneINFO() != null){
JSONObject object = (JSONObject) new JSONTokener(Usuario.retorneINFO()).nextValue();
String chat = object.getString("1");
chat = chat.replaceAll("!hx01", " "); // troca todos os !hx01 por um espaço em branco
chat = chat.replaceAll("!hx02", "'");
chat = chat.replaceAll("!hx03", "\"");
Log.i("ATUALIZAR","-1-");
TextView msg = (TextView) findViewById(R.id.message);
msg.setText(chat);
Log.i("ATUALIZAR","-2-");
new Connect().execute("http://animesslife.engine001.com/chat/get_chat.php");
Log.i("ATUALIZAR","-3-");
}
}
In short, I need to update the text of this TextView msg.setText (chat) by calling it through a function
- I tried to put (View v) as parameter of function update () but did not work
Is it possible to do this or within a function called by .xml? Thanks
EDIT: This is my xml
<Button android:id="@+id/Enviar" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:onClick="Send" android:text="Enviar" /> <EditText android:id="@+id/AreaDeTexto" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_toLeftOf="@+id/Enviar" android:inputType="text" > <requestFocus /> </EditText> <ScrollView android:id="@+id/scrollView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/Enviar" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentTop="true" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/message" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> </ScrollView>