部分代码:一Handler han = new Handler() {public void handleMessage(android.os.Message msg) {Toast.makeText(MessageActivity.this, "jinlail", Toast.LENGTH_LONG).show();LinearLayout client = new LinearLayout(MessageActivity.this);TextView t = new TextView(MessageActivity.this);t.setText(msg.getData().getString("username") + "说:");Button button = new Button(MessageActivity.this);button.setText("播放");final String filepath = msg.getData().getString("filename");button.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {MediaPlayer mediaPlayer = new MediaPlayer();if (mediaPlayer.isPlaying()) {mediaPlayer.reset();}try {mediaPlayer.setDataSource("/sdcard/" + filepath);mediaPlayer.prepare();mediaPlayer.start();} catch (Exception e) {// TODO: handle exception}}});client.setOrientation(LinearLayout.HORIZONTAL);client.addView(t);client.addView(button);line.addView(client);};};二protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);this.setContentView(R.layout.message);new Thread() {public void run() {UDPServer.message=MessageActivity.this;try {UDPServer.openServer();} catch (Exception e) {e.printStackTrace();}};}.start();}三Message msg = new Message();Bundle b3 = new Bundle();b3.putString("username", s.split(",")[0]);b3.putString("filename", s.split(",")[1]);msg.setData(b3); message.han.sendMessage(msg);
1 回答
Cats萌萌
TA贡献1805条经验 获得超9个赞
光看这些只能判断如果 Handler里没有问题 UDPServer怎么调取的message Message里的han是否为空 你可以再好好看看, 主要看看 UDPServer.openServer();跟Message的初始化方法,看看message.han是否为空
- 1 回答
- 0 关注
- 123 浏览
添加回答
举报
0/150
提交
取消