HttpClient.send() crashing on Android

You must Login before you can answer or comment on any questions.

I am trying to send a GET request to a rest web service using HttpClient. On iOs everything works fine, but when I run it in Android Emulator, it is crashing with an exception. SDK: Titanium 2.0.2 (2012/05/30 10:21 2ff31a3) Platform: Android 2.2 Device: Android Emulator 2.2 OS: Mac OSX 10.7

Here is the code I am using:

var xhr = Titanium.Network.createHTTPClient(
    {
        timeout : 5000,
    } );
 
    xhr.onload = function( )
    {
        Ti.API.info( "Data received" );
        _cb( JSON.parse( this.responseText ) );
    };
 
    xhr.onerror = function( )
    {
        Ti.API.info( 'Error' );
    }
    // http://10.10.8.61:8330/m2m/rest/accounts/100-2112-00000/vehicles?limit=50&vehicleCriteria.alias=vehicle&token=e8d8baae-7630-4baf-b15d-7e1257483049
    var lUrl = wsUrl + "/accounts/" + Ti.App.Properties.getString( 'current_account_number' ) + "/vehicles?limit=50&vehicleCriteria.alias=vehicle&token=" + Ti.App.Properties.getString( 'current_token' );
 
    Ti.API.info( "The URL: " + lUrl );
 
    xhr.open( "GET", lUrl );
 
    xhr.send( );
Just after the send(), it crash. The onload callback is never reached. Here is the stacktrace I get:
[WARN][dalvikvm(  320)] threadid=1: thread exiting with uncaught exception (group=0x4001d800)
[ERROR][TiApplication(  320)] (main) [70,371573] Sending event: exception on thread: main msg:java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.; Titanium 2.0.2,2012/05/30 10:21,2ff31a3
[ERROR][TiApplication(  320)] java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
[ERROR][TiApplication(  320)]   at android.view.ViewGroup.addViewInner(ViewGroup.java:1970)
[ERROR][TiApplication(  320)]   at android.view.ViewGroup.addView(ViewGroup.java:1865)
[ERROR][TiApplication(  320)]   at android.view.ViewGroup.addView(ViewGroup.java:1845)
[ERROR][TiApplication(  320)]   at ti.modules.titanium.ui.widget.TiUITableView.processProperties(TiUITableView.java:131)
[ERROR][TiApplication(  320)]   at org.appcelerator.kroll.KrollProxy.setModelListener(KrollProxy.java:737)
[ERROR][TiApplication(  320)]   at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:533)
[ERROR][TiApplication(  320)]   at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:525)
[ERROR][TiApplication(  320)]   at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:503)
[ERROR][TiApplication(  320)]   at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:540)
[ERROR][TiApplication(  320)]   at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:525)
[ERROR][TiApplication(  320)]   at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:503)
[ERROR][TiApplication(  320)]   at org.appcelerator.titanium.proxy.TiViewProxy.handleAdd(TiViewProxy.java:619)
[ERROR][TiApplication(  320)]   at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:310)
[ERROR][TiApplication(  320)]   at android.os.Handler.dispatchMessage(Handler.java:95)
[ERROR][TiApplication(  320)]   at android.os.Looper.loop(Looper.java:123)
[ERROR][TiApplication(  320)]   at android.app.ActivityThread.main(ActivityThread.java:4627)
[ERROR][TiApplication(  320)]   at java.lang.reflect.Method.invokeNative(Native Method)
[ERROR][TiApplication(  320)]   at java.lang.reflect.Method.invoke(Method.java:521)
[ERROR][TiApplication(  320)]   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
[ERROR][TiApplication(  320)]   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
[ERROR][TiApplication(  320)]   at dalvik.system.NativeStart.main(Native Method)
[ERROR][AndroidRuntime(  320)] FATAL EXCEPTION: main
[ERROR][AndroidRuntime(  320)] java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
[ERROR][AndroidRuntime(  320)]  at android.view.ViewGroup.addViewInner(ViewGroup.java:1970)
[ERROR][AndroidRuntime(  320)]  at android.view.ViewGroup.addView(ViewGroup.java:1865)
[ERROR][AndroidRuntime(  320)]  at android.view.ViewGroup.addView(ViewGroup.java:1845)
[ERROR][AndroidRuntime(  320)]  at ti.modules.titanium.ui.widget.TiUITableView.processProperties(TiUITableView.java:131)
[ERROR][AndroidRuntime(  320)]  at org.appcelerator.kroll.KrollProxy.setModelListener(KrollProxy.java:737)
[ERROR][AndroidRuntime(  320)]  at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:533)
[ERROR][AndroidRuntime(  320)]  at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:525)
[ERROR][AndroidRuntime(  320)]  at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:503)
[ERROR][AndroidRuntime(  320)]  at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:540)
[ERROR][AndroidRuntime(  320)]  at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:525)
[ERROR][AndroidRuntime(  320)]  at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:503)
[ERROR][AndroidRuntime(  320)]  at org.appcelerator.titanium.proxy.TiViewProxy.handleAdd(TiViewProxy.java:619)
[ERROR][AndroidRuntime(  320)]  at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:310)
[ERROR][AndroidRuntime(  320)]  at android.os.Handler.dispatchMessage(Handler.java:95)
[ERROR][AndroidRuntime(  320)]  at android.os.Looper.loop(Looper.java:123)
[ERROR][AndroidRuntime(  320)]  at android.app.ActivityThread.main(ActivityThread.java:4627)
[ERROR][AndroidRuntime(  320)]  at java.lang.reflect.Method.invokeNative(Native Method)
[ERROR][AndroidRuntime(  320)]  at java.lang.reflect.Method.invoke(Method.java:521)
[ERROR][AndroidRuntime(  320)]  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
[ERROR][AndroidRuntime(  320)]  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
[ERROR][AndroidRuntime(  320)]  at dalvik.system.NativeStart.main(Native Method)
Any ideas on what can cause the problem? Like I said, on iOs, it is working perfectly, my list is returned from the web service.

— asked 12 months ago by Thierry Lévèque
3 Comments
  • I need to add that at this point in the code, a POST have already been use successfully. On Android too!

    — commented 12 months ago by Thierry Lévèque

  • Hi,

    Were you ever able to solve your problem? I'm having the same issue as well, using Android OS 2.3 and 4.1.

    — commented 8 months ago by Vinh Bui

  • We need to see what _cb does, and see a console log to tell how far exactly the code got before the crash occurred.

    — commented 8 months ago by Shawn Lipscomb

Your Answer

Think you can help? Login to answer this question!