IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

probleme avec fragment


Sujet :

Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    178
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 178
    Par défaut probleme avec fragment
    bonjour;
    je n'arrive pas a me sortir de ce probleme ou tout me semble correct.voici mon code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    package com.example.auger.fragment2;
     
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
     
    public class MainActivity extends AppCompatActivity {
     
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
     
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.menu_main, menu);
            return true;
        }
     
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
     
            //noinspection SimplifiableIfStatement
            if (id == R.id.action_settings) {
                return true;
            }
     
            return super.onOptionsItemSelected(item);
        }
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <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"
        android:orientation="vertical"
        tools:context=".MainActivity">
        <fragment
            android:name="com.example.auger.fragment2.Detail"
            android:id="@+id/fragment"
            android:layout_height="match_parent"
            android:layout_width="match_parent">
        </fragment>
    </LinearLayout>
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">
     
        <ListView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/listView" />
    </LinearLayout>
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    public class Detail extends ListFragment {
        String[] presidents = {
                "Dwight D. Eisenhower",
                "John F. Kennedy",
                "Lyndon B. Johnson",
                "Richard Nixon",
                "Gerald Ford",
                "Jimmy Carter",
                "Ronald Reagan",
                "George H. W. Bush",
                "Bill Clinton",
                "George W. Bush",
                "Barack Obama"
        };
        @Override
        public View onCreateView(LayoutInflater inflater,
                                 ViewGroup container, Bundle savedInstanceState) {
            View v=inflater.inflate(R.layout.detail, container, false);
            return v;
        }
     
        @Override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            ArrayAdapter<String>adapter=new ArrayAdapter<String>(getActivity(),
                    android.R.layout.simple_list_item_1, presidents);
            setListAdapter(adapter);
     
        }
     
    }
    j'obtiens l'erreur;
    Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment

  2. #2
    Modérateur
    Avatar de MasterMbg
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2011
    Messages
    719
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Congo-Kinshasa

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2011
    Messages : 719
    Par défaut
    Salut,

    peux tu afficher le message complet de l'erreur (copie du logcat) stp?

    Christian,
    Plus tu apprends sérieusement, plus tu te rapproches d'un savoir noble. Une chose est certaine, les difficultés ne s'écarteront de ton chemin...

    Tu es nouveau dans le développement Android, la page des COURS est là pour te faciliter la vie
    Tu peux trouver la réponse à ta question dans la FAQ
    Retrouvez mon tutoriel sur la consommation des services web SOAP
    Pense à voter positivement en appuyant sur en bas à droite de la réponse qui t'a donné une piste de solution.

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    178
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 178
    Par défaut
    merci pour ta réponse voici le message:
    Process: com.example.auger.fragment2, PID: 2553
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.auger.fragment2/com.example.auger.fragment2.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2329)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
    at android.app.ActivityThread.access$900(ActivityThread.java:147)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5254)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
    Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
    at com.example.auger.fragment2.MainActivity.onCreate(MainActivity.java:13)
    at android.app.Activity.performCreate(Activity.java:5933)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2282)
    ************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
    ************at android.app.ActivityThread.access$900(ActivityThread.java:147)
    ************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
    ************at android.os.Handler.dispatchMessage(Handler.java:102)
    ************at android.os.Looper.loop(Looper.java:135)
    ************at android.app.ActivityThread.main(ActivityThread.java:5254)
    ************at java.lang.reflect.Method.invoke(Native Method)
    ************at java.lang.reflect.Method.invoke(Method.java:372)
    ************at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
    ************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
    Caused by: java.lang.RuntimeException: Content has view with id attribute 'android.R.id.list' that is not a ListView class
    at android.app.ListFragment.ensureList(ListFragment.java:402)
    at android.app.ListFragment.onViewCreated(ListFragment.java:203)
    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:875)
    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1045)
    at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1147)
    at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2116)
    at android.app.Activity.onCreateView(Activity.java:5282)
    at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(AppCompatDelegateImplV11.java:41)
    at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:830)
    at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
    ************at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
    ************at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
    ************at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
    ************at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
    ************at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
    ************at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
    ************at com.example.auger.fragment2.MainActivity.onCreate(MainActivity.java:13)
    ************at android.app.Activity.performCreate(Activity.java:5933)
    ************at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
    ************at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2282)
    ************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
    ************at android.app.ActivityThread.access$900(ActivityThread.java:147)
    ************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
    ************at android.os.Handler.dispatchMessage(Handler.java:102)
    ************at android.os.Looper.loop(Looper.java:135)
    ************at android.app.ActivityThread.main(ActivityThread.java:5254)
    ************at java.lang.reflect.Method.invoke(Native Method)
    ************at java.lang.reflect.Method.invoke(Method.java:372)
    ************at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
    ************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)

  4. #4
    Membre chevronné
    Profil pro
    Inscrit en
    Juillet 2012
    Messages
    476
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2012
    Messages : 476
    Par défaut
    Le message est clair
    Caused by: java.lang.RuntimeException: Content has view with id attribute 'android.R.id.list' that is not a ListView class
    L'id de ta listview est "listView" au lieu de " "@android:id/list" puisque tu utilises un listfragment

  5. #5
    Modérateur
    Avatar de MasterMbg
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2011
    Messages
    719
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Congo-Kinshasa

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2011
    Messages : 719
    Par défaut
    Change
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    <ListView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/listView" />
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    <ListView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@id/android:list" />
    Christian,
    Plus tu apprends sérieusement, plus tu te rapproches d'un savoir noble. Une chose est certaine, les difficultés ne s'écarteront de ton chemin...

    Tu es nouveau dans le développement Android, la page des COURS est là pour te faciliter la vie
    Tu peux trouver la réponse à ta question dans la FAQ
    Retrouvez mon tutoriel sur la consommation des services web SOAP
    Pense à voter positivement en appuyant sur en bas à droite de la réponse qui t'a donné une piste de solution.

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    178
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 178
    Par défaut
    merci de vos réponses
    est-ce parce que j'utilise simple_list_item 1(que je n'avais jamais utilisé) que je dois changer l'id

Discussions similaires

  1. probleme avec fragment
    Par kapac dans le forum Android
    Réponses: 2
    Dernier message: 02/04/2014, 14h27
  2. Probleme avec la copie des surfaces
    Par Black_Daimond dans le forum DirectX
    Réponses: 3
    Dernier message: 09/01/2003, 10h33
  3. probleme avec la touche F10
    Par b.grellee dans le forum Langage
    Réponses: 2
    Dernier message: 15/09/2002, 22h04
  4. Probleme avec fseek
    Par Bjorn dans le forum C
    Réponses: 5
    Dernier message: 04/08/2002, 07h17
  5. [Kylix] probleme avec un imagelist
    Par NicoLinux dans le forum EDI
    Réponses: 4
    Dernier message: 08/06/2002, 23h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo