Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SWT XML Sprite Sheet Utility

 
Lance Colton
Ranch Hand
Posts: 64
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to create a class, which will take a path to an Image, and an XML file which defines sub-images within the image, and return each sub image as SWT Image objects.

It basically should work like this



with the XML Sprite sheet looking like this



I think the problem is SWT doesn't like for the display object to be passed to an outside class, is there any way to resolve this?

The stack trace:


The is the result of me trying to draw a returned image to a Canvas in a Shell with the same Display.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that sprites.containsKey("play.png") returns true? In other words, that sprites.get("play.png") does not return null?
You are calling sprites.get("name") - using the String literal "name" instead of the parameter name. As a results, the returned Image probably is null.
 
Lance Colton
Ranch Hand
Posts: 64
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Are you sure that sprites.containsKey("play.png") returns true? In other words, that sprites.get("play.png") does not return null?
You are calling sprites.get("name") - using the String literal "name" instead of the parameter name. As a results, the returned Image probably is null.


Yes, each name in the <String, Image> HashMap is there, however the Image objects are all null. something is wrong with the image construction through GC, and I think it might have something to do with the Display object that had to be passed.

let me post the entire source code,



Here is the XML:
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you're not calling sprites.get("play.png"), you're calling sprites.get("name").
 
Lance Colton
Ranch Hand
Posts: 64
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:But you're not calling sprites.get("play.png"), you're calling sprites.get("name").


There are no words, to express, how retarded I feel for that XD

Thank you so much, it works perfectly now.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the kind of mistake everybody makes at least once. But you're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic