配列リストのオブジェクトを返すはずの関数がありますが、何らかの理由で return ステートメントでスタックします。returnステートメントの前のすべてが機能しています。関数を機能させる単一の値のみが ArrayLists に含まれているというエラーがありましたが、もちろん間違ったデータを返します。
package com.burninglobster.TP;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
public class Chart2Activity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Object graphdata[] = graphsetup();
Log.d("This message is NOT shown", "");
List<Double> distances = (List<Double>) graphdata[0];
List<Double> accall = (List<Double>) graphdata[1];
List<Double> accdir = (List<Double>) graphdata[2];
List<Double> accdist = (List<Double>) graphdata[3];
List<Double> meandir = (List<Double>) graphdata[4];
List<Double> meandist = (List<Double>) graphdata[5];
linegraph lgraph = new linegraph();
setContentView(R.layout.splot);
LinearLayout layout1 = (LinearLayout) findViewById(R.id.splot2);
layout1.addView(lgraph.getView1(this, distances, accall));
LinearLayout layout2 = (LinearLayout) findViewById(R.id.splot3);
layout2.addView(lgraph.getView2(this, distances, accdir, meandir));
LinearLayout layout3 = (LinearLayout) findViewById(R.id.splot4);
layout3.addView(lgraph.getView2(this, distances, accdist, meandist));
}
public Object[] graphsetup() {
SharedPreferences rprefs;
rprefs = getSharedPreferences("com.burninglobster.TP.tprefs",
Context.MODE_WORLD_READABLE);
double setdist = rprefs.getFloat("setdist", 0);
String[] sourcesarray = rprefs.getString("sourcesarray", "Standarddef")
.split(",");
String setdisc = sourcesarray[rprefs.getInt("spindiscpos", 0)];
DBHelper dbHelper = new DBHelper(Chart2Activity.this);
SQLiteDatabase db;
db = dbHelper.getReadableDatabase();
String graphquery = "SELECT " + DBHelper.SHOOTER + "," + DBHelper.WDIR
+ "," + DBHelper.WSTR + "," + DBHelper.SMOD + ","
+ DBHelper.DIST + "," + DBHelper.R_DIST + ","
+ DBHelper.OS_DIST + " FROM " + DBHelper.TABLE + " WHERE "
+ DBHelper.SHOOTER + "='" + setdisc + "'" + " ORDER BY "
+ DBHelper.DIST;
Cursor graphcursor = db.rawQuery(graphquery, null);
int rows = graphcursor.getCount();
int ishooter = graphcursor.getColumnIndex(DBHelper.SHOOTER);
int iwdir = graphcursor.getColumnIndex(DBHelper.WDIR);
int iwstr = graphcursor.getColumnIndex(DBHelper.WSTR);
int ismod = graphcursor.getColumnIndex(DBHelper.SMOD);
int idist = graphcursor.getColumnIndex(DBHelper.DIST);
int irdist = graphcursor.getColumnIndex(DBHelper.R_DIST);
int iosdist = graphcursor.getColumnIndex(DBHelper.OS_DIST);
List<Double> accall = new ArrayList<Double>();
List<Double> accdir = new ArrayList<Double>();
List<Double> meandir = new ArrayList<Double>();
List<Double> accdist = new ArrayList<Double>();
List<Double> meandist = new ArrayList<Double>();
List<Double> accdirtemp = new ArrayList<Double>();
List<Double> accdisttemp = new ArrayList<Double>();
List<Double> distances = new ArrayList<Double>();
double dalla = 0;
double ddira = 0;
double ddista = 0;
double ddirm = 0;
double ddistm = 0;
double currentdist = 0;
graphcursor.moveToFirst();
if (rows > 0) {
currentdist = graphcursor.getDouble(idist);
}
for (int i = 0; i < rows; i++) {
// REMOVED ERROR CAUSING SINGLE VALUE IN ARRAYLISTS:
// currentdist=graphcursor.getDouble(idist);
if (graphcursor.getDouble(idist) < (currentdist + 5)) {
accdirtemp.add(graphcursor.getDouble(irdist));
accdisttemp.add(graphcursor.getDouble(iosdist));
} else {
for (int u = 0; u < accdirtemp.size(); u++) {
ddira += Math.pow(accdirtemp.get(u), 2);
ddista += Math.pow(accdisttemp.get(u), 2);
dalla += Math.pow(accdirtemp.get(u), 2)
+ Math.pow(accdisttemp.get(u), 2);
ddirm += accdirtemp.get(u);
ddistm += accdisttemp.get(u);
}
accall.add(Math.sqrt(dalla / accdirtemp.size()));
Double.toString(Math.sqrt(dalla / accdirtemp.size())));
accdir.add(Math.sqrt(ddira / accdirtemp.size()));
accdist.add(Math.sqrt(ddista / accdirtemp.size()));
meandir.add(ddirm / accdirtemp.size());
meandist.add(ddistm / accdirtemp.size());
distances.add(currentdist);
dalla = 0;
ddira = 0;
ddirm = 0;
ddista = 0;
ddistm = 0;
currentdist = graphcursor.getDouble(idist) + 5;
accdirtemp.clear();
accdisttemp.clear();
accdirtemp.add(graphcursor.getDouble(irdist));
accdisttemp.add(graphcursor.getDouble(iosdist));
}
graphcursor.moveToNext();
}
for (int u = 0; u < accdirtemp.size(); u++) {
ddira += Math.pow(accdirtemp.get(u), 2);
ddista += Math.pow(accdisttemp.get(u), 2);
dalla += Math.pow(accdirtemp.get(u), 2)
+ Math.pow(accdisttemp.get(u), 2);
ddirm += accdirtemp.get(u);
ddistm += accdisttemp.get(u);
}
accall.add(Math.sqrt(dalla / accdirtemp.size()));
accdir.add(Math.sqrt(ddira / accdirtemp.size()));
accdist.add(Math.sqrt(ddista / accdirtemp.size()));
meandir.add(ddirm / accdirtemp.size());
meandist.add(ddistm / accdirtemp.size());
distances.add(currentdist);
db.close();
dbHelper.close();
Log.d("This message", " is shown");
return new Object[] { distances, accall, accdir, accdist, meandir,
meandist };
}
}
私はうまく動作する同様の機能を持っていますが、違いはわかりません:
package com.burninglobster.TP;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
public class ChartActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Object plotdata[] = plotsetup();
Log.d("This message", " is also shown");
List<Double> rd1 = (List<Double>) plotdata[0];
List<Double> osd1 = (List<Double>) plotdata[1];
List<Double> rd2 = (List<Double>) plotdata[2];
List<Double> osd2 = (List<Double>) plotdata[3];
List<Double> rd3 = (List<Double>) plotdata[4];
List<Double> osd3 = (List<Double>) plotdata[5];
scatterplot plot = new scatterplot();
setContentView(R.layout.tplot);
LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
layout.addView(plot.getView(this, rd1, osd1, rd2, osd2, rd3, osd3));
}
public Object[] plotsetup() {
SharedPreferences rprefs;
rprefs = getSharedPreferences("com.burninglobster.TP.tprefs",
Context.MODE_WORLD_READABLE);
double setdist = rprefs.getFloat("setdist", 0);
String[] sourcesarray = rprefs.getString("sourcesarray", "Standarddef")
.split(",");
String setdisc = sourcesarray[rprefs.getInt("spindiscpos", 0)];
DBHelper dbHelper = new DBHelper(ChartActivity.this);
SQLiteDatabase db;
db = dbHelper.getReadableDatabase();
String plotquery = "SELECT " + DBHelper.SHOOTER + "," + DBHelper.WDIR
+ "," + DBHelper.WSTR + "," + DBHelper.SMOD + ","
+ DBHelper.DIST + "," + DBHelper.R_DIST + ","
+ DBHelper.OS_DIST + " FROM " + DBHelper.TABLE;
Cursor plotcursor = db.rawQuery(plotquery, null);
int ishooter = plotcursor.getColumnIndex(DBHelper.SHOOTER);
int iwdir = plotcursor.getColumnIndex(DBHelper.WDIR);
int iwstr = plotcursor.getColumnIndex(DBHelper.WSTR);
int ismod = plotcursor.getColumnIndex(DBHelper.SMOD);
int idist = plotcursor.getColumnIndex(DBHelper.DIST);
int irdist = plotcursor.getColumnIndex(DBHelper.R_DIST);
int iosdist = plotcursor.getColumnIndex(DBHelper.OS_DIST);
int rows = plotcursor.getCount();
List<Double> rd1 = new ArrayList<Double>();
List<Double> osd1 = new ArrayList<Double>();
List<Double> rd2 = new ArrayList<Double>();
List<Double> osd2 = new ArrayList<Double>();
List<Double> rd3 = new ArrayList<Double>();
List<Double> osd3 = new ArrayList<Double>();
plotcursor.moveToFirst();
int disccount = 0;
int array1 = 0;
int array2 = 0;
int array3 = 0;
double cursordist;
for (int i = 0; i < rows; i++) {
if (plotcursor.getString(0).equals(setdisc)) {
cursordist = plotcursor.getDouble(idist);
if (cursordist > (setdist - 5) && cursordist < (setdist + 5)) {
rd1.add(plotcursor.getDouble(irdist));
osd1.add(plotcursor.getDouble(iosdist));
array1++;
} else if (cursordist > (setdist)
&& cursordist < (setdist + 10)) {
rd2.add(plotcursor.getDouble(irdist));
osd2.add(plotcursor.getDouble(iosdist));
array2++;
} else if (cursordist > (setdist - 10)
&& cursordist < (setdist)) {
rd3.add(plotcursor.getDouble(irdist));
osd3.add(plotcursor.getDouble(iosdist));
array3++;
}
disccount++;
}
plotcursor.moveToNext();
}
db.close();
dbHelper.close();
Log.d("This message", " is shown");
return new Object[] { rd1, osd1, rd2, osd2, rd3, osd3 };
}
}
returnステートメントの直前に「Log.d」を追加し、アクティビティの関数呼び出しの直後に別のものを追加しましたが、最初のものだけが表示されています。1/2 から 1 分間フリーズした後、待機または強制終了のダイアログが表示されます。問題に関する詳細情報を取得する方法がわかりません。提案?