2012-10-08 4 views
1

J'ai quelques problèmes avec le fragment, je suis une erreur qui dit:fragment Fragment erreur de classe de gonflage

Binary XML file line #2 Error: inflating class fragment. 
Cause by: Java.lan.NullPointerException: name == null 

Ceci est mon fichier binaire:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 
    <fragment 
     android:id="@+id/fragment_content" 
     android:name="com.livetrekker.fragments.WelcomeFragment" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_weight="1" /> 
</LinearLayout> 

Alors mon FragmentActivity:

public class SetupWizard extends FragmentActivity{ 
    public void onCreate(Bundle bundle){ 
     super.onCreate(bundle); 
     setContentView(R.layout.activity_wizardsetup); 
     FragmentManager fragmentManager = getSupportFragmentManager(); 
     FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 

     WelcomeFragment wf = new WelcomeFragment(); 
     fragmentTransaction.add(R.id.fragment_content, wf); 

     fragmentTransaction.commit(); 
    } 
} 

Et enfin mon fragment:

Public class WelcomeFragment extends Fragment { 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ 
     return inflater.inflate(R.layout.welcomelivetrekker,container, false); 
    } 
} 

J'ai importé Android.support.v4.app.Fragment à la fois de mon fichier et vérifier sur Internet, mais aucune de la solution ne fonctionne.

Répondre

0

Votre activity_wizardsetup.xml devrait ressembler à ceci:

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/pager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity"> 
</android.support.v4.view.ViewPager> 

Ensuite, votre fragment_content.xml devrait ressembler à quelque chose à cet effet:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/test" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" /> 

</LinearLayout> 

Je crois que cela devrait fixer ... en mon code j'utilise un FragmentPagerAdapter plutôt que FragmentTransaction ou FragmentManager ... mais je pense que la fixation du xml fonctionnera ...

+0

cela fonctionne merci. Juste une petite erreur c'est Kalimero95

0

Je sais que c'est un vieux fil, mais Je pensais que je répondrais de toute façon, puisque la solution ici ne fonctionnait pas pour moi, mais le problème était le même.

Une exception était sur le gonflement du fragment, car le nom était nul. Le fragment doit avoir le champ suivant:

android:name="com.google.android.gms.maps.MapFragment" 

Source here.

Questions connexes