Sorry for my bad English.
I'm trying to implement the code on the next page Using your own SQLite database in Android applications | ReignDesign Blog
But get this error
I'm trying to implement the code on the next page Using your own SQLite database in Android applications | ReignDesign Blog
But get this error
Compiling code. 0.03
Generating R file. 0.00
Compiling generated Java code. Error
B4A line: 11
Dim mySql As iniSQL
javac 1.6.0_21
src\gebial\b4a\proba1\main.java:251: cannot find symbol
symbol : constructor myDB()
location: class Gebial.b4a.dbHelper.myDB
mostCurrent._mysql = new Gebial.b4a.dbHelper.myDB();
^
1 error
B4X:
package Gebial.b4a.dbHelper;
/**
*
* crear la base de datos
* */
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.SQLException;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
@ShortName("iniSQL")
@Version(1.0f)
@Author("JMMG")
/**
*
* la clase la base de datos
* */
public class myDB extends SQLiteOpenHelper {
/**
*
* crear la base de datos
* */
private static String DB_PATH = "/data/data/Gebial.Probes.MiTabHost/databases/";
private static String DB_NAME = "GebiliteAndroid.db";
private SQLiteDatabase myDatabase;
private final Context myContext;
public myDB(Context context) {
super(context, DB_NAME, null, 1);
this.myContext = context;
// TODO Auto-generated constructor stub
}
/**
*
* crear la base de datos
* */
public void createDatabase () throws IOException {
boolean dbExists = CheckDatabase();
if ( dbExists ) {
}
else {
this.getReadableDatabase();
try {
copyDatabase();
} catch ( IOException e) {
throw new Error("Error copiando la base de datos");
}
}
}
/**
*
* comprobar si la base de datos existe
* */
private boolean CheckDatabase () {
SQLiteDatabase checkDB = null;
try {
String myPath = DB_PATH + DB_NAME;
checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
} catch (SQLiteException e) {
}
if ( checkDB != null) {
checkDB.close();
}
return checkDB != null ? true : false;
}
/**
*
* Copia mi base de datos desde el caperta assets local al
* to the just created empty database in the
* system folder, from where it can be accessed and handled.
* This is done by transfering bytestream.
* */
private void copyDatabase() throws IOException{
InputStream myInput = myContext.getAssets().open(DB_NAME);
String outFilename = DB_PATH + DB_NAME;
OutputStream myOutput = new FileOutputStream(outFilename);
byte[] buffer = new byte[1024];
int length;
while ((length=myInput.read(buffer))>0) {
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
}
/**
*
* abre la base de datos
* */
public void openDatabase () throws SQLException {
String myPath = DB_PATH + DB_NAME;
myDatabase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}
/**
*
* sobreescribir oncreate
* */
@Override
public void onCreate (SQLiteDatabase db) {
}
/**
*
* sobreescribir onUPgrade
* */
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
/**
*
* Sobreescribir onClose
* */
@Override
public synchronized void close () {
if (myDatabase != null)
myDatabase.close();
super.close();
}
}