0

私はマルチプレイヤープログラミングの初心者です。Stringハッシュマップ値に設定するには? RoomListActivity から hashmap プロパティを呼び出し、その値を QuizMaintain アクティビティに設定し、ハッシュマップ値を QuizMaintain クラスから textview に設定したいと考えています。これが私のサンプルコードです

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);
}

次に、QuizMaintain アクティビティから値を設定したい

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);

}

キーが「質問」であるハッシュマップ値を設定したい。そして、設定したい値は分割文字列からのものです。サポートチームに部屋のプロパティを取得するかどうか尋ねるときは、getLiveRoomInfo メソッドを呼び出して、引数として roomID を渡す必要があります。ここで少し混乱。ありがとう。

しかし、私の問題はまだ解決されていないようです。メソッド updateRoomProperties を呼び出した後、ここで別のエラーが発生しました。WarpClient.AddZoneRequestListener(this) return null pointer exception と言います

4

1 に答える 1

0

ルームを作成するときは、ハッシュマップを渡します。このハッシュマップは、サーバー上のルーム内に JSON ドキュメントとして保存されます。AppWarp はこれを Room Properties と呼んでいます。

これらのプロパティを取得するには、getLiveRoomInfo メソッドを呼び出す必要があります。これにより、部屋のプロパティが表示されます。ここで、いくつかのキー値を再度追加/変更しています。ただし、これらの部屋のプロパティを更新していることをサーバーに伝えていません。したがって、変更はローカルのままであり、機能の範囲に限定されすぎます。

そのため、getLiveRoomInfo メソッドを呼び出しても、サーバー上で更新していないため、変更は表示されません。サーバーで更新するには、updateRoomProperties メソッドを呼び出す必要があります。このメソッドでは、ハッシュマップを追加または変更できます。

于 2014-10-30T06:34:52.057 に答える