2013-08-02 7 views
0

Je suis en train de mettre en œuvre un fragment de base et l'activité et il jette une erreur:Android Fragment donnant « erreur fragment de classe de gonflage »

Voici mes classes:

classe fragment:

public class MyFragment extends Fragment { 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    View view = inflater.inflate(R.layout._fragment_dds_image, container, false); 
    return view; 
} 

}

Mon fichier XML Fragment:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#0000FF" 
android:orientation="vertical" > 

Mon activité qui tente d'afficher le fragment:

public class DDSViewActivity extends FragmentActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_ddsview); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.ddsview, menu); 
    return true; 
}} 

Le fichier XML pour l'activité:

<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" > 

<fragment 
    android:id="@+id/fragment1" 
    android:name="dds.MyFragment" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" /> 

Quand je lance cela, il donne em l'erreur suivante:

Impossible de démarrer activty ComponentInfo {com.example.electronicmenu/dds.DDSViewActivity}: android.view.InflateException: ligne de fichier xml binaire # 10: Erreur lors du gonflement du fragment de classe.

link to full stack trace:

+0

Afficher la trace complète de la pile de logcat – Karakuri

+0

https://www.dropbox.com/s/sxtywgav3gbapm6/Error%20to%20Stack%20Trace.txt – Zapnologica

Répondre

0

Utilisez le nom complet de votre classe de fragments, par exemple com.example.myapp.dds.MyFragment

<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" > 

    <fragment 
     android:id="@+id/fragment1" 
     android:name="com.example.myapp.dds.MyFragment" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" /> 
+0

Comment puis-je trouver mon nom complet exact? J'ai essayé de le taper moi-même mais il a donné la même erreur – Zapnologica

+0

C'est le nom de votre classe de fragment incluant le paquet. – Karakuri

+0

Ne fonctionne toujours pas. J'ai même déplacé MyFragment dans le package par défaut. et puis changé le xml en: 'android: name =" com.example.electronicmenu.MyFragment "' – Zapnologica

Questions connexes