我一直在嘗試調用另一個類的方法。如何從Android的另一個類中調用方法?
我有2個班。 Timer.class和DecisionMaking.class。定時器在onFinish()之後,Timer類將假定從DecisionMaking.class中調用一個方法(我剛剛使用了一個toast)。在我的代碼中沒有錯誤,但是當計時器完成計數時,該方法未被調用並且模擬器要求強制關閉。這兩個類都在同一個包中。有什麼我失蹤的?
Timer.class
public class Timer extends Activity{
TextView timeDisplay;
MyCount timer;
int length = 10000;
long startTime;
long timeRemaining;
DecisionMaking decisionmaking;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
timeDisplay = (TextView) findViewById(R.id.timer);
timer = new MyCount(length, 1000);
timer.start();
}
public class MyCount extends CountDownTimer {
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
public void onFinish() {
DecisionMaking decisionmaking = new DecisionMaking();
decisionmaking.sendSms();
timer.start();
}
public void onTick(long millisUntilFinished) {
timeDisplay.setText("Time:" + millisUntilFinished/1000);
}
}
}
DecisionMaking.class
public class DecisionMaking extends Timer{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sendSms();
}
public boolean sendSms() {
Calendar cal = Calendar.getInstance();
Date d = cal.getTime();
int hour = d.getHours();
if (hour > 0 && hour < 6)
return false;
else
{
//Call SMS class here, remove toast
Toast.makeText(getBaseContext(), "SMS sent.", Toast.LENGTH_SHORT).show();
return true;
}
}
}
可以發佈什麼樣的錯誤打印在日誌貓 – Kakey 2010-12-11 13:53:51
12-11 22:01:56.845:錯誤/系統(65):失敗開始核心服務 12-11 22:01:56.845:錯誤/系統(65 ):java.lang.SecurityException 12-11 22:01:56.845:ERROR/System(65):at android.os.BinderProxy.transact(Native Method) 12-11 22:01:56.845:ERROR /系統(65):在android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146) 12-11 22:01:56.845:錯誤/系統(65):在android.os.ServiceManager.addService(ServiceManager.java :72) 12-11 22:01:56.845:錯誤/系統(65):at com.android.server.ServerThread.run(SystemServer.jav a:184) – user538889 2010-12-11 14:32:48