1週間前から本当に問題があります。バーコードの結果をZXingを使って表示する(SQLiteでそのような列はありません)
私はこのようなエラー得た:
03-04 14:55:35.690:E/AndroidRuntime(8700):java.lang.RuntimeException:活性ComponentInfo {thet.mon.aye/thetを開始できません.mon.aye.DevilscanActivity}:android.database.sqlite.SQLiteException:いいえ、そのようなコラム:barcodeType:、コンパイル中:ノート 親切に助けてくださいFROM _id、barcodeType、価格を選択!
私は中級Javaレベルで初心者のAndroidプログラマーです。私がやろうとしています何
は、複数のバーコードをスキャンし、だから、彼らに
を一覧表示することで、私の最初の画面で、私は1つ、「スキャン」ボタンを持って、私はバーコードをスキャンするとき、その結果を以下に示しますその「スキャン」ボタン。このプログラムとZXing活動の主であるListActivity:
私は2つの活動を使用しています。 バーコードの情報を格納するSQLiteアダプタがあります。 1)DevilScanActivity.java listactivityについて:擬似コードはListActivityは、ZXing活動を呼び出すバーコードの結果を取得し、私は3つのJavaクラスを持っている(私の場合BarcodeDBAdapterです)SQLiteデータベース
に保管するということですこれは私DevilScanActivity.java
`
package thet.mon.aye;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class DevilscanActivity extends ListActivity {
/** Called when the activity is first created. */
private static final int ACTIVITY_CREATE=0;
private BarcodeDBAdapter mDbHelper;
private Cursor mNotesCursor;
private ZxingScan zxscan;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.barcode_list);
mDbHelper = new BarcodeDBAdapter(this);
mDbHelper.open();
fillData();
// getListView();
final Button scanButton = (Button) findViewById(R.id.button);
scanButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
// call ZXingScan on click !
zxscan.getIntent();
finish();
}
});
}
private void fillData() {
// Get all of the rows from the database and create the item list
mNotesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(mNotesCursor);
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{BarcodeDBAdapter.KEY_BARCODE_TYPE};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.text1};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.barcode_row, mNotesCursor, from, to);
setListAdapter(notes);
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
l=getListView();
Cursor c = mNotesCursor;
c.moveToPosition(position);
Intent i = new Intent(this, ZxingScan.class);
i.putExtra(BarcodeDBAdapter.KEY_ROWID, id);
i.putExtra(BarcodeDBAdapter.KEY_BARCODE_TYPE, c.getString(
c.getColumnIndexOrThrow(BarcodeDBAdapter.KEY_BARCODE_TYPE)));
i.putExtra(BarcodeDBAdapter.KEY_PRICE, c.getString(
c.getColumnIndexOrThrow(BarcodeDBAdapter.KEY_PRICE)));
startActivityForResult(i, ACTIVITY_CREATE);
}
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
Bundle extras = intent.getExtras();
switch(requestCode) {
case ACTIVITY_CREATE:
String title = extras.getString(BarcodeDBAdapter.KEY_BARCODE_TYPE);
String body = extras.getString(BarcodeDBAdapter.KEY_PRICE);
mDbHelper.createNote(title, body);
fillData();
break;
}
}
}
であるSQLiteデータベース
あるバーコード走査活性 3であるか、またはメイン 2)ZXingScan)BarcodeDBAdapter
`
これは、これは私のBarcodeDBAdapterである私のZXingScan.java
package thet.mon.aye;
import android.app.Activity;
import android.content.Intent;
public class ZxingScan extends Activity {
private BarcodeDBAdapter barcodedb;
public void onActivityResult(int requestCode, int resultCode, Intent intent1) {
intent1 = new Intent("com.google.zxing.client.android.SCAN");
intent1.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent1, 0);
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent1.getStringExtra("SCAN_RESULT");
String format = intent1.getStringExtra("SCAN_RESULT_FORMAT");
barcodedb.createNote(contents, format);
// call DevilscanActivity
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
}
です:
package thet.mon.aye;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class BarcodeDBAdapter {
public static final String KEY_BARCODE_TYPE = "barcodeType";
public static final String KEY_PRICE = "price";
public static final String KEY_ROWID = "_id";
private static final String TAG = "BarCodeDbAdapter";
private DatabaseHelper mDbHelper;
private SQLiteDatabase mDb;
private static final String DATABASE_CREATE =
"create table notes (_id integer primary key autoincrement, "
+ "title text not null, body text not null);";
private static final String DATABASE_NAME = "data";
private static final String DATABASE_TABLE = "notes";
private static final int DATABASE_VERSION = 2;
private final Context mCtx;
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS notes");
onCreate(db);
}
}
/**
* Constructor - takes the context to allow the database to be
* opened/created
*
* @param ctx the Context within which to work
*/
public BarcodeDBAdapter(Context ctx) {
this.mCtx = ctx;
}
public BarcodeDBAdapter open() throws SQLException {
mDbHelper = new DatabaseHelper(mCtx);
mDb = mDbHelper.getWritableDatabase();
return this;
}
public void close() {
mDbHelper.close();
}
/**
* Create a new note using the title and body provided. If the note is
* successfully created return the new rowId for that note, otherwise return
* a -1 to indicate failure.
*
* @param title the title of the note
* @param body the body of the note
* @return rowId or -1 if failed
*/
public long createNote(String title, String body) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_BARCODE_TYPE, title);
initialValues.put(KEY_PRICE, body);
return mDb.insert(DATABASE_TABLE, null, initialValues);
}
/**
* Delete the note with the given rowId
*
* @param rowId id of note to delete
* @return true if deleted, false otherwise
*/
public boolean deleteNote(long rowId) {
return mDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
}
/**
* Return a Cursor over the list of all notes in the database
*
* @return Cursor over all notes
*/
public Cursor fetchAllNotes() {
return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_BARCODE_TYPE,
KEY_PRICE}, null, null, null, null, null);
}
/**
* Return a Cursor positioned at the note that matches the given rowId
*
* @param rowId id of note to retrieve
* @return Cursor positioned to matching note, if found
* @throws SQLException if note could not be found/retrieved
*/
public Cursor fetchNote(long rowId) throws SQLException {
Cursor mCursor =
mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
KEY_BARCODE_TYPE, KEY_PRICE}, KEY_ROWID + "=" + rowId, null,
null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
/**
* Update the note using the details provided. The note to be updated is
* specified using the rowId, and it is altered to use the title and body
* values passed in
*
* @param rowId id of note to update
* @param title value to set note title to
* @param body value to set note body to
* @return true if the note was successfully updated, false otherwise
*/
public boolean updateNote(long rowId, String title, String body) {
ContentValues args = new ContentValues();
args.put(KEY_BARCODE_TYPE, title);
args.put(KEY_PRICE, body);
return mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
}
}
================== ========================================== ============== DatabaseDBクラスで次のスクリプトを実行した後、私のSQLiteは大丈夫です! プライベート静的最終文字列DATABASE_CREATE = "作成テーブルが存在しない" + DATABASE_TABLE + "(" + " KEY_ROWID +" INTEGERプライマリキー自動化、+ KEY_PRICE + "TEXT NOT NULL" + KEY_BARCODE_TYPE + "TEXT NOT NULL); ";
しかし、2から3に、例えば、フォーム1〜2データベースバージョンを、インクリメントすることを忘れないでください!
が、私がnullpointer例外が発生しました! ===========================================ください
再び助けます========================================
03-04 18:21:41.640: E/AndroidRuntime(9648): FATAL EXCEPTION: main
03-04 18:21:41.640: E/AndroidRuntime(9648): java.lang.RuntimeException: Unable to start activity ComponentInfo{thet.mon.aye/thet.mon.aye.DevilscanActivity}: java.lang.NullPointerException
03-04 18:21:41.640: E/AndroidRuntime(9648): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2781)
03-04 18:21:41.640: E/AndroidRuntime(9648): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
03-04 18:21:41.640: E/AndroidRuntime(9648): at android.app.ActivityThread.access$2300(ActivityThread.java:135)
03-04 18:21:41.640: E/AndroidRuntime(9648): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
03-04 18:21:41.640: E/AndroidRuntime(9648): at android.os.Handler.dispatchMessage(Handler.java:99)
03-04 18:21:41.640: E/AndroidRuntime(9648): at android.os.Looper.loop(Looper.java:143)
03-04 18:21:41.640: E/AndroidRuntime(9648): at android.app.ActivityThread.main(ActivityThread.java:4914)
03-04 18:21:41.640: E/AndroidRuntime(9648): at java.lang.reflect.Method.invokeNative(Native Method)
03-04 18:21:41.640: E/AndroidRuntime(9648): at java.lang.reflect.Method.invoke(Method.java:521)
03-04 18:21:41.640: E/AndroidRuntime(9648): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
03-04 18:21:41.640: E/AndroidRuntime(9648): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
03-04 18:21:41.640: E/AndroidRuntime(9648): at dalvik.system.NativeStart.main(Native Method)
03-04 18:21:41.640: E/AndroidRuntime(9648): Caused by: java.lang.NullPointerException
03-04 18:21:41.640: E/AndroidRuntime(9648): at thet.mon.aye.DevilscanActivity.onCreate(DevilscanActivity.java:28)
03-04 18:21:41.640: E/AndroidRuntime(9648): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1065)
03-04 18:21:41.640: E/AndroidRuntime(9648): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745)
私は、データベースDBクラスのDATABASE_CREATEに対して次のように変更すると、データベースの例外がもうなくなったことを知りました。しかし、私はnullポインタの例外を持っています! :(助け~~ プライベート静的最終文字列DATABASE_CREATE = "存在しない場合、テーブルを作成" + DATABASE_TABLE + "(" + KEY_ROWID + "INTEGERプライマリキーAUTOINCREMENT、" + KEY_PRICE + "TEXT NOT NULL、" + KEY_BARCODE_TYPE + "TEXT –
私たちに助けになるNullPointerExceptionスタックトレースを教えてください。 – YuviDroid
ちょっとYuviDroid、私はちょうどそれをしました。親切にチェックしてください:) –