473,836 Members | 1,372 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

J2ME: Loading an image using Canvas class

1 New Member
Hi...i am trying to load an image that has been saved at the following path: C:\WTK22\apps\M yProject\res After exectuing the program, the NullPointerExce ption is thrown...Kindly let me know how to load the image without any exceptions being thrown...

import javax.microedit ion.midlet.*;
import javax.microedit ion.lcdui.*;

public class ImmutableImageE xample extends MIDlet
private Display display;
private MyCanvas canvas;

public ImmutableImageE xample()
display= Display.getDisp lay(this);
canvas=new MyCanvas(this);
}//end of ImmutableImageE xample

public void startApp()throw s MIDletStateChan geException
display.setCurr ent(canvas);
}//end of startApp

public void pauseApp(){}

public void destroyApp(bool ean abc)throws MIDletStateChan geException {
destroyApp(true );
notifyDestroyed ();

public void exitMIDlet()

}//end of exitMIDlet

}//end of class

class MyCanvas extends Canvas implements CommandListener
private Command exit;
private ImmutableImageE xample immutableImageE xample;
private Image image=null;
private Display display;
public MyCanvas(Immuta bleImageExample iie)
this.immutableI mageExample=imm utableImageExam ple;
exit=new Command("Exit", Command.EXIT,1) ;
addCommand(exit );
setCommandListe ner(this);

image=Image.cre ateImage("/myImage.png");
}//end of try
catch(Exception err)
Alert alert=new Alert("Failure" ,"Can't open the image file",null,null );
alert.setTimeou t(Alert.FOREVER );
display.setCurr ent(alert);
}//end of catch
}//end of constructor MyCanvas
protected void paint(Graphics g)
g.drawImage(ima ge,0,0,Graphics .VCENTER|Graphi cs.HCENTER);

}//end of paint

public void commandAction(C ommand command,Display able display)

if(command==exi t)
immutableImageE xample.exitMIDl et();

}//end of commandAction
}//end of class

Thanx, Namrata
Nov 4 '06 #1
1 15908
1 New Member
Expand|Select|Wrap|Line Numbers
  1. public class ImmutableImageExample extends MIDlet
  2. {
  3. public Display display; //<-- do it public o friendly
  4. ...
Expand|Select|Wrap|Line Numbers
  1.     public MyCanvas(ImmutableImageExample iie)
  2.     {
  3.     this.immutableImageExample=iie; //<-change to this
  4.     this.display = iie.display; //<-add this line
Dec 8 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

by: agatha.life | last post by:
I did a javascript for the loading of images (I didn't want to have the images loaded in "on loading" because they are too many). The website is for a model and if you look at the codeof pages ( for ex. http://www.agathamoon.com/gallery_48_eng.htm ) using explorer or firefox it works, with safari it doesn't! :( The idea is to have the word "loading" appearing while going from an image to another.
by: brianflannery | last post by:
Greetings! My situation is this. I currently have a database of which in a form displays jpeg pictures (one at a time) which are linked to the db and stored in a separate folder. I have set up a report with an image control do display/print 4 pictures on a page. When the report opens (in preview mode) the "loading image" dialog flashes 4 times (once for each picture) which isn't a huge deal, but is annoying. There have been several...
by: Nebulism | last post by:
I have been attempting to utilize a draw command script that loads a canvas, and through certain mouse events, draws rectangles. The original code is from http://www.java2s.com/Code/Python/Event/Usemousetodrawashapeoncanvas.htm . The code itself is: from Tkinter import * trace = 0 class CanvasEventsDemo: def __init__(self, parent=None): canvas = Canvas(width=300, height=300, bg='beige') canvas.pack()
by: atlkhan | last post by:
Hi I am loading bitmapdata from the library like this linkageId = "landscape"; myBitmapData = BitmapData.loadBitmap(linkageId); Than attach this bitmap image to a movie. mc = this.createEmptyMovieClip("mc", 0);
by: wingsganesh | last post by:
Hi Guys, I dont know how to send image in windows mobile 6. i captured image using CameraCaptureDialog class and displayed that image in picture box. but still, i need to send this image in one specific link .... can anybody guide me..... how to send image...............
by: eyalbi007 | last post by:
Hi all, I have a flow of things I need to do, and by now I couldn't find a covenient (or any) way doing it: 1. Loading image from binary file. The image is a 3D image, and I know each slice dimentions. Each pixel in this picture is of type Int16 (2 bytes per pixel). 2. Now, I need to set the 'Image' property of my PictureBox to one of my image slices (let's say the first one). I'll be grateful if someone could explain how to perform...
by: aaronkmar | last post by:
Trying to get a loading image to spin while the query is loading. I can get the data div to fade in, but I can't seem to figure out how to get the gif while the query is loading. I'm using two divs.. id "entrytext" is where the data will load into and has a display:none contentLoading is the loading gif div.
by: Myo Thura Lwin | last post by:
Hello, I am facing one problem with canvas control of Visual Editor on eclipse galileo. I would like to show the image onto canvas in fitted size. But when the image is larger than the canvas, it became out of bound and I could not see the whole image. So, could you suggest me how to fixed the image on canvas control to be able to see the whole image. And then, the scroll bars of the canvas do not work. I am a new...
by: rishi goyal | last post by:
how to add image using in project which is loading image using LoadResPicture in vb6
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.