问:
Caused by: android.database.sqlite.SQLiteException: no such table: (code 1) Android
We have a sqlite database in our Application. Its working fine for all the users but few of them experiencing the Caused by: android.database.sqlite.SQLiteException: no such table: generalSettings (code 1): , while compiling: select * from generalSettings error.

Below is my sqlite helper class to create the db and the error log. In assert/Master.db we have the table  generalSettings. But after copying it to the device the table is missing. This is happening only for few users. I searched for the solution but I cant find the exact one. Team please help me to fix this.

Code:

```<code>import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;

import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;
import android.util.Log;

public class InstallDB extends SQLiteOpenHelper {
    Context ctx;

    String DBNAME;
    String DBPATH;
    Modules modObj = new Modules();

    public InstallDB(Context context, String name) {
        super(context, name, null, 1);
        this.ctx = context;
        this.DBNAME = name;

        this.DBPATH = this.ctx.getDatabasePath(DBNAME).getAbsolutePath();
        Log.e("Path 1", DBPATH);

    }

    public void createDataBase() {

        boolean dbExist = checkDataBase();

        SQLiteDatabase db_Read = null;

        if (!dbExist) {
            synchronized (this) {

                db_Read = this.getReadableDatabase();
                Log.e("Path 2", this.getReadableDatabase().getPath());
                db_Read.close();

                copyDataBase();
                Log.v("copyDataBase---", "Successfully");
            }

            // try {

            // } catch (IOException e) {
            // throw new Error("Error copying database");
            // }
        }
    }

    private boolean checkDataBase() {

        SQLiteDatabase checkDB = null;

        try {
            String myPath = DBPATH;
            checkDB = SQLiteDatabase.openDatabase(myPath, null,
                    SQLiteDatabase.OPEN_READWRITE);
        } catch (Exception e) {
            Log.i("SQLite Error", "database does't exist yet.");
        }

        if (checkDB != null) {
            checkDB.close();
        }

        return checkDB != null ? true : false;
    }

    private void copyDataBase() {

        try {
            InputStream myInput = ctx.getAssets().open(DBNAME);
            String outFileName = DBPATH;

            OutputStream myOutput = new FileOutputStream(outFileName);

            byte[] buffer = new byte[1024 * 3];

            int length = 0;

            while ((length = myInput.read(buffer)) > 0) {
                myOutput.write(buffer, 0, length);
            }

            myOutput.flush();
            myOutput.close();
            myInput.close();
        } catch (Exception e) {
            Modules.stacTaceElement = e.getStackTrace();

            StringWriter stackTrace1 = new StringWriter();
            e.printStackTrace(new PrintWriter(stackTrace1));
            System.err.println(stackTrace1);

            Intent send = new Intent(Intent.ACTION_SENDTO);
            String uriText;

            uriText = "mailto:test@test.com"
                    + "&subject=Error Report"
                    + "&body="
                    + stackTrace1.toString();

            uriText = uriText.replace(" ", "%20");
            Uri uri = Uri.parse(uriText);

            send.setData(uri);
            ctx.startActivity(Intent.createChooser(send, "Send mail..."));
            // TODO: handle exception
        }

    }

    @Override
    public void onCreate(SQLiteDatabase db) {

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
</code>```

Error Log:

```<code>java.lang.RuntimeException: Unable to start activity ComponentInfo{palmagent.FidelityAgent.Two/palmagent.FidelityAgent.Two.PassNew}: android.database.sqlite.SQLiteException: no such table: generalSettings (code 1): , while compiling: select * from generalSettings
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: no such table: generalSettings (code 1): , while compiling: select * from generalSettings
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253)
at palmagent.FidelityAgent.Two.masterDatabase.selectquery(masterDatabase.java:59)
at palmagent.FidelityAgent.Two.Modules.checkDatabase(Modules.java:28825)
at palmagent.FidelityAgent.Two.PassNew$LoaduserDetails.onPreExecute(PassNew.java:140)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
at android.os.AsyncTask.execute(AsyncTask.java:535)
at palmagent.FidelityAgent.Two.PassNew.onCreate(PassNew.java:120)
at android.app.Activity.performCreate(Activity.java:5248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2173)
... 11 more
</code>```

答:
I have had the same issue, when I created an update for app.
By google documentation onCreate() from SQLiteOpenHelper is called only when the app is installed first time.
So if you want to add a table you need to increment the database version and add

```<code>onUpgrade() { your_table.create(database) }
</code>```

@Override
    public void onUpgrade(final SQLiteDatabase database,
                          final int oldVersion,
                          final int newVersion) {
        YourTable.onCreate(database);
  }

Body:
We have a sqlite database in our Application. Its working fine for all the users but few of them experiencing the Caused by: android.database.sqlite.SQLiteException: no such table: generalSettings (code 1): , while compiling: select * from generalSettings error.

Below is my sqlite helper class to create the db and the error log. In assert/Master.db we have the table  generalSettings. But after copying it to the device the table is missing. This is happening only for few users. I searched for the solution but I cant find the exact one. Team please help me to fix this.

Code:

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;

import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;
import android.util.Log;

public class InstallDB extends SQLiteOpenHelper {
    Context ctx;

    String DBNAME;
    String DBPATH;
    Modules modObj = new Modules();

    public InstallDB(Context context, String name) {
        super(context, name, null, 1);
        this.ctx = context;
        this.DBNAME = name;

        this.DBPATH = this.ctx.getDatabasePath(DBNAME).getAbsolutePath();
        Log.e("Path 1", DBPATH);

    }

    public void createDataBase() {

        boolean dbExist = checkDataBase();

        SQLiteDatabase db_Read = null;

        if (!dbExist) {
            synchronized (this) {

                db_Read = this.getReadableDatabase();
                Log.e("Path 2", this.getReadableDatabase().getPath());
                db_Read.close();

                copyDataBase();
                Log.v("copyDataBase---", "Successfully");
            }

            // try {

            // } catch (IOException e) {
            // throw new Error("Error copying database");
            // }
        }
    }

    private boolean checkDataBase() {

        SQLiteDatabase checkDB = null;

        try {
            String myPath = DBPATH;
            checkDB = SQLiteDatabase.openDatabase(myPath, null,
                    SQLiteDatabase.OPEN_READWRITE);
        } catch (Exception e) {
            Log.i("SQLite Error", "database does't exist yet.");
        }

        if (checkDB != null) {
            checkDB.close();
        }

        return checkDB != null ? true : false;
    }

    private void copyDataBase() {

        try {
            InputStream myInput = ctx.getAssets().open(DBNAME);
            String outFileName = DBPATH;

            OutputStream myOutput = new FileOutputStream(outFileName);

            byte[] buffer = new byte[1024 * 3];

            int length = 0;

            while ((length = myInput.read(buffer)) > 0) {
                myOutput.write(buffer, 0, length);
            }

            myOutput.flush();
            myOutput.close();
            myInput.close();
        } catch (Exception e) {
            Modules.stacTaceElement = e.getStackTrace();

            StringWriter stackTrace1 = new StringWriter();
            e.printStackTrace(new PrintWriter(stackTrace1));
            System.err.println(stackTrace1);

            Intent send = new Intent(Intent.ACTION_SENDTO);
            String uriText;

            uriText = "mailto:test@test.com"
                    + "&subject=Error Report"
                    + "&body="
                    + stackTrace1.toString();

            uriText = uriText.replace(" ", "%20");
            Uri uri = Uri.parse(uriText);

            send.setData(uri);
            ctx.startActivity(Intent.createChooser(send, "Send mail..."));
            // TODO: handle exception
        }

    }

    @Override
    public void onCreate(SQLiteDatabase db) {

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}

Error Log:

java.lang.RuntimeException: Unable to start activity ComponentInfo{palmagent.FidelityAgent.Two/palmagent.FidelityAgent.Two.PassNew}: android.database.sqlite.SQLiteException: no such table: generalSettings (code 1): , while compiling: select * from generalSettings
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: no such table: generalSettings (code 1): , while compiling: select * from generalSettings
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253)
at palmagent.FidelityAgent.Two.masterDatabase.selectquery(masterDatabase.java:59)
at palmagent.FidelityAgent.Two.Modules.checkDatabase(Modules.java:28825)
at palmagent.FidelityAgent.Two.PassNew$LoaduserDetails.onPreExecute(PassNew.java:140)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
at android.os.AsyncTask.execute(AsyncTask.java:535)
at palmagent.FidelityAgent.Two.PassNew.onCreate(PassNew.java:120)
at android.app.Activity.performCreate(Activity.java:5248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2173)
... 11 more

Body:
I have had the same issue, when I created an update for app.
By google documentation onCreate() from SQLiteOpenHelper is called only when the app is installed first time.
So if you want to add a table you need to increment the database version and add

onUpgrade() { your_table.create(database) }

@Override
    public void onUpgrade(final SQLiteDatabase database,
                          final int oldVersion,
                          final int newVersion) {
        YourTable.onCreate(database);
  }


来源: stackexchange

问:
How to fix ':app:mergeDebugNativeLibs' exection failed issue?
I had built a flutter app with some of the dependencies (from flutter pub). While running that application, It failed with this exception. How to fix this issue?

What went wrong:

```<code>Execution failed for task ':app:mergeDebugNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > More than one file was found with OS independent path 'lib/x86/libc++_shared.so'
</code>```

Thanks in advance.

答:
I hope I am not very late. I also encountered the same Problem.
Please close the app if running in background then clear any issues if in your code (Your IDE must be showing) and finally run flutter clean and this should do the trick.

Hope this helps. Thanks

ContentLicense: CC BY-SA 4.0

Body:
I had built a flutter app with some of the dependencies (from flutter pub). While running that application, It failed with this exception. How to fix this issue?

What went wrong:

Execution failed for task ':app:mergeDebugNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > More than one file was found with OS independent path 'lib/x86/libc++_shared.so'

Thanks in advance.


问:
Google coral kiosk mode with virtual keyboard
Can i run on the Google Coral devboad a chromium in kiosk mode with a virtual keyboard ?

On this exemple they run a chromium with a mouse.

答:
MendelOs, the os on the dev board is just a derivative of Debian10 (buster).
After some research, I found how how to do it (prior I have no idea what kiosk mode is):

update and install needed packages

```<code>sudo su
apt-get update
apt-get -y install unclutter xorg chromium openbox lightdm locales
</code>```

add kiosk group and user

```<code>groupadd kiosk
user add -m kiosk -g kiosk -s /bin/bash
mkdir -p /home/kiosk/.config/openbox
chown -R kiosk:kiosk
</code>```

Tell lightdm to automatically starts with kiosk user

```<code>cat > /etc/lightdm/lightdm.conf << EOF
[SeatDefaults]
autologin-user=kiosk
EOF
</code>```

Tell kiosk user to do this on start

```<code>cat > /home/kiosk/.config/openbox/autostart << EOF
#!/bin/bash

unclutter -idle 0.1 -grab -root &

while:
do
  chromium \
    --no-first-run \
    --start-maximized \
    --window-position=0,0 \
    --window-size=1024,768 \
    --disable \
    --disable-translate \
    --disable-infobars \
    --disable-suggestions-service \
    --disable-save-password-bubble \
    --disable-session-crashed-bubble \
    --incognito \
    --kiosk "https://google.com/"
  sleep 5
done &
EOF
</code>```

Cheers

Body:
MendelOs, the os on the dev board is just a derivative of Debian10 (buster).
After some research, I found how how to do it (prior I have no idea what kiosk mode is):

update and install needed packages

sudo su
apt-get update
apt-get -y install unclutter xorg chromium openbox lightdm locales

add kiosk group and user

groupadd kiosk
user add -m kiosk -g kiosk -s /bin/bash
mkdir -p /home/kiosk/.config/openbox
chown -R kiosk:kiosk

Tell lightdm to automatically starts with kiosk user

cat > /etc/lightdm/lightdm.conf << EOF
[SeatDefaults]
autologin-user=kiosk
EOF

Tell kiosk user to do this on start

cat > /home/kiosk/.config/openbox/autostart << EOF
#!/bin/bash

unclutter -idle 0.1 -grab -root &

while:
do
  chromium \
    --no-first-run \
    --start-maximized \
    --window-position=0,0 \
    --window-size=1024,768 \
    --disable \
    --disable-translate \
    --disable-infobars \
    --disable-suggestions-service \
    --disable-save-password-bubble \
    --disable-session-crashed-bubble \
    --incognito \
    --kiosk "https://google.com/"
  sleep 5
done &
EOF

Cheers


问:
Is it better way to avoid „Cannot use mutating member on immutable” in var
I have a struct with var grid

```<code>struct Machina {
    ....
    var grid: [Whatever] = []
    var other: Something
    ... // other stuff
}
</code>```

But grid needs to be counted every time other changes. So, I can call

```<code>var other: Something {
    didSet {
        defineGrid()
    }
...

mutating func defineGrid() {
    var result: [Whatever]
    ... // count result
    grid = result
}
</code>```

but I would love to simply call grid as var and keep counted grid in _grid

```<code>var _grid: [Whatever]? = nil
var other: Something {
    didSet {
        _grid = nil
    }
...

mutating func defineGrid() {
    var result: [Whatever]
    ... // count result
    _grid = result
}
...
var grid: [Whatever] {
    if _grid == nil {
        defineGrid() // error: Cannot use mutating member on immutable value: 'self' is immutable
    }
    return _grid!
}
</code>```

but in this case I got an error. Is a first approach nice? Is it possible to get var grid from second approach? Maybe it's just a cosmetics. I don't know.

答:
As Alexander said, you need a mutating getter for grid:

```<code>var grid: [Whatever] {
    mutating get {
        if _grid == nil {
            defineGrid()
        }
        return _grid!
    }
}
</code>```

Also, _grid should probably be private.

Body:
I have a struct with var grid

struct Machina {
    ....
    var grid: [Whatever] = []
    var other: Something
    ... // other stuff
}

But grid needs to be counted every time other changes. So, I can call

var other: Something {
    didSet {
        defineGrid()
    }
...

mutating func defineGrid() {
    var result: [Whatever]
    ... // count result
    grid = result
}

but I would love to simply call grid as var and keep counted grid in _grid

var _grid: [Whatever]? = nil
var other: Something {
    didSet {
        _grid = nil
    }
...

mutating func defineGrid() {
    var result: [Whatever]
    ... // count result
    _grid = result
}
...
var grid: [Whatever] {
    if _grid == nil {
        defineGrid() // error: Cannot use mutating member on immutable value: 'self' is immutable
    }
    return _grid!
}

but in this case I got an error. Is a first approach nice? Is it possible to get var grid from second approach? Maybe it's just a cosmetics. I don't know.

Body:
As Alexander said, you need a mutating getter for grid:

var grid: [Whatever] {
    mutating get {
        if _grid == nil {
            defineGrid()
        }
        return _grid!
    }
}

Also, _grid should probably be private.


问:
Compare the first word of a page title to an array in Javascript
the following code gets the page title, compares it with data in array and outputs me a final value

```<code>var title = (document.title);

//test variables
testarray =["blue","top","110","in stock", "red","down","111","in stock"]

//function
function testfunction(array, variable){
    var varindex = array.indexOf(variable)
    return array[varindex+2]
}
//calling the function
testfunction(testarray, title)

var finalvalue = testfunction(testarray, title);
</code>```

So if my page title is Blue, it gives me the value 110 that is what I need.
It works fine but in this way the only valid title for my page has to be Blue, otherwise it won't work.

I would like to be able to have a longer page title like Blue Shoes .  I tried by adding the following variable at the beginning to get only the title first word

```<code>var fulltitle = (document.title);
var title = fulltitle.split(' ').slice(0,1);
</code>```

but it doesn't work. What is wrong with my code ?
thanks

答: Try var title = fulltitle.split(' ')[0]. And bring the compared parts to the same register var varindex = array.indexOf(variable.toLowerCase()).

Body:
the following code gets the page title, compares it with data in array and outputs me a final value

var title = (document.title);

//test variables
testarray =["blue","top","110","in stock", "red","down","111","in stock"]

//function
function testfunction(array, variable){
    var varindex = array.indexOf(variable)
    return array[varindex+2]
}
//calling the function
testfunction(testarray, title)

var finalvalue = testfunction(testarray, title);

So if my page title is Blue, it gives me the value 110 that is what I need.
It works fine but in this way the only valid title for my page has to be Blue, otherwise it won't work.

I would like to be able to have a longer page title like Blue Shoes .  I tried by adding the following variable at the beginning to get only the title first word

var fulltitle = (document.title);
var title = fulltitle.split(' ').slice(0,1);

but it doesn't work. What is wrong with my code ?
thanks