在Angular.js中制作了一个简单的库存应用程序。一切都适用于Firefox,Opera,IE,但不适用于Chrome。
错误:无法在“历史记录”上执行'replaceState':一个历史状态对象,其URL为'file:/// C:/Users/Digital%20Jalebi%20-%20uno/Desktop/ANGULAR/index.html# /'无法在原点为'null'的文档中创建。
angular.js:9199
的问题
public class DictionaryDatabaseHelper extends SQLiteOpenHelper {
final static String DICTIONARY_DATABASE="dictionary";
final static String ITEM_ID_COLUMN="id";
final static String WORD_COLUMN="word";
final static String DEFINITION_COLUMN="definition";
final static String CREATE_DATABASE_QUERY="CREATE TABLE "+DICTIONARY_DATABASE+" ( "+
ITEM_ID_COLUMN+" INTEGER PRIMARY KEY AUTOINCREMENT, "+
WORD_COLUMN+" TEXT , "+
DEFINITION_COLUMN+" TEXT)";
final static String ON_UPGRADE_QUERY="DROP TABLE "+DICTIONARY_DATABASE;
Context context;
public DictionaryDatabaseHelper(Context context, String name,
CursorFactory factory, int version) {
super(context, DICTIONARY_DATABASE, factory, version);
this.context=context;
}
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(CREATE_DATABASE_QUERY);
}
@Override
public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
database.execSQL(ON_UPGRADE_QUERY);
onCreate(database);
}
public long insertData(WordDefinition wordDefinition) {
SQLiteDatabase database=this.getWritableDatabase();
ContentValues values=new ContentValues();
values.put(WORD_COLUMN, wordDefinition.word);
values.put(DEFINITION_COLUMN, wordDefinition.definition);
return database.insert(DICTIONARY_DATABASE, null, values);
}
public long updateData(WordDefinition wordDefinition) {
SQLiteDatabase database=this.getWritableDatabase();
ContentValues values=new ContentValues();
values.put(WORD_COLUMN, wordDefinition.word);
values.put(DEFINITION_COLUMN, wordDefinition.definition);
return database.update(DICTIONARY_DATABASE, values, WORD_COLUMN+" =?", new String[]{wordDefinition.word});
}
public void deleteData(WordDefinition wordDefinition) {
SQLiteDatabase database=this.getWritableDatabase();
String queryString="DELETE FROM "+DICTIONARY_DATABASE+" WHERE "+WORD_COLUMN+" = '"+wordDefinition.word+"'";
database.execSQL(queryString);
}
public ArrayList<WordDefinition> getAllWords() {
ArrayList<WordDefinition> arrayList=new ArrayList<WordDefinition>();
SQLiteDatabase database=this.getReadableDatabase();
String selectAllQueryString="SELECT * FROM "+DICTIONARY_DATABASE;
Cursor cursor=database.rawQuery(selectAllQueryString, null);
if (cursor.moveToFirst()) {
do {
WordDefinition wordDefinition=new WordDefinition(cursor.getString(cursor.getColumnIndex(WORD_COLUMN)), cursor.getString(cursor.getColumnIndex(DEFINITION_COLUMN)));
arrayList.add(wordDefinition);
} while (cursor.moveToNext());
}
return arrayList;
}
public WordDefinition getWordDefinition(String word) {
SQLiteDatabase database=this.getReadableDatabase();
WordDefinition wordDefinition=null;
String selectQueryString="SELECT * FROM "+DICTIONARY_DATABASE+ " WHERE "+WORD_COLUMN+" = '"+word+ "'";
Cursor cursor=database.rawQuery(selectQueryString, null);
if (cursor.moveToFirst()) {
wordDefinition=new WordDefinition(cursor.getString(cursor.getColumnIndex(WORD_COLUMN)), cursor.getString(cursor.getColumnIndex(DEFINITION_COLUMN)));
}
return wordDefinition;
}
public WordDefinition getWordDefinition(long id) {
SQLiteDatabase database=this.getReadableDatabase();
WordDefinition wordDefinition=null;
String selectQueryString="SELECT * FROM "+DICTIONARY_DATABASE+ " WHERE "+ITEM_ID_COLUMN+" = '"+id+ "'";
Cursor cursor=database.rawQuery(selectQueryString, null);
if (cursor.moveToFirst()) {
wordDefinition=new WordDefinition(cursor.getString(cursor.getColumnIndex(WORD_COLUMN)), cursor.getString(cursor.getColumnIndex(DEFINITION_COLUMN)));
}
return wordDefinition;
}
public void initializeDatabaseFortheFirstTime(ArrayList<WordDefinition> wordDefinitions) {
SQLiteDatabase database=this.getWritableDatabase();
database.execSQL("BEGIN");
ContentValues contentValues=new ContentValues();
for (WordDefinition wordDefinition : wordDefinitions) {
contentValues.put(WORD_COLUMN, wordDefinition.word);
contentValues.put(DEFINITION_COLUMN, wordDefinition.definition);
database.insert(DICTIONARY_DATABASE, null, contentValues);
}
database.execSQL("COMMIT");
}
}
在Stack Overflow上的某处阅读:
某些浏览器(例如Chrome)不允许在file://
上使用跨源确保从本地服务器(如Wamp)
运行应用程序然后它会起作用
尝试过WAmp - 没有成功。让我知道如何调试它。
答案 0 :(得分:1)
尝试在本地服务器上运行该应用程序。