時間をバイナリで出力するアプリケーションを作成しました。ロジックはうまく機能しますが、ロジックと GUI を分離しようとすると、いくつかの問題が発生しました。相互参照の問題があるようですが、見つけられないようです。
主な活動:
package se.macke.binarycounter;
import java.util.GregorianCalendar;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;
public class MainActivity extends Activity
{
public TextView text0, text;
public Timer timer;
public RadioButton rB00,rB01,rB02,rB03, rB04, rB05, rB06, rB07, rB08, rB09,
rB0A, rB0B, rB0C, rB0D, rB0E, rB0F, rB11, rB12;
RadioButton[] rButtons = new RadioButton[18];
public Executive exec = new Executive(); // This is row 25 in the logcat reference
public GregorianCalendar gregCal = (GregorianCalendar) GregorianCalendar.getInstance();
論理クラス:
/**
*
*/
package se.macke.binarycounter;
import static java.lang.System.out;
import java.util.GregorianCalendar;
import android.widget.RadioButton;
/**
* @author macke
*
*/
public class Executive
{
//Converts the numbers to a long string with new rows
RadioButton[] rButtons = new RadioButton[18];
GregorianCalendar gregCal = new GregorianCalendar();
MainActivity m = new MainActivity(); // This is row 21 in the LogCat reference
private int sec = gregCal.get(GregorianCalendar.SECOND); // time units
private int min = gregCal.get(GregorianCalendar.MINUTE);
private int hour = gregCal.get(GregorianCalendar.HOUR);
logcat の抜粋:
08-25 13:43:53.459: E/AndroidRuntime(383): FATAL EXCEPTION: main
08-25 13:43:53.459: E/AndroidRuntime(383): java.lang.StackOverflowError
08-25 13:43:53.459: E/AndroidRuntime(383): at java.util.Arrays.binarySearch(Arrays.java:405)
08-25 13:43:53.459: E/AndroidRuntime(383): at org.apache.harmony.luni.internal.util.ZoneInfo.getOffset(ZoneInfo.java:168)
08-25 13:43:53.459: E/AndroidRuntime(383): at org.apache.harmony.luni.internal.util.ZoneInfo.getOffset(ZoneInfo.java:162)
08-25 13:43:53.459: E/AndroidRuntime(383): at java.util.GregorianCalendar.fullFieldsCalc(GregorianCalendar.java:495)
08-25 13:43:53.459: E/AndroidRuntime(383): at java.util.GregorianCalendar.computeFields(GregorianCalendar.java:658)
08-25 13:43:53.459: E/AndroidRuntime(383): at java.util.Calendar.complete(Calendar.java:839)
08-25 13:43:53.459: E/AndroidRuntime(383): at java.util.Calendar.setTimeInMillis(Calendar.java:1339)
08-25 13:43:53.459: E/AndroidRuntime(383): at java.util.GregorianCalendar.<init>(GregorianCalendar.java:339)
08-25 13:43:53.459: E/AndroidRuntime(383): at java.util.GregorianCalendar.<init>(GregorianCalendar.java:239)
08-25 13:43:53.459: E/AndroidRuntime(383): at se.macke.binarycounter.Executive.<init>(Executive.java:20)
08-25 13:43:53.459: E/AndroidRuntime(383): at se.macke.binarycounter.MainActivity.<init>(MainActivity.java:25)
08-25 13:43:53.459: E/AndroidRuntime(383): at se.macke.binarycounter.Executive.<init>(Executive.java:21)
08-25 13:43:53.459: E/AndroidRuntime(383): at se.macke.binarycounter.MainActivity.<init>(MainActivity.java:25)
08-25 13:43:53.459: E/AndroidRuntime(383): at se.macke.binarycounter.Executive.<init>(Executive.java:21)
08-25 13:43:53.459: E/AndroidRuntime(383): at se.macke.binarycounter.MainActivity.<init>(MainActivity.java:25)
08-25 13:43:53.459: E/AndroidRuntime(383): at se.macke.binarycounter.Executive.<init>(Executive.java:21)
回避できる場合、ロジックがGUIを認識すべきではないことを理解しています。代わりにロジック クラスのボタンを初期化する必要があります。その場合、どのようにしますか?