多个标记

时间:2012-02-22 11:24:18

标签: java android

我得到这个错误:

 "Multiple markers at this line
- Syntax error, insert ";" to complete 
 LocalVariableDeclarationStatement
- Syntax error, insert "}" to complete ClassBody
- Syntax error, insert "}" to complete ClassBody
- Syntax error, insert ";" to complete 
 LocalVariableDeclarationStatement"

我没有得到任何遗失

TimerTask getMessagesTask=new TimerTask() {
            this.runOnUiThread(new Runable(){


            @Override
            public void run() {

                      newMessages=connectToserverforincomingmsgs( getmsgurl, chatnumber);
                        TextView tv=new TextView(Chat.this);                   
                        tv.setText(chatnumber+":"+newMessages);
                        LayoutParams param=new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
                        tv.setLayoutParams(param);
                        ((LinearLayout)findViewById(R.id.ll_chat)).addView(tv);

        }});    
  

块引用

1 个答案:

答案 0 :(得分:0)

试试这个:

final Runnable doTaskRunnable = new Runnable() {
            public void run() {
                 newMessages=connectToserverforincomingmsgs( getmsgurl, chatnumber);
                 TextView tv=new TextView(Chat.this);                   
                 tv.setText(chatnumber+":"+newMessages);
                 LayoutParams param=new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
                 tv.setLayoutParams(param);
                 ((LinearLayout)findViewById(R.id.ll_chat)).addView(tv);
            }
        };

        TimerTask getMessagesTask = new TimerTask(){
            public void run() {
                MainActivity.this.runOnUiThread(doTaskRunnable);
            }
        };

此代码将起作用,因为TimerTask和Runnable都要求您实现run方法,因此您需要两个run方法。