Reputation: 40182
Using Trigger.io's barcode api in an application that only contains boilerplate HTML and the following JavaScript:
forge.barcode.scan(function (value) {
alert("You scanned: "+value);
});
I get the following error in the log:
Forge Java error: RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
Full error entry:
[INFO] D/Forge ( 1109): Returned: {"content":{"message":"Forge Java error: RuntimeException: Can't create handler inside thread that has not called Looper.prepare()","type":"UNEXPECTED_FAILURE","subtype":null,"full_error":"java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() at android.os.Handler.(Handler.java:197) at android.os.Handler.(Handler.java:111) at android.app.Dialog.(Dialog.java:107) at android.app.AlertDialog.(AlertDialog.java:114) at android.app.AlertDialog$Builder.create(AlertDialog.java:931) at android.app.AlertDialog$Builder.show(AlertDialog.java:950) at io.trigger.forge.android.modules.barcode.API.scan(API.java:68) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at io.trigger.forge.android.core.ForgeApp.callJavaFromJavaScript(ForgeApp.java:247) at io.trigger.forge.android.core.ForgeJSBridge$1.run(ForgeJSBridge.java:17) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) at java.lang.Thread.run(Thread.java:856)\n"},"callid":"35E46BC5-1C17-4354-B09B-BE67B5FCD513","status":"error"}
Update:
Below is my code:
File config.json
{
"config_version": "2",
"name": "Scan to Web",
"author": "[email protected]",
"version": "0.1",
"platform_version": "v1.4",
"description": "An empty app created by default",
"modules": {
"logging": {
"level": "DEBUG"
},
"barcode": true,
"contact": true,
"file": true,
"is": true,
"media": true,
"prefs": true,
"request": {
"permissions": ["http://*/*", "https://*/*"]
},
"tools": true,
"reload": true
}
}
File default.js
forge.barcode.scan(function (value) {
alert("You scanned: "+value);
});
File index.html
<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
<link rel="stylesheet" href="css/jquery.mobile-1.1.0.min.css" />
<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/jquery.mobile-1.1.0.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<script type="text/javascript" src="js/default.js"></script>
</head>
<body>
<p>Hello world!</p>
</body>
</html>
Upvotes: 1
Views: 238
Reputation: 27492
There was a threading problem in Trigger.io version v1.4.26 - it's fixed in v1.4.27 upwards.
Sorry for the inconvenience!
Upvotes: 1
Reputation: 66
Try one of two things:
1) Turn Reload module on in your app configuration. I know it sounds weird or stupid, but trust me, it should resolve your problem for now. I had very similar issue with Request module when Reload was off.
2) Change "platform_version" in your src/config.json from "v1.4" to "v1.4.25". I think last platform version is a bit broken.
Upvotes: 3
Reputation: 117597
This exception is usually raised if you are calling a UI-related code from a thread other than the UI-thread. If this is Java I would use:
activity.runOnUiThread(new Runnable()
{
@Override
public void run()
{
// place your code here
}
});
Upvotes: 0