eclipse - Android application: "The Application has stopped unexpectedly" - using setText() method -
this question has answer here:
i have problem android application. if use settext() method textview have problem like: application has stopped unexpectedly. please try again.
code of application:
public class tc1 extends actionbaractivity { private textview textview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_tc1); if (savedinstancestate == null) { getsupportfragmentmanager().begintransaction() .add(r.id.container, new placeholderfragment()).commit(); } textview = (textview)findviewbyid(r.id.textview); textview.settext("hi"); // wrong line } ... }
xml fragment:
<relativelayout 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:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="com.example.tc.tc1$placeholderfragment" > <textview android:id="@+id/textview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:layout_marginleft="35dp" android:layout_margintop="20dp" android:text="text" /> </relativelayout>
your textview part of fragment xml try activity layout. move findviewbyid()
call oncreateview()
method of fragment.
for future questions: please not quote "the application has stopped unexpectedly"
instead check logcat
output error messages , stack traces. error message quoted default crashed information user, nothing provides detailed informations developers.
Comments
Post a Comment