0

I'm new in Multiplayer programming. How to set String into hashmap value ? I want to call hashmap properties from RoomListActivity and set it's value on QuizMaintain activity and also I want to set hashmap value from QuizMaintain class to textview. Here's my sample code

RoomListActivity

public void onJoinNewRoomClicked(View view){
    progressDialog = ProgressDialog.show(this,"","Please wait...");
    progressDialog.setCancelable(true);

    HashMap<String, Object> properties = new HashMap<String, Object>();
    properties.put("timer", "");
    properties.put("question", "");
    properties.put("answer", "");
    properties.put("foulanswer", "");


    theClient.createRoom(""+System.currentTimeMillis(), "Yoshua", 2, properties);
}

Then I want to set it's value from QuizMaintain activity

public class QuizMaintain extends Activity implements RoomRequestListener, NotifyListener {

private WarpClient theClient;
private HashMap<String, Object> properties;
private TextView txttimer,txtquestion;
private String roomId = ""; 
private HashMap<String, User> userMap = new HashMap<String, User>();
String string="5x5#5x4#150:3#500:20#536+59";
String[] questions = string.split("#");
String question1 = questions[0];
String question2 = questions[1];
String question3 = questions[2];
String question4 = questions[3];
String question5 = questions[4];


@Override
public void onCreate(Bundle savedInstanceState){
     super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_quiz_maintain);
        txttimer = (TextView)findViewById(R.id.timer);
        txtquestion = (TextView)findViewById(R.id.questionview);


        try{
            theClient = WarpClient.getInstance();
        }catch(Exception e){
            e.printStackTrace();
        }

        theClient.getLiveRoomInfo("143680827");
        Intent intent = getIntent();
        roomId = intent.getStringExtra("roomId");
        init(roomId);

        //setquestionview();






}



private void init(String roomId){
    if(theClient!=null){
        theClient.addRoomRequestListener(this);
        theClient.addNotificationListener(this);
        theClient.joinRoom(roomId);
    }
}



@Override
public void onGetLiveRoomInfoDone(LiveRoomInfoEvent event) {
    properties = event.getProperties();
    properties.put("question", question1);

}

I want to set hashmap value where is the key are "question". And the value that i want to set are from split string.When I ask their support team if I want to get room properties I should call getLiveRoomInfo method and pass roomID as argument. A bit confused here. Thanks.

But it seems my problem are not solved yet. After call method updateRoomProperties but I got another error here. It's say WarpClient.AddZoneRequestListener(this) return null pointer exception

1 Answers1

0

When you are creating a room you are passing a hashmap. This hashmap is stored as a JSON document inside the room on server. AppWarp calls it Room Properties.

Now to retrieve these properties you have to call getLiveRoomInfo method. This will present you the room properties. Here you are adding/changing some key-value again. But you haven't told the server that you are updating these room properties. Therefore your changes remain local and that too limited to the scope of function.

So, when you call the getLiveRoomInfo method, you won't see the changes as you haven't updated them on server. To update on server, you need to call updateRoomProperties method. In this method you can add or change your hashmap.

Suyash Mohan
  • 310
  • 3
  • 10