I cant get it to work! NullPointerExeption at first awt.Graphics Object

I am writing a game with AWT having it as an applet. I intend NOT to use anything outside of Java 1.1
For my Game i thought that i ATLEAST need the following classes:
MainGame, Level, Unit.
I Started writing Level. wrote a fewe methods for it such as
drawGras(int grastype) And started to write MainGame to see if they would work together. it's is/is going to be my first Java application where i actually know what object orienting is... I have already wrote a game in Java but with out knowing what a class or what object orienting realy is(the game works rather good to) but this time i wanted to use object orienting but came up with problems =( if first posted in "New to Javaprogramming" but they couldn't help me and advice me here
My previous post: http://forum.java.sun.com/thread.jsp?forum=54&thread=290558
Here's my code:
import java.awt.*;
public class MainGame extends java.applet.Applet
     implements Runnable {
     Thread runner;
     Image ImgLevel, ImgUnit;
     public MainGame() {
          Level nr1 = new Level();
          nr1.init();
          nr1.setGround(300);
          nr1.drawGras(1);
          nr1.CalcGraphics();
          nr1.drawSky(1);
          Image ImgLevel = nr1.getLevelImage();
     public void paint(Graphics g) {
          g.drawImage(ImgLevel,0,0,this);
     public void update(Graphics g) {
          paint(g);
     public void init() {
          MainGame Game = new MainGame();
     public void stop() {
          runner = null;
          System.exit(1);
     public void start() {
          if(runner == null) {
               runner = new Thread(this);
               runner.start();
     void Pause(int time) {
         try {
             Thread.sleep(time);
         } catch(InterruptedException e) {
           System.out.println(e.toString());
     public void run() {
          Thread thisThread = Thread.currentThread();
               while(thisThread == runner) {
class Level extends java.applet.Applet {
    Font BigText = new Font("Arial", Font.PLAIN, 36);
    Font Normal = new Font("Arial", Font.PLAIN, 14);
    Font Bold = new Font("Arial", Font.BOLD, 14);
    Graphics GrLevel;
    int pattern, sky, GroundtoWalk, Ground;
    Color BgColor = new Color(166,202,240);
    Color gras1 = new Color(0,255,0);
    Color gras2 = new Color(0,200,0);
    Color gras3 = new Color(0,100,0);
    Image ImgLevel;
    void setBgColor(int r, int g, int b) {
        BgColor = new Color(r,g,b);
    void CalcGraphics() {
        ImgLevel = createImage(800,600);
        GrLevel = ImgLevel.getGraphics();
    void setGround(int GrounD) {
        Ground = GrounD;
    void GroundToWalkADD(int addToGround) {
        GroundtoWalk = Ground + addToGround;
    void setGroundToWalk(int GrToWalk) {
        GroundtoWalk = GrToWalk;
    public void init() {
          System.out.println("Init 1"); // This was placed here when i was checking how far it got when debuging
          CalcGraphics();
          System.out.println("Init 2");
          drawGras(1);
          System.out.println("Init 3");
          repaint();
          System.out.println("Init 4");
    Image getLevelImage() {
        return ImgLevel;
    public void paint(Graphics g) {
          g.drawImage(ImgLevel,0,0,this);
    public void update(Graphics g) {
        paint(g);
    void drawGras(int pt) {
     GrLevel.setColor(BgColor);
     GrLevel.fillRect(0,0,800,600);
     switch(pt) {
          case 1:
               GrLevel.setColor(gras1);
               GrLevel.fillRect(0,GroundtoWalk,800,300);
               GrLevel.setClip(0,GroundtoWalk,800,300);
               for(int i = 0; 890>i;i=i+5) {
                    GrLevel.setColor(gras2);
                    GrLevel.drawLine(0+i,GroundtoWalk,-190+i,GroundtoWalk+300);
               for(int i=950; 0<i; i=i-5) {
                    GrLevel.setColor(gras3);
                    GrLevel.drawLine(890-i,GroundtoWalk,1000-i,GroundtoWalk+300);
          break;
          case 2:
               GrLevel.setColor(gras2);
               GrLevel.fillRect(0,GroundtoWalk+5,800,300);
               for(int i = 0; 890>i;i=i+5) {
                    GrLevel.setColor(gras3);
                    GrLevel.drawLine(0+i,GroundtoWalk,-190+i,GroundtoWalk+300);
               for(int i=950; 0<i; i=i-5) {
                    GrLevel.setColor(gras1);
                    GrLevel.drawLine(890-i,GroundtoWalk,1000-i,GroundtoWalk+300);
          break;
          case 3:
               GrLevel.setColor(gras3);
               GrLevel.fillRect(0,GroundtoWalk+10,800,300);
               for(int i = 0; 800>i; i=i+20) {
                    GrLevel.fillArc(0+i,GroundtoWalk,20,20,180,-180);
          break;
     pattern = pt;
    int getGrasPattern() {
         return pattern;
    void drawSky(int cl) {
            GrLevel.setColor(BgColor);
            GrLevel.fillRect(0,0,800,155);
            switch(cl) {
                case 1:
               for(int y = 0;y<7;y++) {
               for(int x = 0;x<800;x=x+20) {
                            GrLevel.setColor(Color.white);
                            GrLevel.drawArc(x,y*20,20,20,180,180);
                            GrLevel.setColor(Color.red);
                            GrLevel.drawArc(x,y*20+4,20,20,180,180);
                            GrLevel.setColor(Color.yellow);
                            GrLevel.drawArc(x,y*20+2,20,20,180,180);
                            GrLevel.setColor(Color.green);
                            GrLevel.drawArc(x,y*20+8,20,20,180,180);
                            GrLevel.setColor(Color.blue);
                            GrLevel.drawArc(x,y*20+12,20,20,180,180);
                            GrLevel.setColor(Color.pink);
                            GrLevel.drawArc(x,y*20+16,20,20,180,180);
          break;
          case 2:
                    GrLevel.setColor(Color.gray);
          break;
     sky = cl;
     GrLevel.setFont(BigText);
     GrLevel.setColor(Color.black);
     GrLevel.fillRect(0,0,800,50);
     GrLevel.setColor(Color.white);
     GrLevel.drawString("Score Tabel - comming someday",((size().width)/2)-260, 40);
    int getSkyTyp() {
         return sky;
}I tested running the code of class Level by puting it into Level.java and compiled it...ran it with appletviewer and it worked as it was intended to.
But when i compiled it with MainGame... and in the HTML started MainGame.class,.....applet didn't intializeand i got the following error messege:
Init 1
java.lang.NullPointerException
        at Level.CalcGraphics(MainGame.java:84)
        at MainGame.<init>(MainGame.java:11)Line 82: void CalcGraphics() {
Line 83: ImgLevel = createImage(800,600);
Line 84: GrLevel = ImgLevel.getGraphics(); // The First awt.Graphics object
Line 85: }
Line 9:      public MainGame() {
Line 10:     Level nr1 = new Level();
Line 11:     nr1.CalcGraphics(); // calling the method above -> same error first awt.Graphics Object.
If i change it os that "drawGras" comes first it's first awt.Graphics Line will show the same error
Hope some one can and will help me

As per the documentation of
java.awt.Component.createImage(int,int):
Creates an off-screen drawable image to be used for
double buffering.
Parameters:
width - the specified width
height - the specified height
Returns:
an off-screen drawable image, which can be used for
double buffering. The return value may be null if the
component is not displayable. This will always happen
if GraphicsEnvironment.isHeadless() returns true.
Since:
JDK1.0 its not
ImgLevel = createImage(800,600); that's making the problem but The first awt.Graphics Object in class Level, no mather which on it is =((
>
The key part is '...may be null if the component is
not displayable.'
You should put your graphics initialization code in
start(), which will be called when your applet is
ready to go. Before then, your applet is not
displayable. (Also, remember to dispose() your
graphics in your stop() method, if not sooner.)for the part writen above...I'll try to change it like you are saying.
Thanx for your help!

Similar Messages

  • I cant get itunes to work on my new Sony Vaio. Im running Windows 8.1.

    i cant get itunes to work on my new Sony Vaio. Im running Windows 8.1. Anyone have a fix?

    Hello philtapevans,
    The following article provides information and steps that can help get iTunes installed on your computer.
    Issues installing iTunes or QuickTime for Windows
    http://support.apple.com/kb/HT1926
    Cheers,
    Allen

  • Set up ipod touch to cox email, ive tried everything and cant get it to work. thanks!

    set up ipod touch to cox email, ive tried everything and cant get it to work. thanks!

    Here's an answer from the net:
    Go to Settings/Mail,contacts,calendars/Add account choose other, choose Add Mail Account. Fill in name, email address, password and description on the screen that comes up. Save those.
    One the next screen tat comes up click om POP in the first line then fil in the host name as
    spop.west.cox.net or spop.east.cox.net or the one to go with your region.
    Note that is not a misprint, that is spop (secure pop)
    Fill in your username one more time (the password should have carried over from previously)
    Fill in your outgoing mail server like smtp.west.cox.net (change for your region) and click Save.
    When all the settings are verified a checkmark will appear next to them all and you are good to go.
    If it says something like "can't connect via SSL would you like to ..." then you probably missed the step about selecting POP on the second screen and are trying IMAP so go back and try over with POP. Or perhaps mistyped soemthing.
    Once everything is working you can go back into the settings and see that it has automatically connected on port 995 and that SSL is on
    Note that you probably won't be able to send email from a wifi in a cafe or similar as cox won't let you connect to their smtp from outside their network.
    I haven't tried receiving mail from a non cox connected wifi yet but I suspect it will work just fine. Anyway these settings work for me using my ipod to my home wifi router connected to cox.
    I could not find a definitive guide when I searched so I hope this helps other folks trying to configure this.
    I got the spop from "Mail for Mac OS X 10.5 configure SSL / POP" here:
    http://support.cox.com/sdccommon/asp...c-7f95e8bcaf39

  • Apple Please sort out the V 11.1.4 problems as I cant get iTunes to work now. You need to have a new version asap

    Please sort out the V 11.1.4 problems as I cant get iTunes to work now. You need to have a new version asap

    Go to Control Panel > Add or Remove Programs (Win XP) or Programs and Features (later)
    Remove all of these items in the following order:
    iTunes
    Apple Software Update
    Apple Mobile Device Support (if this won't uninstall move on to the next item)
    Bonjour
    Apple Application Support
    Reboot, download iTunes, then reinstall, either using an account with administrative rights, or right-clicking the downloaded installer and selecting Run as Administrator.
    The uninstall and reinstall process will preserve your iTunes library and settings, but ideally you would back up the library and your other important personal documents and data on a regular basis. See this user tip for a suggested technique.
    Please note:
    Some users may need to follow all the steps in whichever of the following support documents applies to their system. These include some additional manual file and folder deletions not mentioned above.
    HT1925: Removing and Reinstalling iTunes for Windows XP
    HT1923: Removing and reinstalling iTunes for Windows Vista, Windows 7, or Windows 8
    tt2

  • I cant get ECWID to work on my mobile devices, it only seems to use the desktop site rather that the Tablet or iPhone

    I cant get ECWID to work on my mobile devices, it only seems to use the desktop site rather that the Tablet or iPhone? Can anyone help me?

    Hi Jim,
    We’ll be glad to help you.
    Ecwid supports responsive layout, which means that the store pages can adapt to the visitor's screen width on the fly and keep the layout clean and nice. Your products and categories lists will be fit for any window's size, as Ecwid will calculate the most suitable number of products or categories in row automatically. In other words, Ecwid looks great on any mobile devices. You can check how your Ecwid store may look on smartphones and tablets, if you see your Starter Site (what it is).
    However, if you want Ecwid reveals itself in all its glory, you should embed your Ecwid store into website, which also support responsive layout, because if the site doesn’t adapt to size screen, Ecwid is not able to determine how it should be changed since it’s just a part of the site.
    We’ve checked your site and found that you used Adobe Muse for building your site. Using Adobe Muse, you can create alternate site layouts for web content to be displayed on desktop, smartphones, and tablets. Nonetheless, your site has a layout for desktops only, that’s why it looks the same on all devices. You can learn how to create those alternate layouts in Adobe Muse, by reading “Creating a Website for Mobile Devices” article.
    I hope this helps! But if there are any questions, don’t hesitate to reach us out on Ecwid forums.

  • Cant get Frontrow to work after installing 10.4.3 and updating it

    I made a terrible mistake today and moved all my files from my harddisk to my external harddisk. I had to reinstall everything but I cant get frontrow to work properly. I cant find it on my external harddisk either.
    Can someone please help me with this tricky question.

    Winbo:
    Can you describe your problem in a bit more detail? Why did you decide to move your files? What files did you move? What method did you use to move them? Did you move them over completely by way of backing up and then erased your disk prior to moving them back?
    Any other information you can provide will make it easier to make suggestions on your issue.
    Good luck.
    cornelius
    PismoG4 550, 100GB 5400 Toshiba internal, 1 GB RAM; Pismo 500 OS X (10.4.5)   Mac OS X (10.4.5)   Beige G3 OS 8.6

  • Cant get facetime to work on mini ipad

    Cant get FaceTime to work on new mini IPad....any suggestions? It keeps verifying but it will not work, it allows me to get apps. Triple checked that the Apple ID and password is correct, checked the settings to make sure they are turned on, able to get imessage, not sure what the problem could be?

    Using FaceTime http://support.apple.com/kb/ht4319
    Troubleshooting FaceTime http://support.apple.com/kb/TS3367
    The Complete Guide to FaceTime + iMessage: Setup, Use, and Troubleshooting
    http://tinyurl.com/a7odey8
    Troubleshooting FaceTime and iMessage activation
    http://support.apple.com/kb/TS4268
    iOS: FaceTime is 'Unable to verify email because it is in use'
    http://support.apple.com/kb/TS3510
    Using FaceTime and iMessage behind a firewall
    http://support.apple.com/kb/HT4245
    iOS: About Messages
    http://support.apple.com/kb/HT3529
    Set up iMessage
    http://www.apple.com/ca/ios/messages/
    iOS 6 and OS X Mountain Lion: Link your phone number and Apple ID for use with FaceTime and iMessage
    http://support.apple.com/kb/HT5538
    How to Set Up & Use iMessage on iPhone, iPad, & iPod touch with iOS
    http://osxdaily.com/2011/10/18/set-up-imessage-on-iphone-ipad-ipod-touch-with-io s-5/
    Extra FaceTime IDs
    http://tinyurl.com/k683gr4
    Troubleshooting Messages
    http://support.apple.com/kb/TS2755
    Troubleshooting iMessage Issues: Some Useful Tips You Should Try
    http://www.igeeksblog.com/troubleshooting-imessage-issues/
    Setting Up Multiple iOS Devices for iMessage and Facetime
    http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l
    FaceTime and iMessage not accepting Apple ID password
    http://www.ilounge.com/index.php/articles/comments/facetime-and-imessage-not-acc epting-apple-id-password/
    Fix Can’t Sign Into FaceTime or iMessage iOS 7
    http://ipadtutr.com/fix-login-facetime-imessage-ios-7/
    FaceTime, Game Center, Messages: Troubleshooting sign in issues
    http://support.apple.com/kb/TS3970
    Unable to use FaceTime and iMessage with my apple ID
    https://discussions.apple.com/thread/4649373?tstart=90
    How to Block Someone on FaceTime
    http://www.ehow.com/how_10033185_block-someone-facetime.html
    My Facetime Doesn't Ring
    https://discussions.apple.com/message/19087457
    Send an iMessage as a Text Message Instead with a Quick Tap & Hold
    http://osxdaily.com/2012/11/18/send-imessage-as-text-message/
    To send messages to non-Apple devices, check out the TextFree app https://itunes.apple.com/us/app/text-free-textfree-sms-real/id399355755?mt=8
    How to Send SMS from iPad
    http://www.iskysoft.com/apple-ipad/send-sms-from-ipad.html
    You can check the status of the FaceTime/iMessage servers at this link.
    http://www.apple.com/support/systemstatus/
     Cheers, Tom

  • Cant get bluetooth to work on iphone 5 wont even discover divices

    Cant get bluetooth to work on iphone 5 wont even discover divices

    supported bluetooth profiles http://support.apple.com/kb/ht3647
    what are you trying to connect your device to?

  • Cant get wifi to work on ipod

    cant get wifi to work on ipod

    would help if you added more then that
    as in what set up is on your router, what have you tried etc

  • Cant get query to work

    can anyone see what i'm trying to do here?:::
    <cfquery name="display_log"
    datasource="allied_control_db1">
    SELECT *
    FROM ops_log_entry
    ORDER BY log_entry_date_time DESC
    </cfquery>
    <cfquery name="get_current_status"
    datasource="allied_control_db1">
    SELECT *
    FROM new_log_entries
    WHERE #display_log.ID# =
    #get_current_status.id_original_entry#
    </cfquery>
    i want to pull the 'current status' of an entry from another
    table where the ID of 'ops_log_entry' matches that of
    'new_log_entries'
    everything work except this line:
    WHERE #display_log.ID# =
    #get_current_status.id_original_entry#
    i dont think i'm far off but just cant get it to work.
    anyone?

    Hi Phil,
    i'm always carefull not to use reserved words as i spent
    nearly 24 hrs pulling my hair out before trying to figure out why a
    query wasnt working, so i'm pretty sure its not that.
    i havent added anything to the query apart from the date/time
    column name.
    <cfquery name="display_log"
    datasource="allied_control_db1">
    SELECT *
    FROM ops_log_entry AS L INNER JOIN new_log_entries AS N
    ON ( L.ID = N.id_original_entry )
    WHERE N.log_entry_date_time = (SELECT
    MAX(N1.log_entry_date_time)
    FROM new_log_entries AS N1
    WHERE N1.id_original_entry = N.id_original_entry)
    </cfquery>
    ive checked the DB column types and the ops_log_entry.ID is
    of course an AutoNumber (long integr) & the
    new_log_entries.id_original_entry is a Number (long integr)
    so seen as they are both the same types, should there be any
    need for single quotes?

  • [solved]passenger + nginx + rvm cant get nginx to work

    Hello ,
    I am trying to install   passenger-install-nginx-module from the wiki of ruby on rails. I removed my existing nginx but
    but now I cant get nginx to work from the /opt/nginx location. I am getting
    ruby-2.0.0-p481 [ytsejam@ytsejam ~]$ nginx -v
    bash: nginx: command not found
    If I try with "pacman Ql nginx "
    ruby-2.0.0-p481 [ytsejam@ytsejam ~]$ pacman -Ql nginx
    error: package 'nginx' was not found
    but I can enter the directory of /opt/nginx by using cd command.
    can anyone help me ?
    Last edited by ytsejam (2014-08-26 08:25:52)

    I'm happy to see that nginx-passenger had what you were looking for. If you encounter any problems, please don't hesitate to leave an AUR comment or submit a pull request!

  • I installed Aperture from the App Store, it was working ok, then suf=ddenly it wont load, I get the "Aperture encountered problem" message, have updated all OSX and Aperture but I still cant get it to work, any ideas ?

    I installed Aperture from the App Store, it was working ok, then suf=ddenly it wont load, I get the "Aperture encountered problem" message, have updated all OSX and Aperture but I still cant get it to work, any ideas ?

    I installed Aperture from the App Store, it was working ok, then suf=ddenly it wont load, I get the "Aperture encountered problem" message, have updated all OSX and Aperture but I still cant get it to work, any ideas ?

  • Strange problem. I have upgraded to OSX 10.9.1 but cant get wifi to work so forced to be hard wired. Any inputs appreciated.

    Hi All,
    Strange problem. I have upgraded to OSX 10.9.1 but cant get wifi to work so forced to be hard wired. Any inputs appreciated. Problem is I cant even reinstall it as I saw on a thread reason, it needs wifi to begin.

    It only needs an internet connection - wired or wireless.
    Fixing a Mavericks Installation Problem
    How to manage a failed OS X Mavericks installation | MacFixIt - CNET Reviews.
    Try these in order:
    1. a. Resetting your Mac's PRAM and NVRAM
        b. Intel-based Macs: Resetting the System Management Controller (SMC)
    2. Restart the computer in Safe Mode, then restart again, normally. If this doesn't help, then:
         Boot to the Recovery HD: Restart the computer and after the chime press and hold down the
         COMMAND and R keys until the Utilities menu screen appears. Alternatively, restart the computer and
         after the chime press and hold down the OPTION key until the boot manager screen appears.
         Select the Recovery HD and click on the downward pointing arrow button.
    3. Repair the Hard Drive and Permissions: Upon startup select Disk Utility from the Utilities menu. Repair the Hard Drive and Permissions as follows.
    When the recovery menu appears select Disk Utility. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the main menu. Select Restart from the Apple menu.
    4. Reinstall Lion/Mountain Lion, Mavericks: Reboot from the Recovery HD. Select Reinstall Lion/Mountain Lion, Mavericks from the Utilities menu, and click on the Continue button.
    Note: You will need an active Internet connection. I suggest using Ethernet if possible because it is three times faster than wireless.

  • Cant get tv out working

    im trying to get tv out working on my ati x300.
    i connected it to my main display and noticed the framebuffer kicked in during boot. it changed the console res to 1680x1050. i cant see anything on my crappy little crt tv.
    looking through the wiki it says to run xrandr but i believe i would need to be connected through svideo for that to work.
    if im using vesa i can see whats going on and log in without any problems. i cant run xbmc though.
    if i use the radeo driver i get nothing. and again, it looks like the res is being set too high even though i defined 800x600 in xorg.conf.
    removing xorg.conf i still get nothing.
    you guys have any ideas?

    Wow, I'm glad I found this topic, I was beginning to think it was just me. Just like you guys, I have tried everything, and have received the same results. I really hope we can get an answer to this soon, because I need to run Sax 'N Dottys Karaoke presenter, (via Windows Vista/BootCamp) next week!! Without a video out, Im screwed. (Unless anyone knows of a comparable MAC Karaoke presenter that will read MP3G's)
    Message was edited by: petevspete

  • DVP FX970 Cant Get it to Work

    I purchased a sony dvp fx970 and I cant' get it to play the usb flashdrive neither a dvd, please help how to get started doing this.  The screen comes on and momentarily flashes the word dvd player and thats about it

    USB devices which can connect to the player are flash memory and digital still camera. Other devices (USB hub, etc.) cannot be connected. When an unsupported device is connected, an error message appears.
    Please try the following steps: 
    Re-connect the USB device securely 
    Press INPUT SELECT repeatedly to select “USB” 
    Try another USB flash drive, preferably another brand
    Check if the same flash drive works with a computer. If yes, then the said flash drive may not be compatible with the player
    Click here if you're unable to playback MP4 files from a USB device.
    Click here to troubleshoot the DVD playback issue. 
    If my post answers your question, please mark it as "Accept as Solution"
    http://bit.ly/LapMagWin

Maybe you are looking for

  • Unable to open raw files in lightroom from my nikon d5300

    I have recently bought a nikon d5300 camera and cannot open any raw files using elements 12 or lightroom 5.3 which are both recommended for the new camera and its raw formats?

  • Haven't been able to use Safari Browser for months, it keeps crashing seconds after I launch it

    I haven't been able to use my Safari Browser for months. Each time I launch it, it crashes.

  • Dynamic Memory

    Hello, I was reading up the field symbols(FS) and data references(DR) in the ABAP help documents and i have a doubt. When you can use data references to allocate memory dynamically how can or rather what happens to this memory when you have done both

  • How to download the e-learning video

    Hi all, Does anyone know how to download the e-learning video in SAP Business One ? Because some of the links don't have the link for download and i must click it to watch the video. It will help me to watch it in offline connection. Thanks in advanc

  • Converting PR into Schedule lines in mass

    All SAP Gurus, We have scheduling agreements for several materials. Now in day to day working, various user departments rais the PR for these items. Then we enter the schedule for these items into the scheduling agreement (with reference to PR). But