我在这里阅读了有关此错误的所有其他页面,但似乎没有一个解决方案对我有用。任何帮助表示赞赏。我有一个活动可以让用户根据需要插入尽可能多的数据。然后将其保存到 SQL 中,然后用户可以选择他们刚刚保存的特定数据集。当我现在尝试开始一个新的时,它会引发此错误。
07-15 16:43:07.604: E/AndroidRuntime(320): FATAL EXCEPTION: main
07-15 16:43:07.604: E/AndroidRuntime(320): android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
07-15 16:43:07.604: E/AndroidRuntime(320): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:424)
07-15 16:43:07.604: E/AndroidRuntime(320): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
07-15 16:43:07.604: E/AndroidRuntime(320): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
07-15 16:43:07.604: E/AndroidRuntime(320): at com.rivers.gt5protuner.CrAETune$LoadContacts.onPostExecute(CrAETune.java:261)
07-15 16:43:07.604: E/AndroidRuntime(320): at com.rivers.gt5protuner.CrAETune$LoadContacts.onPostExecute(CrAETune.java:1)
07-15 16:43:07.604: E/AndroidRuntime(320): at android.os.AsyncTask.finish(AsyncTask.java:631)
07-15 16:43:07.604: E/AndroidRuntime(320): at android.os.AsyncTask.access$600(AsyncTask.java:177)
07-15 16:43:07.604: E/AndroidRuntime(320): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
07-15 16:43:07.604: E/AndroidRuntime(320): at android.os.Handler.dispatchMessage(Handler.java:99)
07-15 16:43:07.604: E/AndroidRuntime(320): at android.os.Looper.loop(Looper.java:137)
07-15 16:43:07.604: E/AndroidRuntime(320): at android.app.ActivityThread.main(ActivityThread.java:5233)
07-15 16:43:07.604: E/AndroidRuntime(320): at java.lang.reflect.Method.invokeNative(Native Method)
07-15 16:43:07.604: E/AndroidRuntime(320): at java.lang.reflect.Method.invoke(Method.java:511)
07-15 16:43:07.604: E/AndroidRuntime(320): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
07-15 16:43:07.604: E/AndroidRuntime(320): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
07-15 16:43:07.604: E/AndroidRuntime(320): at dalvik.system.NativeStart.main(Native Method)
07-15 16:48:06.972: I/Process(320): Sending signal. PID: 320 SIG: 9
从这段代码
public class CrAETune extends Activity implements OnClickListener{
private long rowID;
private EditText caret,lapet,trket,ppet,tyet,rh1,rh2,sr1,sr2,de1,de2,dc1,dc2,ar1,ar2,c1,c2,t1,t2,bb1,bb2,li1,li2,la1,la2,lb1,lb2,df1,df2,g1,g2,g3,g4,g5,g6,g7,gf,ts,hp,tq,lb,mil,rpm,parts,comments,combo,sorttime,sortpp;
String a,b,c,message,pps,tys,rh1s,rh2s,sr1s,sr2s,de1s,de2s,dc1s,dc2s,ar1s,ar2s,c1s,c2s,t1s,t2s,bb1s,bb2s,li1s,li2s,la1s,la2s,lb1s,lb2s,df1s,df2s,g1s,g2s,g3s,g4s,g5s,g6s,g7s,gfs,tss,hps,tqs,lbs,mils,rpms,partss,commentss;
Button paste;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.personalsetup);
caret = (EditText) findViewById(R.id.editcartype);
lapet = (EditText) findViewById(R.id.editlaptime);
trket = (EditText) findViewById(R.id.edittracktype);
ppet = (EditText)findViewById(R.id.editperfpoints);
tyet = (EditText)findViewById(R.id.edittires);
rh1 = (EditText)findViewById(R.id.editrh1);
rh2 = (EditText)findViewById(R.id.editrh2);
sr1 = (EditText)findViewById(R.id.editsr1);
sr2 = (EditText)findViewById(R.id.editsr2);
de1 = (EditText)findViewById(R.id.editde1);
de2 = (EditText)findViewById(R.id.editde2);
dc1 = (EditText)findViewById(R.id.editdc1);
dc2 = (EditText)findViewById(R.id.editdc2);
ar1 = (EditText)findViewById(R.id.editar1);
ar2 = (EditText)findViewById(R.id.editar2);
c1 = (EditText)findViewById(R.id.editc1);
c2 = (EditText)findViewById(R.id.editc2);
t1 = (EditText)findViewById(R.id.editt1);
t2 = (EditText)findViewById(R.id.editt2);
bb1 = (EditText)findViewById(R.id.editbb1);
bb2 = (EditText)findViewById(R.id.editbb2);
li1 = (EditText)findViewById(R.id.editli1);
li2 = (EditText)findViewById(R.id.editli2);
la1 = (EditText)findViewById(R.id.editla1);
la2 = (EditText)findViewById(R.id.editla2);
lb1 = (EditText)findViewById(R.id.editlb1);
lb2 = (EditText)findViewById(R.id.editlb2);
df1 = (EditText)findViewById(R.id.editdf1);
df2 = (EditText)findViewById(R.id.editdf2);
g1 = (EditText)findViewById(R.id.editgear1);
g2 = (EditText)findViewById(R.id.editgear2);
g3 = (EditText)findViewById(R.id.editgear3);
g4 = (EditText)findViewById(R.id.editgear4);
g5 = (EditText)findViewById(R.id.editgear5);
g6 = (EditText)findViewById(R.id.editgear6);
g7 = (EditText)findViewById(R.id.editgear7);
gf = (EditText)findViewById(R.id.editgf);
ts = (EditText)findViewById(R.id.edittop);
hp = (EditText)findViewById(R.id.edithp);
tq = (EditText)findViewById(R.id.edittq);
lb = (EditText)findViewById(R.id.editweight);
mil = (EditText)findViewById(R.id.editmiles);
rpm = (EditText)findViewById(R.id.editrpm);
parts = (EditText)findViewById(R.id.editparts);
comments = (EditText)findViewById(R.id.editcomments);
combo = (EditText)findViewById(R.id.editcombo);
sorttime = (EditText)findViewById(R.id.editsorttime);
sortpp = (EditText)findViewById(R.id.editsortpp);
paste = (Button)findViewById(R.id.newpasteBtn);
paste.setOnClickListener(this);
Bundle extras = getIntent().getExtras();
if (extras != null)
{
rowID = extras.getLong("row_id");
caret.setText(extras.getString("car"));
lapet.setText(extras.getString("lap"));
trket.setText(extras.getString("trk"));
ppet.setText(extras.getString("pp"));
tyet.setText(extras.getString("ty"));
rh1.setText(extras.getString("rh1"));
rh2.setText(extras.getString("rh2"));
sr1.setText(extras.getString("sr1"));
sr2.setText(extras.getString("sr2"));
de1.setText(extras.getString("de1"));
de2.setText(extras.getString("de2"));
dc1.setText(extras.getString("dc1"));
dc2.setText(extras.getString("dc2"));
ar1.setText(extras.getString("ar1"));
ar2.setText(extras.getString("ar2"));
c1.setText(extras.getString("c1"));
c2.setText(extras.getString("c2"));
t1.setText(extras.getString("t1"));
t2.setText(extras.getString("t2"));
bb1.setText(extras.getString("bb1"));
bb2.setText(extras.getString("bb2"));
li1.setText(extras.getString("li1"));
li2.setText(extras.getString("li2"));
la1.setText(extras.getString("la1"));
la2.setText(extras.getString("la2"));
lb1.setText(extras.getString("lb1"));
lb2.setText(extras.getString("lb2"));
df1.setText(extras.getString("df1"));
df2.setText(extras.getString("df2"));
g1.setText(extras.getString("g1"));
g2.setText(extras.getString("g2"));
g3.setText(extras.getString("g3"));
g4.setText(extras.getString("g4"));
g5.setText(extras.getString("g5"));
g6.setText(extras.getString("g6"));
g7.setText(extras.getString("g7"));
gf.setText(extras.getString("gf"));
ts.setText(extras.getString("ts"));
hp.setText(extras.getString("hp"));
tq.setText(extras.getString("tq"));
lb.setText(extras.getString("lb"));
mil.setText(extras.getString("mil"));
rpm.setText(extras.getString("rpm"));
parts.setText(extras.getString("parts"));
comments.setText(extras.getString("comments"));
}
Button saveButton =(Button) findViewById(R.id.newsaveBtn);
saveButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
if (caret.getText().length() != 0)
{
AsyncTask<Object, Object, Object> saveContactTask =
new AsyncTask<Object, Object, Object>()
{
@Override
protected Object doInBackground(Object... params)
{
saveContact();
return null;
}
@Override
protected void onPostExecute(Object result)
{
finish();
}
};
saveContactTask.execute((Object[]) null);
}
else
{
AlertDialog.Builder alert = new AlertDialog.Builder(CrAETune.this);
alert.setTitle(R.string.errorTitle);
alert.setMessage(R.string.errorMessage);
alert.setPositiveButton(R.string.errorButton, null);
alert.show();
}
}
});
}
@Override
protected void onResume()
{
super.onResume();
new LoadContacts().execute(rowID);
}
private class LoadContacts extends AsyncTask<Long, Object, Cursor>
{
CrDbCon dbConnector = new CrDbCon(CrAETune.this);
@Override
protected Cursor doInBackground(Long... params)
{
dbConnector.open();
return dbConnector.getOneContact(params[0]);
}
@Override
protected void onPostExecute(Cursor result)
{
super.onPostExecute(result);
// get the column index for each data item
int nameIndex = result.getColumnIndex("car");
int capIndex = result.getColumnIndex("lap");
int codeIndex = result.getColumnIndex("trk");
int newIndex = result.getColumnIndex("pp");
int epicIndex = result.getColumnIndex("ty");
int aIndex = result.getColumnIndex("rh1");
int bIndex = result.getColumnIndex("rh2");
int cIndex = result.getColumnIndex("sr1");
int dIndex = result.getColumnIndex("sr2");
int eIndex = result.getColumnIndex("de1");
int fIndex = result.getColumnIndex("de2");
int dc1Index = result.getColumnIndex("dc1");
int dc2Index = result.getColumnIndex("dc2");
int ar1Index = result.getColumnIndex("ar1");
int ar2Index = result.getColumnIndex("ar2");
int kIndex = result.getColumnIndex("c1");
int lIndex = result.getColumnIndex("c2");
int mIndex = result.getColumnIndex("t1");
int nIndex = result.getColumnIndex("t2");
int rIndex = result.getColumnIndex("li1");
int qIndex = result.getColumnIndex("li2");
int sIndex = result.getColumnIndex("la1");
int tIndex = result.getColumnIndex("la2");
int bbtIndex = result.getColumnIndex("bb1");
int bbsIndex = result.getColumnIndex("bb2");
int uIndex = result.getColumnIndex("lb1");
int vIndex = result.getColumnIndex("lb2");
int wIndex = result.getColumnIndex("df1");
int xIndex = result.getColumnIndex("df2");
int yIndex = result.getColumnIndex("g1");
int zIndex = result.getColumnIndex("g2");
int aaIndex = result.getColumnIndex("g3");
int bbIndex = result.getColumnIndex("g4");
int ccIndex = result.getColumnIndex("g5");
int ddIndex = result.getColumnIndex("g6");
int eeIndex = result.getColumnIndex("g7");
int ffIndex = result.getColumnIndex("gf");
int topsIndex = result.getColumnIndex("ts");
int horsepIndex = result.getColumnIndex("hp");
int torqIndex = result.getColumnIndex("tq");
int lbsIndex = result.getColumnIndex("lb");
int mileIndex = result.getColumnIndex("mil");
int rpmsIndex = result.getColumnIndex("rpm");
int partIndex = result.getColumnIndex("parts");
int commentsIndex = result.getColumnIndex("comments");
caret.setText(result.getString(nameIndex));
lapet.setText(result.getString(capIndex));
trket.setText(result.getString(codeIndex));
ppet.setText(result.getString(newIndex));
tyet.setText(result.getString(epicIndex));
rh1.setText(result.getString(aIndex));
rh2.setText(result.getString(bIndex));
sr1.setText(result.getString(cIndex));
sr2.setText(result.getString(dIndex));
de1.setText(result.getString(eIndex));
de2.setText(result.getString(fIndex));
dc1.setText(result.getString(dc1Index));
dc2.setText(result.getString(dc2Index));
ar1.setText(result.getString(ar1Index));
ar2.setText(result.getString(ar2Index));
c1.setText(result.getString(kIndex));
c2.setText(result.getString(lIndex));
t1.setText(result.getString(mIndex));
t2.setText(result.getString(nIndex));
bb1.setText(result.getString(bbtIndex));
bb2.setText(result.getString(bbsIndex));
li2.setText(result.getString(qIndex));
li1.setText(result.getString(rIndex));
la1.setText(result.getString(sIndex));
la2.setText(result.getString(tIndex));
lb1.setText(result.getString(uIndex));
lb2.setText(result.getString(vIndex));
df1.setText(result.getString(wIndex));
df2.setText(result.getString(xIndex));
g1.setText(result.getString(yIndex));
g2.setText(result.getString(zIndex));
g3.setText(result.getString(aaIndex));
g4.setText(result.getString(bbIndex));
g5.setText(result.getString(ccIndex));
g6.setText(result.getString(ddIndex));
g7.setText(result.getString(eeIndex));
gf.setText(result.getString(ffIndex));
ts.setText(result.getString(topsIndex));
hp.setText(result.getString(horsepIndex));
tq.setText(result.getString(torqIndex));
lb.setText(result.getString(lbsIndex));
mil.setText(result.getString(mileIndex));
rpm.setText(result.getString(rpmsIndex));
parts.setText(result.getString(partIndex));
comments.setText(result.getString(commentsIndex));
result.close();
dbConnector.close();
}
}
private void saveContact()
{
CrDbCon dbConnector = new CrDbCon(this);
if (getIntent().getExtras() == null)
{
dbConnector.insertContact(
caret.getText().toString(),//1
lapet.getText().toString(),
trket.getText().toString(),
ppet.getText().toString(),
tyet.getText().toString(),//5
rh1.getText().toString(),
rh2.getText().toString(),
sr1.getText().toString(),
sr2.getText().toString(),
de1.getText().toString(),//10
de2.getText().toString(),
dc1.getText().toString(),
dc2.getText().toString(),
ar1.getText().toString(),
ar2.getText().toString(),//15
c1.getText().toString(),
c2.getText().toString(),
t1.getText().toString(),
t2.getText().toString(),
bb1.getText().toString(),//20
bb2.getText().toString(),
li1.getText().toString(),
li2.getText().toString(),
la1.getText().toString(),
la2.getText().toString(),
lb1.getText().toString(),
lb2.getText().toString(),
df1.getText().toString(),
df2.getText().toString(),
g1.getText().toString(),
g2.getText().toString(),
g3.getText().toString(),//30
g4.getText().toString(),
g5.getText().toString(),
g6.getText().toString(),
g7.getText().toString(),
gf.getText().toString(),//35
ts.getText().toString(),
hp.getText().toString(),
tq.getText().toString(),
lb.getText().toString(),
mil.getText().toString(),//40
rpm.getText().toString(),
parts.getText().toString(),
comments.getText().toString(),
combo.getText().toString(),
sorttime.getText().toString(),
sortpp.getText().toString());//43
}
else
{
dbConnector.updateContact(rowID,
caret.getText().toString(),
lapet.getText().toString(),
trket.getText().toString(),
ppet.getText().toString(),
tyet.getText().toString(),
rh1.getText().toString(),
rh2.getText().toString(),
sr1.getText().toString(),
sr2.getText().toString(),
de1.getText().toString(),//10
de2.getText().toString(),
dc1.getText().toString(),
dc2.getText().toString(),
ar1.getText().toString(),
ar2.getText().toString(),//15
c1.getText().toString(),
c2.getText().toString(),
t1.getText().toString(),
t2.getText().toString(),
bb1.getText().toString(),//20
bb2.getText().toString(),
li1.getText().toString(),
li2.getText().toString(),
la1.getText().toString(),
la2.getText().toString(),
lb1.getText().toString(),
lb2.getText().toString(),
df1.getText().toString(),
df2.getText().toString(),
g1.getText().toString(),
g2.getText().toString(),
g3.getText().toString(),//30
g4.getText().toString(),
g5.getText().toString(),
g6.getText().toString(),
g7.getText().toString(),
gf.getText().toString(),//35
ts.getText().toString(),
hp.getText().toString(),
tq.getText().toString(),
lb.getText().toString(),
mil.getText().toString(),//40
rpm.getText().toString(),
parts.getText().toString(),
comments.getText().toString(),
combo.getText().toString(),
sorttime.getText().toString(),
sortpp.getText().toString());
}
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.newpasteBtn:
Intent awee = new Intent(CrAETune.this, GoPro.class);
startActivity(awee);
break;
case R.id.deleteBtn:
deleteContact();
break;
case R.id.shareBtn:
getstrings();
String message = "Hey I just used my "
+a
+" to post a "
+b
+" on "
+c
+" with this setup saved with my GT5 PRO Tuner App from DarkLionRacing"
+'\n'
+" Performance Points "
+pps
+ '\n'
+" Tires were "
+tys
+'\n'+" and the parts settings go like this "+" Ride Height "+rh1s+" / "+rh2s
+'\n'+" Spring Rate "+sr1s+" / "+sr2s
+'\n'+" Damper(EXT)"+de1s+" / "+de2s
+'\n'+" Damper(COMP "+dc1s+" / "+dc2s
+'\n'+" AntiRoll Bar "+ar1s+" / "+ar2s
+'\n'+" Camber "+c1s+" / "+c2s
+'\n'+" Toe "+t1s+" / "+t2s
+'\n'+" Brake Bias "+bb1s+" / "+bb2s
+'\n'+" LSD Init "+li1s+" / "+li2s
+'\n'+" LSD Accel "+la1s+" / "+la2s
+'\n'+" LSD Braking "+lb1s+" / "+lb2s
+'\n'+" Downforce "+df1s+" / "+df2s
+'\n'+" Gears "
+'\n'+g1s
+'\n'+g2s
+'\n'+g3s
+'\n'+g4s
+'\n'+g5s
+'\n'+g6s
+'\n'+g7s
+'\n'+gfs
+'\n'+" Top Speed "
+'\n'+tss
+'\n'+" Horse power "+" "+hps
+'\n'+" Torque "+" "+tqs
+'\n'+" Weight "+" "+lbs
+'\n'+" Distance on the motor "+" "+mils
+'\n'+" RPM "+" "+rpms
+'\n'+" The parts I installed were "+" "+partss
+'\n'+" "+commentss
+" I bet you'll love it! "
;
Intent golk = new Intent(android.content.Intent.ACTION_SEND);
golk.putExtra(android.content.Intent.EXTRA_EMAIL," " );
golk.putExtra(android.content.Intent.EXTRA_SUBJECT,"Check Out This Setup!");
golk.setType("text/plain");
golk.putExtra(android.content.Intent.EXTRA_TEXT, message);
startActivity(golk);
break;
case R.id.copyBtn:
Intent awe = new Intent(CrAETune.this, GoPro.class);
startActivity(awe);
break;}
}
private void deleteContact()
{
AlertDialog.Builder alert = new AlertDialog.Builder(CrAETune.this);
alert.setTitle(R.string.confirmTitle);
alert.setMessage(R.string.confirmMessage);
alert.setPositiveButton(R.string.delete_btn,
new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int button)
{
final CrDbCon dbConnector =
new CrDbCon(CrAETune.this);
AsyncTask<Long, Object, Object> deleteTask =
new AsyncTask<Long, Object, Object>()
{
@Override
protected Object doInBackground(Long... params)
{
dbConnector.deleteContact(params[0]);
return null;
}
@Override
protected void onPostExecute(Object result)
{
finish();
}
};
deleteTask.execute(new Long[] { rowID });
}
}
);
}
private void getstrings() {
// TODO Auto-generated method stub
a=caret.getText().toString();
b=lapet.getText().toString();
c=trket.getText().toString();
pps=ppet.getText().toString();
tys=tyet.getText().toString();
rh1s=rh1.getText().toString();
rh2s=rh2.getText().toString();
sr1s=sr1.getText().toString();
sr2s=sr2.getText().toString();
de1s=de1.getText().toString();
de2s=de2.getText().toString();
dc1s=dc1.getText().toString();
dc2s=dc2.getText().toString();
ar1s=ar1.getText().toString();
ar2s=ar2.getText().toString();
c1s=c1.getText().toString();
c2s=c2.getText().toString();
t1s=t1.getText().toString();
t2s=t2.getText().toString();
bb1s=bb1.getText().toString();
bb2s=bb2.getText().toString();
li1s=li1.getText().toString();
li2s=li2.getText().toString();
la1s=la1.getText().toString();
la2s=la2.getText().toString();
lb1s=lb1.getText().toString();
lb2s=lb2.getText().toString();
df1s=df1.getText().toString();
df2s=df2.getText().toString();
g1s=g1.getText().toString();
g2s=g2.getText().toString();
g3s=g3.getText().toString();
g4s=g4.getText().toString();
g5s=g5.getText().toString();
g6s=g6.getText().toString();
g7s=g7.getText().toString();
gfs=gf.getText().toString();
tss=ts.getText().toString();
hps=hp.getText().toString();
tqs=tq.getText().toString();
lbs=lb.getText().toString();
mils=mil.getText().toString();
rpms=rpm.getText().toString();
partss=parts.getText().toString();
commentss=comments.getText().toString();
}
}