1

アプリに問題があり、何が問題なのかわかりません。ICS ではアプリは動作しますが、2.X では問題があります。ループに関係していると思いますが、まだ少し混乱しています。

開発者コンソールは、エラーレポートのためにこれをスローします:

Exception class > java.lang.StackOverflowError
Source method > Matrix.setScale()

これは問題を引き起こしているコードです...

private void shiftLoop7()
{
    if (d7 != doy && d7 < 366)
    {
        d7 = d7 + 8;
        shiftLoop7();
    }
    else if(d7 == doy)
    {

        if (hour >= 0 && hour < 8)
        {
            shift.setText("C");
            shift.setTextAppearance(getApplicationContext(), R.style.CShift);

            shiftImage.setImageResource(R.drawable.c);
            timeTill.setText("till 7:45 AM");

            dayshift.setText("A Shift");
            day1.setBackgroundResource(R.color.A);
            day2.setBackgroundResource(R.color.A);
            day3.setBackgroundResource(R.color.A);
            day4.setBackgroundResource(R.color.A);

            nightshift.setText("C Shift");
            night1.setBackgroundResource(R.color.C);
            night2.setBackgroundResource(R.color.C);
            night3.setBackgroundResource(R.color.C);
            night4.setBackgroundResource(R.color.C);
        }
        else if (hour >= 8 && hour < 17)
        {
            shift.setText("A");
            shift.setTextAppearance(getApplicationContext(), R.style.AShift);

            shiftImage.setImageResource(R.drawable.a);
            timeTill.setText("till 4:45 PM");

            dayshift.setText("A Shift");
            day1.setBackgroundResource(R.color.A);
            day2.setBackgroundResource(R.color.A);
            day3.setBackgroundResource(R.color.A);
            day4.setBackgroundResource(R.color.A);

            nightshift.setText("C Shift");
            night1.setBackgroundResource(R.color.C);
            night2.setBackgroundResource(R.color.C);
            night3.setBackgroundResource(R.color.C);
            night4.setBackgroundResource(R.color.C);
        }
        else
        {
            shift.setText("C");
            shift.setTextAppearance(getApplicationContext(), R.style.CShift);

            shiftImage.setImageResource(R.drawable.c);
            timeTill.setText("till 7:45 AM");

            dayshift.setText("A Shift");
            day1.setBackgroundResource(R.color.A);
            day2.setBackgroundResource(R.color.A);
            day3.setBackgroundResource(R.color.A);
            day4.setBackgroundResource(R.color.A);

            nightshift.setText("C Shift");
            night1.setBackgroundResource(R.color.C);
            night2.setBackgroundResource(R.color.C);
            night3.setBackgroundResource(R.color.C);
            night4.setBackgroundResource(R.color.C);
        }
    }
    else
    {
        shiftLoop8();
    }
}
4

1 に答える 1

1

スタック オーバーフローの一般的な原因は、多数の再帰呼び出しです。これは、無限再帰を引き起こすバグ、または非常に深い再帰を持つように構成されたコードが原因です。

あなたの場合、スタック オーバーフローは、コードにかなり深い再帰呼び出しが発生する可能性があるという事実が原因である可能性があります。while ループだけになるように再帰呼び出しを再構築できますか? たとえば、次の代わりに:

if (d7 != doy && d7 < 366)
{
    d7 = d7 + 8;
    shiftLoop7();
}

あなたはちょうど次のことを行うことができます:

while (d7 != doy && d7 < 366)
{
    d7 = d7 + 8;
}
于 2012-06-06T03:33:04.653 に答える