当前位置: 代码迷 >> Android >> 高手来帮忙看下这个异常是为什么,跟着视频学的
  详细解决方案

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

热度:12   发布时间:2016-05-01 09:57:46.0
高手来帮忙看下这个错误是为什么,跟着视频学的
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.
  相关解决方案