これは、ブール値とその周りの構造のみを含む、非常に大幅に削減されたバージョンです。
public int payoffDebt(Double totalDebt) {
boolean booIsPaid[] = new boolean[c.getCount()];
int bb = 0;
int bbb = 0;
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
booIsPaid[bb++] = false;
}
while (totalDebt > 0) {
for (int i : rowCounter) {
if ((indBal[p] <= 0) && (booIsPaid[bbb] == false)) {
booIsPaid[bbb++] = true;
}
}
}
return monthTotal;
}
これが私がやろうとしていることです。早い段階で、ユーザーの「負債」をループし、booIsPaid と呼ばれるそれぞれにブール値を割り当てます。それらはfalseに設定されており、これは正常に機能します。ただし、以下では、Android アプリケーションで、これが呼び出されたアクティビティで Window Leaking LogCat を取得するため、それらを正しく反復処理しているとは思いません。設定した場所をコメントアウトするtrue
と、すべて正常に動作します。誰かがどこが正しくないかを見ることができますか?
編集:スタックトレース:
12-02 21:14:35.121: E/AndroidRuntime(8832): FATAL EXCEPTION: AsyncTask #1
12-02 21:14:35.121: E/AndroidRuntime(8832): java.lang.RuntimeException: An error occured while executing doInBackground()
12-02 21:14:35.121: E/AndroidRuntime(8832): at android.os.AsyncTask$3.done(AsyncTask.java:299)
12-02 21:14:35.121: E/AndroidRuntime(8832): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
12-02 21:14:35.121: E/AndroidRuntime(8832): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
12-02 21:14:35.121: E/AndroidRuntime(8832): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
12-02 21:14:35.121: E/AndroidRuntime(8832): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
12-02 21:14:35.121: E/AndroidRuntime(8832): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-02 21:14:35.121: E/AndroidRuntime(8832): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
12-02 21:14:35.121: E/AndroidRuntime(8832): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
12-02 21:14:35.121: E/AndroidRuntime(8832): at java.lang.Thread.run(Thread.java:856)
12-02 21:14:35.121: E/AndroidRuntime(8832): Caused by: java.lang.ArrayIndexOutOfBoundsException: length=4; index=4
12-02 21:14:35.121: E/AndroidRuntime(8832): at com.---.---.DebtDataSource.payoffDebt(DebtDataSource.java:290)
12-02 21:14:35.121: E/AndroidRuntime(8832): at com.---.---.Planner$PlannerTask.doInBackground(Planner.java:73)
12-02 21:14:35.121: E/AndroidRuntime(8832): at com.---.---.Planner$PlannerTask.doInBackground(Planner.java:1)
12-02 21:14:35.121: E/AndroidRuntime(8832): at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-02 21:14:35.121: E/AndroidRuntime(8832): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
12-02 21:14:35.121: E/AndroidRuntime(8832): ... 5 more
12-02 21:14:35.128: W/ActivityManager(291): Force finishing activity com.---.---/.Planner
12-02 21:14:35.175: W/ActivityManager(291): Force finishing activity com.---.---/.ManageDebts
12-02 21:14:35.285: W/ActivityManager(291): Duplicate finish request for ActivityRecord{41e0b390 com.---.---/.Planner}
12-02 21:14:35.496: I/ActivityManager(291): Displayed com.---.---/.Planner: +557ms
12-02 21:14:35.605: E/WindowManager(8832): Activity com.---.---.Planner has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4175e930 that was originally added here
12-02 21:14:35.605: E/WindowManager(8832): android.view.WindowLeaked: Activity com.---.---.Planner has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4175e930 that was originally added here
12-02 21:14:35.605: E/WindowManager(8832): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
12-02 21:14:35.605: E/WindowManager(8832): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
12-02 21:14:35.605: E/WindowManager(8832): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
12-02 21:14:35.605: E/WindowManager(8832): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
12-02 21:14:35.605: E/WindowManager(8832): at android.view.Window$LocalWindowManager.addView(Window.java:547)
12-02 21:14:35.605: E/WindowManager(8832): at android.app.Dialog.show(Dialog.java:277)
12-02 21:14:35.605: E/WindowManager(8832): at com.---.---.Planner$PlannerTask.onPreExecute(Planner.java:56)
12-02 21:14:35.605: E/WindowManager(8832): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
12-02 21:14:35.605: E/WindowManager(8832): at android.os.AsyncTask.execute(AsyncTask.java:534)
12-02 21:14:35.605: E/WindowManager(8832): at com.---.---.Planner.onCreate(Planner.java:36)
12-02 21:14:35.605: E/WindowManager(8832): at android.app.Activity.performCreate(Activity.java:5008)
12-02 21:14:35.605: E/WindowManager(8832): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
12-02 21:14:35.605: E/WindowManager(8832): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
12-02 21:14:35.605: E/WindowManager(8832): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
12-02 21:14:35.605: E/WindowManager(8832): at android.app.ActivityThread.access$600(ActivityThread.java:130)
12-02 21:14:35.605: E/WindowManager(8832): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
12-02 21:14:35.605: E/WindowManager(8832): at android.os.Handler.dispatchMessage(Handler.java:99)
12-02 21:14:35.605: E/WindowManager(8832): at android.os.Looper.loop(Looper.java:137)
12-02 21:14:35.605: E/WindowManager(8832): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-02 21:14:35.605: E/WindowManager(8832): at java.lang.reflect.Method.invokeNative(Native Method)
12-02 21:14:35.605: E/WindowManager(8832): at java.lang.reflect.Method.invoke(Method.java:511)
12-02 21:14:35.605: E/WindowManager(8832): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-02 21:14:35.605: E/WindowManager(8832): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-02 21:14:35.605: E/WindowManager(8832): at dalvik.system.NativeStart.main(Native Method)
編集:すべてを作り直しました。ここに私の新しい方法があります:
while (totalDebt > 0) {
booIsPaid = false;
remainingBalance = 0;
// Increment month
monthTotal = monthTotal + 1;
// update INDIVIDUAL debt Here
for (int i : rowCounter) {
nameList.add(indName[r++]);
// Zero Balance, set Boolean true, add to Remainder
if ((indBal[p] <= 0) && !booIsPaid) {
booIsPaid = true;
remainingbalance = remainingbalance + indPay[q];
indPay[q] = 0;
indBal[p] = 0;
payList.add(Double.valueOf(IndPay));
// First balance after zero; set Boolean false, add to remainder to payment.
} else if ((indBal[p] > 0) && booIsPaid) {
booIsPaid = false;
indPay[q] = indPay[q] + remainingbalance;
indPay[q] = Math.round(indPay[q] * 100.00) / 100.00;
IndPay = myFormat.format(indPay[q]);
payList.add(Double.valueOf(IndPay));
// Other remaining balances
} else if ((indBal[p] > 0) && !booIsPaid) { indPay[q] = 0;
indPay[q] = Math.round(indPay[q] * 100.00) / 100.00;
IndPay = myFormat.format(indPay[q]);
payList.add(Double.valueOf(IndPay));
}
// indPay[q] (should or should not include remainder here!
indBal[p] = indBal[p] - (indPay[q] - interestFee);
totalDebt = totalDebt - (indPay[q++] - interestFee);
IndBal = myFormat.format(indBal[p++]);
indBalList.add(Double.valueOf(IndBal));
feeList.add(Double.valueOf(InterestFee));
}
}
注: 出力はここの 4 つの ArrayLists に格納されており、月ごとにユーザーに出力されます。
全体の実用的なアプリケーションは、債務返済戦略を考え出すことです。私はまだこれをテストしておらず、報告します。フィードバックはありますか?お知らせ下さい!