Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 多重标记_Java_Android - Fatal编程技术网

Java 多重标记

Java 多重标记,java,android,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 compl

我犯了这样的错误:

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

        }});    
区块报价

试试这个:

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方法。

在末尾添加一个括号“{”以关闭TimerTask