2010-12-11 16 views
1

私は別のクラスからメソッドを呼び出そうとしています。Androidの別のクラスからメソッドを呼び出す方法は?

私は2つのクラスを持っています。 Timer.classとDecisionMaking.classです。 Timerクラスは、タイマーがonFinish()になったら、DecisionMaking.classからメソッド(今はトーストを使用しました)を呼び出すと仮定しています。私のコードにエラーはありませんが、タイマーがカウントを終了すると、メソッドは呼び出されず、エミュレータはForce Closeを要求します。両方のクラスは同じパッケージに入っています。私が行方不明のものはありますか?

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; 
    } 
} 
} 
+0

ログにはどのようなエラーが記録されますか? – Kakey

+0

12-11 22:01:56.845:ERROR/System(65):コアサービスの開始に失敗しました 12-11 22:01:56.845:ERROR/System(65 ):java.lang.SecurityException 12-11 22:01:56.845:ERROR /システム(65):01:56.845:android.os.BinderProxy.transact(ネイティブメソッド) 12-11 22でERROR /システム(65):android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146) 12-11 22:01:56.845:ERROR/System(65):android.os.ServiceManager.addService(ServiceManager.java :72) 12-11 22:01:56.845:エラー/システム(65):com.android.server.ServerThread.run(SystemServer.jav a:184) – user538889

答えて

0

私はonFinish()メソッドでtimer.start呼び出す必要だと思いません。

+0

onFinish()のtimer.startは、一度カウントを終了するとタイマーを再起動します。 – user538889

+0

表示されるエラーは何ですか?あなたは投稿できますか? – Kakey

+0

12-11 22:01:18.875:ERROR/Zygote(32):setreuid()が失敗しました。 errno:2 12-11 22:01:38.045:ERROR/Zygote(32):setreuid()が失敗しました。 errno:17 – user538889

関連する問題