java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

Appcelerator JIRA | eric harms | 7 months ago
  1. 0

    Having some issues with Android file upload where the key in my payload is an integer. Sample code to reproduce, taken from Ti API HttpClient file upload docs: {code:java} Titanium.Media.openPhotoGallery({ success: function(event) { var xhr = Titanium.Network.createHTTPClient(); xhr.onload = function(e) { Ti.UI.createAlertDialog({ title: 'Success', message: 'status code ' + this.status }).show(); }; xhr.open('POST', 'REQUESTBI.N URL'); xhr.send({1: event.media}); } }); {code} 1. Create a Requestbi.n url and replace it in the .open() 2. run this on an Android device. You should receive the following error, specifying that the int key cannot be cast to a string, and you will not be able to upload the file to requestbin. [WARN] : W/System.err: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String [WARN] : W/System.err: at ti.modules.titanium.network.TiHTTPClient.send(TiHTTPClient.java:1012) [WARN] : W/System.err: at ti.modules.titanium.network.HTTPClientProxy.send(HTTPClientProxy.java:154) [WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method) [WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:57) [WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Function.call(V8Function.java:43) [WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Function$1.run(V8Function.java:70) [WARN] : W/System.err: at android.os.Handler.handleCallback(Handler.java:739) [WARN] : W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95) [WARN] : W/System.err: at android.os.Looper.loop(Looper.java:145) [WARN] : W/System.err: at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:118) 3. as suggested by AppC support, change the .send() to {code:java} xhr.send(JSON.stringify({1: event.media})); {code} this will fire and upload to requestbin, however if you look at the response in requestbin, the event.media is a json string and not a binary object. 4. change the .send() to {code:java} var payload = {}; var key = '\"' + 1 + '\"'; payload[key] = event.media; xhr.send(payload); {code} this will post the photo and be received as a binary object in requestbin. I have witnessed this for Android only. IOS seems to handle things ok, and I can post the object without having to do any additional processing. I am posting to an API that has been used by our native Android developers, and they are sending the key as an integer. I believe that the Titanium SDK is somehow tripping over the integer to string conversion Please let me know if you need any more info. Thanks Eric

    Appcelerator JIRA | 7 months ago | eric harms
    java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
  2. 0

    Having some issues with Android file upload where the key in my payload is an integer. Sample code to reproduce, taken from Ti API HttpClient file upload docs: {code:java} Titanium.Media.openPhotoGallery({ success: function(event) { var xhr = Titanium.Network.createHTTPClient(); xhr.onload = function(e) { Ti.UI.createAlertDialog({ title: 'Success', message: 'status code ' + this.status }).show(); }; xhr.open('POST', 'REQUESTBI.N URL'); xhr.send({1: event.media}); } }); {code} 1. Create a Requestbi.n url and replace it in the .open() 2. run this on an Android device. You should receive the following error, specifying that the int key cannot be cast to a string, and you will not be able to upload the file to requestbin. [WARN] : W/System.err: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String [WARN] : W/System.err: at ti.modules.titanium.network.TiHTTPClient.send(TiHTTPClient.java:1012) [WARN] : W/System.err: at ti.modules.titanium.network.HTTPClientProxy.send(HTTPClientProxy.java:154) [WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method) [WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:57) [WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Function.call(V8Function.java:43) [WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Function$1.run(V8Function.java:70) [WARN] : W/System.err: at android.os.Handler.handleCallback(Handler.java:739) [WARN] : W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95) [WARN] : W/System.err: at android.os.Looper.loop(Looper.java:145) [WARN] : W/System.err: at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:118) 3. as suggested by AppC support, change the .send() to {code:java} xhr.send(JSON.stringify({1: event.media})); {code} this will fire and upload to requestbin, however if you look at the response in requestbin, the event.media is a json string and not a binary object. 4. change the .send() to {code:java} var payload = {}; var key = '\"' + 1 + '\"'; payload[key] = event.media; xhr.send(payload); {code} this will post the photo and be received as a binary object in requestbin. I have witnessed this for Android only. IOS seems to handle things ok, and I can post the object without having to do any additional processing. I am posting to an API that has been used by our native Android developers, and they are sending the key as an integer. I believe that the Titanium SDK is somehow tripping over the integer to string conversion Please let me know if you need any more info. Thanks Eric

    Appcelerator JIRA | 7 months ago | eric harms
    java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
  3. 0

    Execution Error, return code 2 while executing query in hive for twitter sentiment analysis

    Stack Overflow | 4 weeks ago | Ayushi Jain
    org.apache.hadoop.hive.ql.metadata.HiveException: org.apache.hadoop.hive.ql.metadata.HiveException: org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Bug on Adobe air for Android? - Pushwoosh Community

    pushwoosh.com | 1 week ago
    java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.ClassCastException

      java.lang.Integer cannot be cast to java.lang.String

      at ti.modules.titanium.network.TiHTTPClient.send()
    2. ti.modules.titanium
      HTTPClientProxy.send
      1. ti.modules.titanium.network.TiHTTPClient.send(TiHTTPClient.java:1012)
      2. ti.modules.titanium.network.HTTPClientProxy.send(HTTPClientProxy.java:154)
      2 frames
    3. org.appcelerator.kroll
      V8Function$1.run
      1. org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method)
      2. org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:57)
      3. org.appcelerator.kroll.runtime.v8.V8Function.call(V8Function.java:43)
      4. org.appcelerator.kroll.runtime.v8.V8Function$1.run(V8Function.java:70)
      4 frames
    4. Android Platform
      Looper.loop
      1. android.os.Handler.handleCallback(Handler.java:739)
      2. android.os.Handler.dispatchMessage(Handler.java:95)
      3. android.os.Looper.loop(Looper.java:145)
      3 frames
    5. org.appcelerator.kroll
      KrollRuntime$KrollRuntimeThread.run
      1. org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:118)
      1 frame