Game working in simulator, but not device.

When I run my app in the simulator, everything goes fine.

But when I run the game on my Neuxs 7, I get a pop-up message that says:

Runtime Error

H:\mygame\main.lua:542: attempt to index global ‘titlebackground’ (a nil value)

Here’s what I have (starting at line 540):

function makebackground() titlebackground=display.newImage("background.png") titlebackground:scale(320,480) titlebackground:toBack() end

my png file is exactly named background.png.

Why is this happening?

Are there more messages in your console log window?

http://docs.coronalabs.com/guide/basics/debugging/index.html

I would connect my Nexus to my computer and debug it, but it can’t do anything other than charge when it’s connected to something.

You need to be able to get it into Developer mode.  Then you can install the “adb” tools and get a console log while its tethered.  You will need to google the steps to get into developer mode.  You have to go into a particular settings screen and tap one entry like 7 times.  You may also have to install a device driver (Windows) too.

Rob

titlebackground:scale(320,480)

What are you trying to scale? What’s the image’s resolution in pixels?

The only reason why you would get that error is if it could not load background.png in the previous line of code.  Are you seeing the background load? 

Is there anything weird about your background image?  Like in CMYK mode?  Really a JPEG named .png?  24/32 bit or 8 bit?  If you’re 100% sure about the file name matching, then that leaves a corrupt image that Android is more sensitive to that the computer’s OS you’re running the simulator on is.

Rob

I had the same error once. All I had was a simple mistake in the code.

Well, I just made a new background image and it worked.

Then we will go with the corrupted image theory and your Nexus is more sensitive to such things.

Glad it’s working!

Rob

Are there more messages in your console log window?

http://docs.coronalabs.com/guide/basics/debugging/index.html

I would connect my Nexus to my computer and debug it, but it can’t do anything other than charge when it’s connected to something.

You need to be able to get it into Developer mode.  Then you can install the “adb” tools and get a console log while its tethered.  You will need to google the steps to get into developer mode.  You have to go into a particular settings screen and tap one entry like 7 times.  You may also have to install a device driver (Windows) too.

Rob

titlebackground:scale(320,480)

What are you trying to scale? What’s the image’s resolution in pixels?

The only reason why you would get that error is if it could not load background.png in the previous line of code.  Are you seeing the background load? 

Is there anything weird about your background image?  Like in CMYK mode?  Really a JPEG named .png?  24/32 bit or 8 bit?  If you’re 100% sure about the file name matching, then that leaves a corrupt image that Android is more sensitive to that the computer’s OS you’re running the simulator on is.

Rob

I had the same error once. All I had was a simple mistake in the code.

Well, I just made a new background image and it worked.

Then we will go with the corrupted image theory and your Nexus is more sensitive to such things.

Glad it’s working!

Rob