package com.s5c.Changlink;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.widget.Toast;
@SuppressLint({ "SimpleDateFormat", "HandlerLeak" })
public class sqlService extends Service {
SharedPreferences sp;
String branch,mold,sql,id,Changelocation;
Thread Change;
Timer timer;
Date molds;
Date data=new Date(System.currentTimeMillis());
SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
Message message;
public void onCreate() {
super.onCreate();
}
public int onStartCommand(Intent intent, int flags, int startId) {
sp =getSharedPreferences("User", MODE_PRIVATE);
branch = sp.getString("branch", "");
mold = sp.getString("mold", "");
try {
molds = dateFormater.parse(mold);
} catch (ParseException e) {
e.printStackTrace();
}
if(molds.before(data)){
timer.schedule(change, molds, 300000);////代码在这里出错,使程序崩溃
}else{
timer.schedule(change, 300000, 300000);
}
return super.onStartCommand(intent, flags, startId);
}
TimerTask change = new TimerTask(){
public void run() {
message = new Message();
message.what = 1;
handler.sendMessage(message);
}
};
Handler handler = new Handler(){
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
Toast.makeText(sqlService.this, "完全正常", Toast.LENGTH_LONG).show();
break;
}
super.handleMessage(msg);
}
};
public void onDestroy() {
Toast.makeText(this, "您将取消服务", Toast.LENGTH_LONG).show();
super.onDestroy();
}
public IBinder onBind(Intent intent) {
return null;
}
}
以上就是程序代码,我在造成崩溃的地方有标注,不明白为什么会造成程序崩溃