• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

SWT XML Sprite Sheet Utility

 
Ranch Hand
Posts: 64
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22772
130
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22772
130
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22772
130
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's the kind of mistake everybody makes at least once. But you're welcome
 
Good heavens! What have you done! Here, try to fix it with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic