AppInventor SQLite crashes on CREATE TABLE IF NOT EXISTS

Hi all,

I’m new to Android programming. I’m using AppInventor with AI2 Companion and am trying to get Pedroza’s SQLITE off the ground. It is crashing the companion on my phone (Unfortunately, AI2 Companion has stopped working) with the very first SQL command being executed - CREATE TABLE IF NOT EXISTS.

Assuming this Looper.prepare() is the key, the answer from a quick google would appear to be within the java well below the level of AI2. Is there something I can fix on my phone or should I be going back to the author?

Regards,

Phil

LOGCAT as follows:

E/AndroidRuntime(28753): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime(28753): Process: edu.mit.appinventor.aicompanion3, PID: 28753
E/AndroidRuntime(28753): java.lang.RuntimeException: An error occured while exec
uting doInBackground()
E/AndroidRuntime(28753): at android.os.AsyncTask$3.done(AsyncTask.java:30
4)
E/AndroidRuntime(28753): at java.util.concurrent.FutureTask.finishComplet
ion(FutureTask.java:355)
E/AndroidRuntime(28753): at java.util.concurrent.FutureTask.setException(
FutureTask.java:222)
E/AndroidRuntime(28753): at java.util.concurrent.FutureTask.run(FutureTas
k.java:242)
E/AndroidRuntime(28753): at java.util.concurrent.ThreadPoolExecutor.runWo
rker(ThreadPoolExecutor.java:1112)
E/AndroidRuntime(28753): at java.util.concurrent.ThreadPoolExecutor$Worke
r.run(ThreadPoolExecutor.java:587)
E/AndroidRuntime(28753): at java.lang.Thread.run(Thread.java:818)
E/AndroidRuntime(28753): Caused by: java.lang.RuntimeException: Can’t create han
dler inside thread that has not called Looper.prepare()
E/AndroidRuntime(28753): at android.os.Handler.(Handler.java:209)
E/AndroidRuntime(28753): at android.os.Handler.(Handler.java:123)
E/AndroidRuntime(28753): at android.widget.Toast$TN.(Toast.java:349
)
E/AndroidRuntime(28753): at android.widget.Toast.(Toast.java:105)
E/AndroidRuntime(28753): at android.widget.Toast.makeText(Toast.java:263)

E/AndroidRuntime(28753): at com.pedroza.PedrozaSQLite.PedrozaSQLite$DbHel
per.onCreate(PedrozaSQLite.java:73)
E/AndroidRuntime(28753): at android.database.sqlite.SQLiteOpenHelper.getD
atabaseLocked(SQLiteOpenHelper.java:251)
E/AndroidRuntime(28753): at android.database.sqlite.SQLiteOpenHelper.getW
ritableDatabase(SQLiteOpenHelper.java:163)
E/AndroidRuntime(28753): at com.pedroza.PedrozaSQLite.PedrozaSQLite$Execu
teSQL.doInBackground(PedrozaSQLite.java:90)
E/AndroidRuntime(28753): at com.pedroza.PedrozaSQLite.PedrozaSQLite$Execu
teSQL.doInBackground(PedrozaSQLite.java:84)
E/AndroidRuntime(28753): at android.os.AsyncTask$2.call(AsyncTask.java:29
2)
E/AndroidRuntime(28753): at java.util.concurrent.FutureTask.run(FutureTas
k.java:237)
E/AndroidRuntime(28753): … 3 more

Hello Phil,
Can you show the relevant blocks you are using?

Worth noting… PedrozaSQLite.aia works fine on my phone. I was playing with it a couple of days ago. I had thought maybe my Android wasn’t up to it.

It’s just these blocks with the following SQL Statement:

CREATE TABLE IF NOT EXISTS tblTemplate (‘id’ INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, ‘Category’ TEXT NOT NULL, ‘Field2’ TEXT, ‘Field3’ TEXT, ‘Field4’ TEXT, ‘Field5’ TEXT);

1 Like

It works well with me, here it is the .aia I used: testAIA.aia (22,8 KB)
Maybe you can provide your .AIA if you keep getting that error.

I only used classes added in API level minor than 8 (so all apps built with appinventor can use it, without compatibilities problems)

2 Likes

Very strange. Everything is attached.

So points to note:

  • Your testAIA.aia, with your SQL statement works, but only once.

    Step 1: Run it up, including the companion.
    Step 2: Clicking but_ExecuteSQL works.
    Step 3: Clicking but_ClrDatabase works.
    Step 4: Clicking but_ExecuteSQL fails.

I did get a warning that your project was created in a newer version of AI2, if that makes any difference. I wouldn’t think so at this simple level.

Thanks for sticking this out so far…

testAIA(1).aia (22.8 KB)

1 Like

Crashes when I cut out the Companion and install it as an .apk too.

Where are you from? Is English your native language?

I can’t reproduce the problem, it works fine in my cellphone.
The ClearDatabase method shouldn’t be used in production apps. I mean, you can use it, but maybe you should think the strategy of your app better.

Maybe you can tell me a little bit more about the specifications of the cellphone where the extension crashes, for example, Android or API level

2 Likes

Gees, I’ve never been asked that before : / Sorry if I’m being unclear - especially cause I’m from Australia, and English is my only language.

I’m not surprised that you can’t reproduce it. The fault has to be at this end. There’s clearly something going on between my old phones (I’ve tried two) or my old computers, details are below but I think it’s appropriate to take this to the AppInventor google groups now… I shouldn’t be wasting your time for this when it’s not your issue.

Android 5.1 Lollipop_MR1
API 21
Kernel Version 3.10.72
AI2 Companion Version 2.44

I’d already seen your guidance on the clear database function, It’s only in there as a debugging tool, so I can keep executing CREATE TABLE , then clearing the database so I can run it again.

Hahaha I asked just in case you speak spanish like me.

Are you using AppInventor or Thunkable for testing? That error is definetely the SQLite extension because I use those classes

Usually AI, but today I tried AI and Thunkable, and the direct apk install. All 3 failed. Just tried PedrozaSQLite again tonight, and it still works fine, with my SQL statement in it. So confused.

I get that it’s the SQLite extension, but I though maybe my phone/computers had the issue, not your extension.

I googled the error in case it was something I could do at this end… https://stackoverflow.com/questions/3875184/cant-create-handler-inside-thread-that-has-not-called-looper-prepare/16886486#16886486 seemed to have the most info on possible fixes. But then… if it was this, then wouldn’t it always fail??

Anything else you want me to do here?

1 Like

I’ve the same problem: Thunkable app crash both on live and USB connection. If SQLite blocks are disabled all works fine.

Device: Samsung J1
Android version: 4.4.4

Any idea?

2 Likes

Is it because of the Toast? I have to read more about threads.

Try turning it off in the Designer Properties, set the SuppressWarnings to true.

2 Likes