Parcelable protocol requires a Parcelable.Creator object called CREATOR (I do have CREATOR)

后端 未结 6 640
天命终不由人
天命终不由人 2020-12-08 20:32

I am trying to pass Parcelable data from one intent to another and this is the error I am getting:

08-31 14:12:22.709: E/AndroidRuntime(9931): FATAL EXCEPTIO         


        
6条回答
  •  甜味超标
    2020-12-08 20:49

    Try this way

    // create List of player
            ArrayList> players = new ArrayList>();
    
            //create Player
    
            HashMap player = new HashMap();
            player.put("score", "20");//replace 20 with your score variable
            player.put("name", "Biraj");//replace Biraj with your name variable
    
            // Add to arraylist
    
            players.add(player);
    
            // pass to intent
    
            Intent i;
            i.putExtra("PLAYERS", players);
    
            // read From intent
    
            ArrayList> playerFromintent = (ArrayList>) getIntent().getSerializableExtra("PLAYERS");
    
            // read from ArrayList
    
            for (HashMap hashMap : playerFromintent) {
                System.out.println("Name : " + hashMap.get("name"));
                System.out.println("Score : " + hashMap.get("score"));
            }
    

提交回复
热议问题