mardi 4 août 2015

When i run my Fragment project, eclipse shows errors. I don't know how to fix it

Here is the instruction i tried to follow carefully:

http://ift.tt/1k5dyDx

here are the first errors appear in Logcat:

E/MoreInfoHPW_ViewGroup(21404): Parent view is not a TextView

E/AndroidRuntime(21404): FATAL EXCEPTION: main

E/AndroidRuntime(21404): Process: com.example.fragmentstest, PID: 21404

E/AndroidRuntime(21404): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fragmentstest/com.example.fragmentstest.MainActivity}: android.view.InflateException: Binary XML file line #20: Error inflating class fragment

here are my MainActivity and activity_main codes:

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
public void selectFrag(View view){
    Fragment fr;
    if (view == findViewById(R.id.button2)){
        fr = new FragmentTwo();
    } else {
        fr = new FragmentOne();
    }
    FragmentManager fm = getFragmentManager();
    FragmentTransaction fragmentTransaction = fm.beginTransaction();
    fragmentTransaction.replace(R.id.fragment_place, fr);
    fragmentTransaction.commit();


}  




<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<Button
    android:id="@+id/button1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Fragment No.1"
    android:onClick="selectFrag" />

<Button
    android:id="@+id/button2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Fragment No.2" 
    android:onClick="selectFrag"/>

<fragment 
    android:name="com.example.fragmentstest.FragmentOne"
    android:id="@+id/fragment_place"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>"

</LinearLayout>

Aucun commentaire:

Enregistrer un commentaire