ImageView Shows Up in Simulator, But Not on Device.

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

I have an imageView inside of a scrollView that I want to be able to move based on the accelerometer. Below is the relevent code:

var scrollView = Titanium.UI.createScrollView({
    top:125,
    contentWidth:480,
    contentHeight:480,
    zIndex:4,
    height:260,
    width:300
 
});
 
 
var imageView = Titanium.UI.createImageView({
    images:images,
    zIndex:5,
    duration:50, 
    repeatCount:0  
});
 
 
scrollView.add(imageView);
 
Titanium.Accelerometer.addEventListener('update',function(e)
{
   imageView.animate({center:{x:imageView.center.x += (e.x * 10),y: imageView.center.y -= (e.y * 10)},duration:1});     
});
Now, the imageView shows up fine in the Simulator, but when I push the app to the device using Titanium, the imageView doesn't show up.

Anyone have an idea what is going on here, and is this the best way to animate the imageView using the accelerometer?

7 Answers

I don't know if this is relevant but a coworker encountered a similar issue with native Objective-C code. They had a PNG image properly showing up in the simulator but not displayed with the device. The image was there (responding to events) but still invisible.

It appeared to be a problem with the image path (a space or a special character). You may want to check your path if you still have this problem.

— answered 3 years ago by Faustine Le Mee
answer permalink
2 Comments
  • I've seen where simulator loaded an image with a missing "/" in it's path. But the device didn't load it. double check your path.

    — commented 3 years ago by Robert Logan

  • I have also run into this ... and it is case-sensitive on device: - actual filename is test.jpg - "Test.jpg" will work on simulator but not device

    ...just a thought to double-check exact case of filename.

    — commented 3 years ago by S Singer

I've had the same problem, with images showing up when using the simulator, but not on the device. Your problem may be different, but as I've found this question while searching for my problem, I'm posting here, hoping it'll help someone.

My problem was that the images were saved from an XHR request. I was using:

var f = Titanium.Filesystem.getFile('test.jpg');
f.write(this.responseData);
The problem seemed to be the getFile method, the first parameter should be the directory path:
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'test.jpg');

This worked for me!

var thumb = Ti.App.Properties.getString('theImage');
var file = Ti.Filesystem.getFile(thumb);
var image = file.read(image);
var thumbnailView = Titanium.UI.createImageView({
    image:image,
    height:150,
    width:150
});
view.add(thumbnailView);

Had this issue also yesterday. With android run: adb -e logcat

And you should be able to see what the problem is. For me it was Titanium not copying across content & folders to the emulator. In some situations running touch * in the folders on the desktop was enough to get titanium to copy it over. The other issue was more painful - essentially titanium applying some weird rules to paths. This was fixed by using the latest nightly build for Android from http://drop.io/titanium_android_nightly and then using paths ala:

Titanium.UI.createWindow({url:"code/dashboard.js",backgroundImage:'app://images/dashboard.png',navBarHidden:true,fullscreen:true});

I had this same problem and was happy to see that the solution was a simple one in my case. I had placed my files in a folder called 'Images' with an uppercase 'I' in my project folder but had referenced it as 'images' with a lowercase 'i' in my code. As soon as I changed the folder name to 'images' with the lowercase 'i' everything worked fine.

Your Answer

Think you can help? Login to answer this question!