Error with imageuri on sending tweet




I’ve just integrated twitter with my Android app, and the login works fine. However I’ve a problem with sending a tweet.

Code is

Uri myImageUri = Uri.parse("file:///android_asset/twitterimg.jpg");
final Card card = new Card.AppCardBuilder(this)

final TwitterSession session = TwitterCore.getInstance().getSessionManager().getActiveSession();

final Intent intent = new ComposerActivity.Builder(this)

When the tweet is sent it gets the error ‘ /android_asset/twitterimg.jpg (No such file or directory)’ - however the image is shown in the app when they enter their tweet text, so it’s definitely exists on the device in the right place, and I presume specified ok in the intent. Last thing I tried was making sure the image was the right size (with preferred aspect ratio) as described in but no change.

Exception is:

11-02 17:16:05.805: E/TweetUploadService(4237): Post Tweet failed
11-02 17:16:05.805: E/TweetUploadService(4237): /android_asset/twitterimg.jpg (No such file or directory)
11-02 17:16:05.805: E/TweetUploadService(4237): 	at retrofit.RestAdapter$RestHandler.invokeRequest(
11-02 17:16:05.805: E/TweetUploadService(4237): 	at retrofit.RestAdapter$RestHandler.access$100(
11-02 17:16:05.805: E/TweetUploadService(4237): 	at retrofit.RestAdapter$RestHandler$2.obtainResponse(
11-02 17:16:05.805: E/TweetUploadService(4237): 	at
11-02 17:16:05.805: E/TweetUploadService(4237): 	at java.util.concurrent.Executors$
11-02 17:16:05.805: E/TweetUploadService(4237): 	at java.util.concurrent.FutureTask$Sync.innerRun(
11-02 17:16:05.805: E/TweetUploadService(4237): 	at
11-02 17:16:05.805: E/TweetUploadService(4237): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(
11-02 17:16:05.805: E/TweetUploadService(4237): 	at java.util.concurrent.ThreadPoolExecutor$
11-02 17:16:05.805: E/TweetUploadService(4237): 	at


Hey @BlissfulGames,

It seems like the image can’t be found at the time of the posting. Is any code moving it another location? As a test, if you switch to uploading an image from a hard-code url, does that work?



Hi Mike,

Nothing should be happening to the image file - it just sits in the Assets folder.

How do you mean a hard-code URL? When I initially tried it I assumed the file had to be available online and so my original uri was pointing to an http:// file on my website, but when that didn’t work I read the docs a bit more carefully and saw it was supposed to be a local file. It’s a cocos2d-x game and most of the images are in the Assets folder rather than than the Android resources folder (/res/drawable say).



I’ve just seen a stackoverflow post ( that says the file has to be somewhere like the SD card since it needs to be accessible by other apps (the twitter say). Is that right?

It would be awkward as I didn’t want to a) pollute the user’s storage, or b) have additional permissions (I’ll need the android.permission.WRITE_EXTERNAL_STORAGE permission). Really it’s the text they’re tweeting that’s important rather than the image (in fact since it’s a google play link I was hoping the card would be automatically created from the link)


Thanks @BlissfulGames, the hard-coded URL was intended as a test to see if it was working via that way or not.

Are you actually looking to include an image in addition to the text or do you just want a Twitter card created with the tweet?


Just the twitter card I think. The idea is that the user is sharing the game with other people, so they can write whatever they like, but a link to google play is important.

After integrating twitter into the app using Fabric it sent to me to the documentation here: and the 2nd option of twitterkit sounded very simple plus ticked all the boxes. The image isn’t really important, but I think it didn’t compile if I didn’t include the image URI (edit - wasn’t a compile error, it was a runtime exception: IllegalStateException App Card requires a non-null imageUri)