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 :

ExpandListView Adapter - avec hash map ne marche pas


Sujet :

Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre à l'essai
    Femme Profil pro
    Développeur .NET
    Inscrit en
    Février 2015
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 42
    Localisation : Vietnam

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Février 2015
    Messages : 4
    Par défaut ExpandListView Adapter - avec hash map ne marche pas
    Bonjour,

    J`ai personalise l`adapter et j`ai les erreurs.
    J`arrive pas a trouver pourquoi C`est quoi l`erreur. Est-ce que sa vient de l`adapter? Comme j`ai personalise cette derniere, je ne sais pas trop si j`a bien fait.

    java.lang.RuntimeException: Unable to start activity
    ComponentInfo{MyProject/MyProject.MainActivity}:
    java.lang.NullPointerException
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
    at android.app.ActivityThread.access$800(ActivityThread.java:135)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5001)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.NullPointerException
    at MyProject.EventListFragment.Data(EventListFragment.java:124)
    at MyProject.EventListFragment.onCreateView(EventListFragment.java:146)
    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:953)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136)
    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499)
    at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:548)
    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
    at android.app.Activity.performStart(Activity.java:5241)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2157)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
    at android.app.ActivityThread.access$800(ActivityThread.java:135)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5001)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    at dalvik.system.NativeStart.main(Native Method)

    EventListFragment

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
    View view = inflater.inflate(R.layout.fragment_event_list, container, false);
    expandableList = (ExpandableListView) view.findViewById(R.id.expandableView);
    getActivity().setTitle("All");
     
    ExpandableListViewAdapter expandableListAdapter = new ExpandableListViewAdapter(getActivity());
    expandableList.setAdapter(expandableListAdapter);
    Data();
    return view;
    }
    Data()
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    public void Data() {     
    ArrayList<ProductItem> productsList = new ArrayList<>();
    for (String val : Client.data.keySet()) {
    ProductItem dataItem = Client.data.get(val);
    productsList.add(dataItem);
    }
    }
    expandableList.setAdapter(new ExpandableListViewAdapter(getActivity(),productsList));
    }
    Adapter

    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    public class ExpandableListViewAdapter extends BaseExpandableListAdapter
    {  
    private LayoutInflater inflater;
    InterFragmentNavigator interFragmentNavigator;
    ArrayList<ProductItem> dataList = new ArrayList<>();  
    private HashMap<String, ProductItem> listDataChild;
     
    public ExpandableListViewAdapter(Context context) {
    this.context = context;
    }
    public ExpandableListViewAdapter(Context context,ArrayList<ProductItem> filteredList, boolean showDateAndTime)
    {
    HashMap<String, ProductItem> listDataChild = new HashMap<String, ProductItem>();
    for (ProductItem data : filteredList) {
        this.listDataChild.put(data.Name, data);
    }
     
    for (ProductItem data: filteredList) {
        listDataHeader.add(data.Name);
    }
     
    this.context=context;
    inflater = LayoutInflater.from(context);
    this.interFragmentNavigator = ((InterFragmentNavigator) context);
     
    this.showDateAndTime = showDateAndTime;
    }
    @Override
    public Object getChild(int groupPosition, int childPosition) {
    return listDataChild.get(this.listDataHeader.get(groupPosition));
    }
     
     
    @Override
    public long getChildId(int groupPosition, int childPosition) {
    return childPosition;
    }
     
     
    @Override
    public View getChildView(int groupPosition, int childPosition,
                        boolean isLastChild, View convertView, ViewGroup parent) {
    final String childText=(String)getChild(groupPosition, childPosition);
    ChildViewHolder childViewHolder;
    if(convertView == null) {
    childViewHolder = new ChildViewHolder();
    LayoutInflater inflater=(LayoutInflater)this.context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
     
    convertView = inflater.inflate(R.layout.group_child, null);
     
    childViewHolder.Name = (TextView) convertView.findViewById(R.id.Name);
    childViewHolder.Description = (TextView) convertView.findViewById(R.id.description);
     
    convertView.setTag(childViewHolder);
    }
    else {
    childViewHolder = (ChildViewHolder) convertView.getTag();
    }
     
    childViewHolder.Name.setText(listDataChild.get(childPosition).Name.toUpperCase());
    childViewHolder.Description.setText(listDataChild.get(childPosition).Description);      
     
    return convertView;
    }  
    @Override
    public int getChildrenCount(int groupPosition) {
    return listDataChild.size();
    }
     
    @Override
    public Object getGroup(int groupPosition) {
     
    return this.listDataHeader.get(groupPosition);
    }
     
    @Override
    public int getGroupCount() {
     
    return this.listDataHeader.size();
    }
     
    @Override
    public long getGroupId(int groupPosition) {
     
    return groupPosition;
    }
     
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
                        View convertView, ViewGroup parent) {
    GroupViewHolder groupHolder;
    if (convertView == null) {
     
    LayoutInflater inflater=(LayoutInflater)this.context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
    convertView=inflater.inflate(R.layout.group_row, null);
     
    groupHolder = new GroupViewHolder();
    groupHolder.Name = (TextView) convertView.findViewById(R.id.Name);        
     
    convertView.setTag(groupHolder);
    } else {
    groupHolder = (GroupViewHolder) convertView.getTag();
    }
     
    groupHolder.Name.setText((String) getGroup(groupPosition));     
    return convertView;
    }
     
     
     
    @Override
    public boolean hasStableIds() {
    return false;
    }
    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
    return false;
    }
     
    class GroupViewHolder {
    public TextView Name;
    }
     
    class ChildViewHolder {
    public TextView Name;
    public TextView Description;       
    }    
    }

  2. #2
    Modérateur
    Avatar de grunk
    Homme Profil pro
    Lead dév - Architecte
    Inscrit en
    Août 2003
    Messages
    6 693
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Lead dév - Architecte
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2003
    Messages : 6 693
    Par défaut
    Comme le log l'indique tu as une valeur null ligne 124 de EventListFragment

    Caused by: java.lang.NullPointerException
    at MyProject.EventListFragment.Data(EventListFragment.java:124)
    Sans voir les lignes concernées dur d'en dire plus.
    Pry Framework php5 | N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  3. #3
    Membre à l'essai
    Femme Profil pro
    Développeur .NET
    Inscrit en
    Février 2015
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 42
    Localisation : Vietnam

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Février 2015
    Messages : 4
    Par défaut
    Les lists ne sont pas initialises. Merci

Discussions similaires

  1. [MySQL] condition avec requete qui ne marche pas ..sous ie
    Par esti89 dans le forum PHP & Base de données
    Réponses: 8
    Dernier message: 13/06/2008, 09h53
  2. Réponses: 0
    Dernier message: 06/06/2008, 17h03
  3. Comment compiler en 64 bits avec gcc, -m64 ne marche pas.
    Par jeanlouis_lecodeur dans le forum GCC
    Réponses: 1
    Dernier message: 27/02/2008, 17h40
  4. TabSheet avec enabled à false ne marche pas?
    Par codial dans le forum Delphi
    Réponses: 8
    Dernier message: 06/03/2007, 12h46
  5. aperçu d image avec input type file marche pas dans ffx
    Par siddh dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 09/11/2005, 09h11

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