我一直在尝试调用另一个类的方法。如何从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