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?



LOGCAT as follows:

E/AndroidRuntime(28753): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime(28753): Process:, PID: 28753
E/AndroidRuntime(28753): java.lang.RuntimeException: An error occured while exec
uting doInBackground()
E/AndroidRuntime(28753): at android.os.AsyncTask$3.done(
E/AndroidRuntime(28753): at java.util.concurrent.FutureTask.finishComplet
E/AndroidRuntime(28753): at java.util.concurrent.FutureTask.setException(
E/AndroidRuntime(28753): at
E/AndroidRuntime(28753): at java.util.concurrent.ThreadPoolExecutor.runWo
E/AndroidRuntime(28753): at java.util.concurrent.ThreadPoolExecutor$Worke
E/AndroidRuntime(28753): at
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.(
E/AndroidRuntime(28753): at android.os.Handler.(
E/AndroidRuntime(28753): at android.widget.Toast$TN.(
E/AndroidRuntime(28753): at android.widget.Toast.(
E/AndroidRuntime(28753): at android.widget.Toast.makeText(

E/AndroidRuntime(28753): at com.pedroza.PedrozaSQLite.PedrozaSQLite$DbHel
E/AndroidRuntime(28753): at android.database.sqlite.SQLiteOpenHelper.getD
E/AndroidRuntime(28753): at android.database.sqlite.SQLiteOpenHelper.getW
E/AndroidRuntime(28753): at com.pedroza.PedrozaSQLite.PedrozaSQLite$Execu
E/AndroidRuntime(28753): at com.pedroza.PedrozaSQLite.PedrozaSQLite$Execu
E/AndroidRuntime(28753): at android.os.AsyncTask$
E/AndroidRuntime(28753): at
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:


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)


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


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… 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?


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.