Bitmap Object - any special way to access it needed?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brendanmcdonagh
    New Member
    • Nov 2007
    • 153

    Bitmap Object - any special way to access it needed?

    Hi all,

    If i have a class - Product, it has 2 fields, String name, and Bitmap productImage. If I try to access the bitmap from another class like Bitmap b = p.productImage; I get null (i have tried many different ways - directly accessing or via a getter method) but if i try to access the string variable of the object it's fine. i know the bitmap has been created. Do i have to convert the bitmap into something else? or is my way of doing it correct?

    Please hlp, i'm going out of my mind with this nullpionterexce ption.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Originally posted by brendanmcdonagh
    Hi all,

    If i have a class - Product, it has 2 fields, String name, and Bitmap productImage. If I try to access the bitmap from another class like Bitmap b = p.productImage; I get null (i have tried many different ways - directly accessing or via a getter method) but if i try to access the string variable of the object it's fine. i know the bitmap has been created. Do i have to convert the bitmap into something else? or is my way of doing it correct?

    Please hlp, i'm going out of my mind with this nullpionterexce ption.
    Seeing the code I may be able to spot an error; nothing jumps out at me from your description.

    Mark.

    Comment

    • brendanmcdonagh
      New Member
      • Nov 2007
      • 153

      #3
      There's a bit of it Marcus, I have been programming a blackberry app talking to a server. It it Java though, let me know if you would be willing to help me out, I qouldn't like to just post 2 1/2 classes without your ask me to. Here' the method that fills my list

      Code:
      public void drawListRow(ListField listField, net.rim.device.api.ui.Graphics g, int index, int y, int width) 
         {
         Product[] data;
      
      	Product p = (Product) get(listField, index);
      
          
              int ypos = y + UPPER_MARGIN;
              int xpos = TEXT_MARGIN;
      		
              String str1 = "line 1";
              
              String str2 = "line 2";
      		
      		Log.info("tdrawrow" + vector.size());
      		
      		//Product p = (Product)vector.elementAt(0);
      		this.productId = p.productId;
      	this.productName = p.productName;
      	this.productPrice = p.productPrice;
      	this.productOffer = p.productOffer;
      	this.productOfferValidity = p.productOfferValidity;
      	
      	if(p.getProductImagePath() != null)
      	{
      	try
      	{
      	try
      	{
      	b = p.productImage;
      	this.productImagePath = p.getProductImagePath();
      	Log.info("This is productimage" + productImagePath);
      	
      	}
      	catch(Exception jjj)
      	{
      	Log.info("Error tttt" + jjj);
      	}
      	
      	
      	int indent = 20;
      	
      	Log.info("b != null");
      	g.drawBitmap(0, y, 16, 16, b, 0, 1);
      	Log.info("drawn");
      	
              g.drawText(productName, indent, y, DrawStyle.ELLIPSIS, width - indent);
      		Log.info("drawn text");
      	}
      	
      	catch(Exception tt)
      	{
      		Log.info("This is productimage error" + tt);
      		 int indent = 0;
              g.drawText(productName, indent, y, DrawStyle.ELLIPSIS, width - indent);
      	}
      }
      	this.productRating = p.productRating;
      	this.productQuantity = p.productQuantity;
      		
      	
      	Log.info("End of method");
      	}
      	
      	public Object get(ListField listField, int index) {
             return vector.elementAt(index);
          }
      
          public int getPreferredWidth(ListField listField) {
              return getWidth();
          }
      
          public int indexOfList(ListField listField, String prefix, int start) {
              return getSelectedIndex();
          }
      
          
      
      
      
      }
      Let me know if you want to see product, product creates the image from a utils class. It works when i just show the image in product class itself.

      p.s. My two variable class was hypothertical, there are string variables for name, price, imagepath, offers, offer validity, etc and then the bitmap variable.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by brendanmcdonagh
        Hi all,

        If i have a class - Product, it has 2 fields, String name, and Bitmap productImage. If I try to access the bitmap from another class like Bitmap b = p.productImage; I get null (i have tried many different ways - directly accessing or via a getter method) but if i try to access the string variable of the object it's fine. i know the bitmap has been created. Do i have to convert the bitmap into something else? or is my way of doing it correct?

        Please hlp, i'm going out of my mind with this nullpionterexce ption.
        There is nothing special about a Bitmap or any other type: if a field of that type is reachable from outside (e.g. it is a 'public' field) it is either null both inside and outside that particular object that holds the field or it isn't. Something else is wrong in your code. System.out.prin tln( ... ) sprinkled in at strategic places is your friend here.

        kind regards,

        Jos

        Comment

        Working...