您好我为我的游戏创建了一个天文台。问题是我创建了2个类。这不起作用。我有一个Exepction。
public class Crono1 extends Activity implements Callback{
public TextView txtTiempo;
public boolean detenido;
public boolean pausado;
private Handler handler;
String cronometro;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtTiempo = (TextView) findViewById(R.id.ConTiempo);
final Button btn = (Button) findViewById(R.id.BtnAccion);
final Button btnDetener = (Button) findViewById(R.id.BtnDetener);
detenido = false;
pausado = true;
handler = new Handler(this);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Tiempo w = new Tiempo (handler);
Thread t = new Thread (w);
t.start();
}
});
btnDetener.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
detenido = true;
txtTiempo.setText("00:00:00:00");
}
});
}
@Override
public boolean handleMessage(Message msg) {
TextView texto = (TextView) findViewById(R.id.ConTiempo);
Integer text = (Integer) msg.obj;
texto.setText(text+"");
Log.d("ENTRO",msg.obj.toString());
return true;
}
public class Time implements Runnable{
public TextView txtTiempo;
public boolean detenido;
public boolean pausado;
int centesimas = 00,minutos=00, segundos=00, horas=00;
String cronometro;
private Handler handler;
public Time (Handler handler){
this.handler = handler;
}
@Override
public void run (){
while(!detenido)
{
while(!pausado)
{
try {
//if(centesimas == 99){
//centesimas = 00;
segundos++;
//}
if (segundos == 59) {
segundos = 00;
minutos++;
}
if (minutos == 59) {
minutos = 00;
//horas++;
}
centesimas++;
//cronometro = /*horas + ":" +*/ minutos + ":" + segundos /*+ ":" + centesimas*/;
sendMsg (minutos + ":" + segundos);
handler.sendEmptyMessage(0);
Thread.sleep(900);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
private void sendMsg(String string)
{
Message message = new Message ();
message.obj = string;
handler.sendMessage(message);
}
Exepction是“Unchaught handler”和“ClassCastExeption”。我的错是什么?如何做:如果时间是1:50,完成应用程序或使用Intent ??