我尝试随时间获取字符串(hh:mm:ss),但出现此错误:
10-28 12:35:27.682: E/AndroidRuntime(14002): java.lang.NullPointerException
我在我的主班上打电话给这个:
private TimeUpdater timeupdater;
.
.
.
private Runnable runnable = new Runnable(){
public void run() {
datasource = new DataSource(getBaseContext());
datasource.open();
comment = datasource.getComment("1");
data = comment.toString().split(" ");
/*for(int i=0;i<11;i++)
{
dataUpdate[i]=data[i+1];
System.out.println("U " + dataUpdate[i]);
System.out.println("D " + data[i+1]);
}*/
String a = timeupdater.upTime(dane[5]);
System.out.println(a);
time.setText(timeupdater.upTime(dane[5]));
//for(int i=0;i<12;i++)
//System.out.println(dane[i]);
handler.postDelayed(this, 1000);
}
};
内部数据 [5] 是 00:00:00
这是我的时间更新程序类:
public class TimeUpdater {
private int hh, mm, ss;
private String time;
private String shh, smm, sss;
public String upTime(String time) {
String[] czas = time.split(":");
hh = Integer.parseInt(czas[0]);
mm = Integer.parseInt(czas[1]);
ss = Integer.parseInt(czas[2]);
if(ss<60)
ss++;
if(ss==60)
{
ss=0;
mm++;
}
if(mm==60)
hh++;
if(hh<10)
shh = "0"+hh;
if(mm<10)
smm = "0"+mm;
if(ss<10)
sss = "0"+ss;
this.time = shh + ":" + smm + ":" + sss;
System.out.println(time);
return this.time;
}
我需要,因为以后我想做更多的电话。我需要知道如何在其他类中创建公共字符串以每秒更改数据