2010-12-11 5 views
1

다른 클래스의 메서드를 호출하려고했습니다.Android에서 다른 클래스의 메서드를 호출하는 방법은 무엇입니까?

나는 2 개의 클래스가 있습니다. Timer.class 및 DecisionMaking.class를 참조하십시오. Timer 클래스는 일단 타이머가 onFinish()가되면 DecisionMaking.class에서 메소드 (지금은 축배를 사용했습니다)를 호출한다고 가정합니다. 내 코드에는 오류가 없지만 타이머가 카운팅을 끝내면 메서드가 호출되지 않고 에뮬레이터에서 강제 종료를 요청합니다. 두 클래스 모두 동일한 패키지에 있습니다. 제가 누락 된 것이 있습니까?

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) : java.lang.SecurityException 12-11 22 : 01 : 56.845 : ERROR/시스템 (65) : android.os.BinderProxy.transact (네이티브 메소드) 12-11 22 : 01 : 56.845 : 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 : ERROR/System (65) : com.android.server.ServerThread.run (SystemServer.jav a : 184) – user538889

답변

0

내가는 onFinish() 메소드에 timer.start를 호출 할 필요를 생각하지 않습니다.

+0

onFinish()의 timer.start는 카운트를 완료하면 타이머를 다시 시작합니다. – user538889

+0

표시된 오류는 무엇입니까? U 게시 할 수 있습니까? – 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

관련 문제