My simple app with just a webview crashes with a CalledFromWrongThreadException. It is just a button that fires an event onclick to titanium. Titanium "natively" fires an event with a response message that is written to a div delement in the page.
This works fine but... the app "mostly" crashes, especially when the keyboard ist still open when the button is clicked.
What am I doing wrong? Any ideas welcome!
Info&start of stacktrace
Application type: mobile Titanium SDK: 2.0.1 (04/12/12 16:33 999c68a) <from log, console empty at launch!> Platform & version: Android 2.2 Device: Android emulator AND physical device model Host Operating System: Windows 7 Titanium Studio: 2.1.0.201205041150 [ERROR][TiApplication( 267)] (KrollRuntimeThread) [43669,72437] Sending event: exception on thread: KrollRuntimeThread msg:android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.; Titanium 2.0.1,2012/04/12 16:36,999c68a [ERROR][TiApplication( 267)] android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.ApplicationWindow() in Titanium,
function ApplicationWindow() { //create component instance var self = Ti.UI.createWindow({ backgroundColor:'#ffffff', navBarHidden:true, exitOnClose:true }); //construct UI var webView = Ti.UI.createWebView({url:"../page/index.html"}); self.add(webView); Ti.App.addEventListener('performSearch', function(evt) { Ti.App.fireEvent('searchResult', {message:"Searching for "+evt.data+": No result."}); return false; }); return self; } //make constructor function the public component interface module.exports = ApplicationWindow;html/js in Webview
<html> <head> <script type="text/javascript"> function performSearch() { Titanium.App.fireEvent('performSearch', {data : escape(document.getElementById("searchpattern").value) } ); return false; }; Titanium.App.addEventListener('searchResult',function(e) { document.getElementById("result").innerHTML = 'Titanium says: ' + e.message; return false; }); </script> </head> <body> <form> <input id="searchpattern" type="TEXT" value="" /> <button onClick="return performSearch();">Search</button> <div id="result"></div> </form> </body> </html>
3 Answers
I have this problem. How to solve?
Same here. I am getting this error when getting the HTML property of a WebView. I really don't know how to get around this problem.
Your Answer
Think you can help? Login to answer this question!