强文
我无法打开数据库和查询。我想访问使用意图值从不同的java文件传递的表行。请帮忙 !
import java.io.File;
import java.util.ArrayList;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.Toast;
public class Finish_kitchen extends Activity {
GridView gridView;
private imageAdapter imageAdapter;
private SQLiteDatabase db;
private static String DB_Path = "/mnt/sdcard/Kitchen_Data.db";
private Cursor c;
private String path;
private ListView listView1;
private ArrayList<String> Steps;
private ArrayList<String> Image_path;
private ArrayList<String> Audio_path;
private int count;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.finish_kit);
listView1 = (ListView) findViewById(R.id.listView1);
Steps = new ArrayList<String>();
Image_path = new ArrayList<String>();
Audio_path = new ArrayList<String>();
path = getIntent().getStringExtra("path");
db = SQLiteDatabase.openDatabase(DB_Path, null, SQLiteDatabase.OPEN_READWRITE);
c = db.query(path, null, null, null, null, null, null);
c.moveToFirst();
Steps.add(c.getString(1));
Toast.makeText(getApplicationContext(), "heyaa gotcha", Toast.LENGTH_LONG).show();
}
}
logcat的
04-04 11:50:02.411:D / PackageItemInfo(26824): loadIcon(缓存)名称= org.example.beproj.MainActivity 04-04 11:50:49.752:D / skia(26824):新的语言环境 04-04 11:50:54.116:W / IInputConnectionWrapper(26824):showStatusIcon在非活动的InputConnection上 04-04 11:52:06.674:W / MediaRecorder(26824):mediarecorder因未处理的事件而离开 04-04 11:52:12.390:E / SQLiteLog(26824):( 1)接近&#34; /&#34;:语法错误 04-04 11:52:12.390:D / AndroidRuntime(26824):关闭VM 04-04 11:52:12.390:W / dalvikvm(26824):threadid = 1:线程退出未捕获异常(组= 0x41b11ae0) 04-04 11:52:12.400:E / AndroidRuntime(26824):致命异常:主要 04-04 11:52:12.400:E / AndroidRuntime(26824):java.lang.RuntimeException:无法启动活动 ComponentInfo {org.example.beproj / org.example.beproj.Finish_kitchen}: android.database.sqlite.SQLiteException:near&#34; /&#34;:语法错误(代码 1):,编译时:SELECT * FROM / storage / sdcard0 / Kitchen / mnvx 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2186) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.app.ActivityThread.access $ 600(ActivityThread.java:145) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1238) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.os.Handler.dispatchMessage(Handler.java:99) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.os.Looper.loop(Looper.java:137) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.app.ActivityThread.main(ActivityThread.java:5099) 04-04 11:52:12.400:E / AndroidRuntime(26824):at java.lang.reflect.Method.invokeNative(Native Method) 04-04 11:52:12.400:E / AndroidRuntime(26824):at java.lang.reflect.Method.invoke(Method.java:511) 04-04 11:52:12.400:E / AndroidRuntime(26824):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:803) 04-04 11:52:12.400:E / AndroidRuntime(26824):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:570) 04-04 11:52:12.400:E / AndroidRuntime(26824):at dalvik.system.NativeStart.main(Native Method) 04-04 11:52:12.400:E / AndroidRuntime(26824):引起:android.database.sqlite.SQLiteException:near&#34; /&#34;:语法错误(代码 1):,编译时:SELECT * FROM / storage / sdcard0 / Kitchen / mnvx 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native) 方法) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:888) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:499) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.database.sqlite.SQLiteProgram。(SQLiteProgram.java:58) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.database.sqlite.SQLiteQuery。(SQLiteQuery.java:37) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200) 04-04 11:52:12.400:E / AndroidRuntime(26824):at org.example.beproj.Finish_kitchen.onCreate(Finish_kitchen.java:50) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.app.Activity.performCreate(Activity.java:5117) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081) 04-04 11:52:12.400:E / AndroidRuntime(26824):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2150) 04-04 11:52:12.400:E / AndroidRuntime(26824):... 11更多 04-04 11:52:14.922:I / Process(26824):发送信号。 PID:26824 SIG:9
答案 0 :(得分:0)
c = db.query(path, null, null, null, null, null, null);
第一个参数应该是您的表名。但是你提供了一个文件路径。
以下是错误消息 -
11:52:12.400: E/AndroidRuntime(26824): Caused by: android.database.sqlite.SQLiteException: near "/": syntax error (code 1): , while compiling: SELECT * FROM /storage/sdcard0/Kitchen/mnvx