首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

高手来帮忙看下这个异常是为什么,跟着视频学的

2013-09-04 
高手来帮忙看下这个错误是为什么,跟着视频学的package com.example.handleractivityimport android.os.Bu

高手来帮忙看下这个错误是为什么,跟着视频学的
package com.example.handleractivity;

import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {


private Button startbutton=null;
private Button endbutton=null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        startbutton=(Button)findViewById(R.id.StartButton);
        startbutton.setOnClickListener(new StartButtonjt());
        endbutton=(Button)findViewById(R.id.EndButton);
        endbutton.setOnClickListener(new endbuttonjt());
    }

    class StartButtonjt implements OnClickListener{

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
handler.post(updateThread);}
    
    }
    class endbuttonjt implements OnClickListener{

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
handler.removeCallbacks(updateThread);
}
    
    }
    
    Handler handler=new Handler();
    Runnable updateThread=new Runnable(){

@Override
public void run() {
// TODO Auto-generated method stub
System.out.print("updateThread");
handler.postDelayed(updateThread,3000);

}
    
    };

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.


        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}


   我是看视频敲的代码跟视频一样  但是为什么我的 startbutton.setOnClickListener报错{The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (MainActivity.StartButtonjt)},
 class StartButtonjt 也报错{The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (MainActivity.StartButtonjt)},
onclick也报错{The method onClick(View) of type MainActivity.StartButtonjt must override or implement a supertype method}
[解决办法]
import android.content.DialogInterface.OnClickListener;
import android.view.View.OnClickListener;

热点排行