Search code examples
javascriptimagetitanium

Image View - invalid image type?


I'm attempting to work on code for school, and I'm attempting to make an application which shows five different images of different video games. Clicking on any of the pictures should lead to a detailed explanation of the video game, and lead to buttons from there. However, I'm having a bit of trouble even having the images show up in my views. Just earlier today, I reskinned an old app I made for a previous class, added in the new pictures into a different named folder, changed information in the app to make that fix accordingly, and tested. The first thing that popped up was invalid image type, referencing the open window function I had very early in the code. I have a for loop that I'm using to roll through all the different images. If I attempt to use url or backgroundImage, it shows black views, but no images in them. This is the loop I'm using:

for(var i=0; i<imageFiles.length; i++){
var view = Ti.UI.createView({
    backgroundColor: "#000",
    top: margin*2,
    left: margin,
    width: size*1.55,
    height: size*1.55
});
var newPicture = Ti.UI.createImageView({
    title: imageList[0].title,
    image: "images/" + imageFiles[i],
    top: 0,
    width: view.width

});
console.log(imageFiles[i]);
view.add(newPicture);
viewContainer.add(view);

};

The margin and size are variables we made as placeholders for spacing, so I used some math to organize everything on the page properly. The images are all .jpg. Is there any ideas as to why I would be receiving the invalid image type error on this, and not when I had the same file extension on my images on the previous application? I appreciate your time.


Solution

  • Just wondering is it because the image path is incorrect.

    Is your 'images' folder placed right under "resources" folder?

    If so, try setting your image path like this:

    var newPicture = Ti.UI.createImageView({
        title: imageList[0].title,
        image: Ti.Filesystem.resourcesDirectory+ "/images/" + imageFiles[i],
        top: 0,
        width: view.width
    });
    

    Or test it out by using function: Ti.Filesystem.File.exists()