首先,请不要将此问题标记为重复,因为我已经搜索了有关stackoverflow上此错误的每个问题,但仍然没有任何帮助我。我尝试增加数据库版本,卸载并重新安装应用程序,尝试不同的模拟器,甚至尝试在实际的手机上。
这是我的logcat:
$par
[1] 0.9191288 1.0266562 1.1754382 0.9973042 248.5229404 75.2993413 380.2445394 460.2091730
$value
[1] 1031918725
$counts
function gradient
705 76
$convergence
[1] 0
$message
NULL
$hessian
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,] 7.688038e+09 4.293539e+07 0 2.89082527 6.248865e+04 4.860839e+04 0 0.02980232
[2,] 4.293539e+07 2.761336e+06 0 0.29802322 -3.247231e+03 1.245818e+04 0 -0.02980232
[3,] 0.000000e+00 0.000000e+00 0 0.00000000 0.000000e+00 0.000000e+00 0 0.00000000
[4,] 2.890825e+00 2.980232e-01 0 55.25350571 -2.980232e-02 0.000000e+00 0 0.02980232
[5,] 6.248865e+04 -3.247231e+03 0 -0.02980232 8.401275e+01 -3.635883e+00 0 -0.02980232
[6,] 4.860839e+04 1.245818e+04 0 0.00000000 -3.635883e+00 3.185868e+01 0 -0.02980232
[7,] 0.000000e+00 0.000000e+00 0 0.00000000 0.000000e+00 0.000000e+00 0 0.00000000
[8,] 2.980232e-02 -2.980232e-02 0 0.02980232 -2.980232e-02 -2.980232e-02 0 0.02980232
单击ListView中的列表项时发生错误。
04-26 13:43:43.970: E/SQLiteLog(2331): (1) no such table: event
04-26 13:43:43.987: D/AndroidRuntime(2331): Shutting down VM
04-26 13:43:44.007: E/AndroidRuntime(2331): FATAL EXCEPTION: main
04-26 13:43:44.007: E/AndroidRuntime(2331): Process: com.example.shareity, PID: 2331
04-26 13:43:44.007: E/AndroidRuntime(2331): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.shareity/com.example.shareity.NewEvent}: android.database.sqlite.SQLiteException: no such table: event (code 1): , while compiling: SELECT * FROM event
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.app.ActivityThread.access$800(ActivityThread.java:144)
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.os.Handler.dispatchMessage(Handler.java:102)
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.os.Looper.loop(Looper.java:135)
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.app.ActivityThread.main(ActivityThread.java:5221)
04-26 13:43:44.007: E/AndroidRuntime(2331): at java.lang.reflect.Method.invoke(Native Method)
04-26 13:43:44.007: E/AndroidRuntime(2331): at java.lang.reflect.Method.invoke(Method.java:372)
04-26 13:43:44.007: E/AndroidRuntime(2331): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
04-26 13:43:44.007: E/AndroidRuntime(2331): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
04-26 13:43:44.007: E/AndroidRuntime(2331): Caused by: android.database.sqlite.SQLiteException: no such table: event (code 1): , while compiling: SELECT * FROM event
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1255)
04-26 13:43:44.007: E/AndroidRuntime(2331): at com.example.shareity.library.DBHandlerEvent.getEventDetails(DBHandlerEvent.java:97)
04-26 13:43:44.007: E/AndroidRuntime(2331): at com.example.shareity.NewEvent.onCreate(NewEvent.java:100)
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.app.Activity.performCreate(Activity.java:5933)
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
04-26 13:43:44.007: E/AndroidRuntime(2331): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
04-26 13:43:44.007: E/AndroidRuntime(2331): ... 10 more
04-26 13:43:47.066: I/Process(2331): Sending signal. PID: 2331 SIG: 9
}
这是我下次单击列表项时应该进入的意图。
public class ListNew extends Activity {
ListView list;
TextView eid;
TextView ename;
TextView edesc;
//Button Btngetdata;
ArrayList<HashMap<String, String>> oslist = new ArrayList<HashMap<String, String>>();
//URL to get JSON Array
private static String url = "http://<mylink>/test.php/";
//JSON Node Names
private static final String TAG_OS = "events";
private static final String TAG_EID = "eid";
private static final String TAG_ENAME = "ename";
private static final String TAG_ETYPE = "etype";
private static final String TAG_EDESC = "edesc";
private static final String TAG_ESDATE = "esdate";
private static final String TAG_EEDATE = "eedate";
private static final String TAG_ESTIME = "estime";
private static final String TAG_EETIME = "eetime";
private static final String TAG_LOCATION = "location";
private static final String TAG_CREATED_AT = "created_at";
private static final String TAG_EDITED_AT = "edited_at";
private static final String TAG_CREATEDBY = "createdby";
private static final String TAG_APPROVED = "approved";
JSONArray events = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listnew);
oslist = new ArrayList<HashMap<String, String>>();
new JSONParse().execute();
/*
Btngetdata = (Button)findViewById(R.id.getdata);
Btngetdata.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new JSONParse().execute();
}
});
*/
}
private class JSONParse extends AsyncTask<String, String, JSONObject> {
private ProgressDialog pDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
eid = (TextView)findViewById(R.id.vers);
ename = (TextView)findViewById(R.id.name);
edesc = (TextView)findViewById(R.id.api);
pDialog = new ProgressDialog(ListNew.this);
pDialog.setMessage("Getting Data ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected JSONObject doInBackground(String... args) {
JSONParser jParser = new JSONParser();
// Getting JSON from URL
JSONObject json = jParser.getJSONFromUrl2(url);
return json;
}
@Override
protected void onPostExecute(JSONObject json) {
pDialog.dismiss();
try {
// Getting JSON Array from URL
events = json.getJSONArray(TAG_OS);
for(int i = 0; i < events.length(); i++){
JSONObject c = events.getJSONObject(i);
// Storing JSON item in a Variable
String eid = c.getString(TAG_EID);
String ename = c.getString(TAG_ENAME);
String etype = c.getString(TAG_ETYPE);
String edesc = c.getString(TAG_EDESC);
String esdate = c.getString(TAG_ESDATE);
String eedate = c.getString(TAG_EEDATE);
String estime = c.getString(TAG_ESTIME);
String eetime = c.getString(TAG_EETIME);
String location = c.getString(TAG_LOCATION);
String created_at = c.getString(TAG_CREATED_AT);
String edited_at = c.getString(TAG_EDITED_AT);
String createdby = c.getString(TAG_CREATEDBY);
String approved = c.getString(TAG_APPROVED);
// Adding value HashMap key => value
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_EID, eid);
map.put(TAG_ENAME, ename);
map.put(TAG_ETYPE, etype);
map.put(TAG_EDESC, edesc);
map.put(TAG_ESDATE, esdate);
map.put(TAG_EEDATE, eedate);
map.put(TAG_ESTIME, estime);
map.put(TAG_EETIME, eetime);
map.put(TAG_LOCATION, location);
map.put(TAG_CREATED_AT, created_at);
map.put(TAG_EDITED_AT, edited_at);
map.put(TAG_CREATEDBY, createdby);
map.put(TAG_APPROVED, approved);
oslist.add(map);
list=(ListView)findViewById(R.id.list);
//Log.d("TAG_is d first one", TAG_APPROVED + "," + approved);
ListAdapter adapter = new SimpleAdapter(ListNew.this, oslist,
R.layout.list_v,
new String[] { TAG_ENAME,TAG_CREATEDBY, TAG_CREATED_AT }, new int[] {
R.id.vers,R.id.name, R.id.api});
list.setAdapter(adapter);
//Log.d("after setting adapter", TAG_EID + "," + TAG_ENAME);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//Toast.makeText(MainActivity.this, "You Clicked at "+oslist.get(+position).get("ename"), Toast.LENGTH_SHORT).show();
Intent i = new Intent(ListNew.this, NewEvent.class);
i.putExtra("eid", oslist.get(+position).get("eid") );
//i.putExtra("tel", tels.get(position) );
i.putExtra("ename", oslist.get(+position).get("ename") );
i.putExtra("etype", oslist.get(+position).get("etype") );
i.putExtra("edesc", oslist.get(+position).get("edesc") );
i.putExtra("esdate", oslist.get(+position).get("esdate") );
i.putExtra("eedate", oslist.get(+position).get("eedate") );
i.putExtra("estime", oslist.get(+position).get("estime") );
i.putExtra("eetime", oslist.get(+position).get("eetime") );
i.putExtra("location", oslist.get(+position).get("location") );
i.putExtra("created_at", oslist.get(+position).get("created_at") );
i.putExtra("edited_at", oslist.get(+position).get("edited_at") );
i.putExtra("createdby", oslist.get(+position).get("createdby") );
i.putExtra("approved", oslist.get(+position).get("approved") );
startActivity(i);
}
});
}//end if
} catch (JSONException e) {
e.printStackTrace();
}
}
}
编辑:添加了数据库助手类
public class NewEvent extends Activity {
Button bk, newact;
String ename;
String eid;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.event);
//DBHandlerEvent db = new DBHandlerEvent(getApplicationContext());
//HashMap<String, String> event = new HashMap<String, String>();
//event = db.getEventDetails();
bk = (Button) findViewById(R.id.btnbackne);
newact = (Button) findViewById(R.id.btnnewact);
final TextView en = (TextView) findViewById(R.id.tvename);
final TextView des = (TextView) findViewById(R.id.tvdescription);
final TextView sd = (TextView) findViewById(R.id.tvsdate);
final TextView ed = (TextView) findViewById(R.id.tvedate);
final TextView location = (TextView) findViewById(R.id.tvgoal);
final TextView reg = (TextView) findViewById(R.id.tveventregdate);
Intent intent= getIntent();
eid = intent.getStringExtra("eid");
ename = intent.getStringExtra("ename");
String edesc = intent.getStringExtra("edesc");
String esdate = intent.getStringExtra("esdate");
String eedate = intent.getStringExtra("eedate");
String estime = intent.getStringExtra("estime");
String eetime = intent.getStringExtra("eetime");
String loc = intent.getStringExtra("location");
String createdby= intent.getStringExtra("createdby");
//en.setText(eid);
en.setText(ename);
des.setText(edesc);
sd.setText(esdate);
ed.setText(eedate);
//en.setText(estime);
//en.setText(eetime);
location.setText(loc);
reg.setText(createdby);
bk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(v.getContext(), ListNew.class);
startActivityForResult(myIntent, 0);
finish();
}
});
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
HashMap<String,String> user = new HashMap<String, String>();
user = db.getUserDetails();
DBHandlerEvent dbe = new DBHandlerEvent(getApplicationContext());
HashMap<String,String> event = new HashMap<String, String>();
event = dbe.getEventDetails();
String logd = user.get("fname");
String ev = event.get("createdBy");
if (logd.equals(ev)){
newact.setVisibility(View.VISIBLE);
}else{
newact.setVisibility(View.GONE);
}
newact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
/*
Intent myIntent2 = new Intent(v.getContext(), CreateActivity.class);
startActivityForResult(myIntent2, 0);
*/
Intent send = new Intent(NewEvent.this, Donate.class);
send.putExtra("eid", eid);
send.putExtra("ename", ename.toString());
startActivity(send);
finish();
}
});
final TextView createdBy = (TextView) findViewById(R.id.tvCreatedBy);
//createdBy.setText("Event created by: "+user.get("fname"));
}
}
答案 0 :(得分:1)
你需要一个空间:
KEY_ID + "INTEGER PRIMARY KEY,"
所以
KEY_ID + " INTEGER PRIMARY KEY,"
另外,我不确定你为什么要执行这一行:
db.execSQL("PRAGMA foreign_keys=ON;");
答案 1 :(得分:0)
假设您通过增加数据库版本来尝试它。
1.在添加或检索该表中的数据之前,请确保已创建名为 事件 的表。 2.检查你的SqliteOpenHelper类中的方法onCreate()&amp; onUpgrade()。它应该包含这样的东西
private static final String DATABASE_CREATE; // your create table sql command
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(MySQLiteHelper.class.getName(),
"Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_COMMENTS);
onCreate(db);
}
答案 2 :(得分:0)
最后在stackoverflow的聊天部分聊天后,我找到了答案。
该表未在应用程序中的本地数据库文件中创建。不是服务器。所以我添加了
db=openOrCreateDatabase("StudentDB", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS student(eid VARCHAR,ename VARCHAR,esdate VARCHAR);");
到onCreate方法,它现在工作正常:)
答案 3 :(得分:0)
我需要3个小时才能解决这个问题! 这是我的解决方案:
db.execSQL("create table " + CrimeTable.NAME+"("
+ " _id integer primary key autoincrement, "
+ CrimeTable.Cols.UUID + ", "
+ CrimeTable.Cols.TITLE + ", "
+ CrimeTable.Cols.DATE + ", "
+ CrimeTable.Cols.SOLVED + ")" //you should add the space after every ",",just like ", ",not like ",".the space is important!
答案 4 :(得分:0)
此表名/数据库表名的创建不正确的主要原因是,最好的解决方法是再次创建表和更新。它对我有帮助,也解决了。