我是多人編程中的新手。如何將String
設置爲hashmap值?我想從RoomListActivity調用hashmap屬性,並在QuizMaintain活動上設置它的值,並且我想將QuizMaintain類的hashmap值設置爲textview。下面是我的示例代碼Appwarp Android編程從房間列表中獲取屬性
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);
}
價值我想設置的HashMap值,其中的關鍵是「問題」。而我想要設置的值來自拆分字符串。當我詢問他們的支持團隊,如果我想獲得房間屬性,我應該調用getLiveRoomInfo方法並傳遞roomID作爲參數。這裏有點困惑。謝謝。
但似乎我的問題還沒有解決。在調用方法updateRoomProperties之後,我在這裏得到了另一個錯誤。這就是說WarpClient.AddZoneRequestListener(this)返回空指針異常