Cannot create class in system package: help!

I am working on a j2me application, and I can compile, preverify and jar everything fine.  However the emulator gives this error message:

Cannot create class in system package

I think this is a general java question rather than a midlet-related one, and I really hope one of you guys can help ... Java isn't really my area of expertes!  Here's the code:

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import javax.microedition.midlet.*;
import java.io.*;

public class hello extends MIDlet implements CommandListener
{
      Command exitCommand = new Command("exit", Command.EXIT, 1);
      ScreenPic screenPic;

      public hello()
      {
            screenPic = new ScreenPic();
            screenPic.addCommand(exitCommand);
            screenPic.setCommandListener(this);
    }

      protected void startApp()
      {
            System.out.println("starting application");
      }

      protected void pauseApp()
      {
      }

      protected void destroyApp(boolean b)
      {
      }

      public void commandAction(Command c, Displayable d)
      {
            if(c == exitCommand) notifyDestroyed();
      }

}

public class ScreenPic extends GameCanvas
{
      Image image;
      Byte imageData;

       public ScreenPic()
      {
            super(true);
            byte[] imageData = new byte[(int)5120*5120];
            image.createImage(imageData, 0, imageData.length);
      }

}
LVL 5
LornaJaneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Not my area of expertise either ;-) But if that code's in the same file, the ScreenPic class shouldn't be marked public. FYI, the cast at

byte[] imageData = new byte[(int)5120*5120];

is redundant.
TimYatesCommented:
What package are your two classes in?

You cannot put them in a package starting with java or javax
TimYatesCommented:
Part of the J2ME "Security" model ;-)  is that you cannot put classes into the base j2me package structure...  it is to prevent overwriting the base classes with your own malicious ones I guess (as a lot of the data is protected or private in those classes)...
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

CEHJCommented:
I would have said the same had i seen a package declaration at the top of the code ;-)
TimYatesCommented:
I guessed cos there were 2 public classes, it was an incomplete cut and paste ;-)
CEHJCommented:
You could be right ;-)
bsmohanCommented:
R u trying to create a class in some java.*.* package??
LornaJaneAuthor Commented:
I'm not trying to put them in a package at all, there's only the one file so it didn't seem worth it and it's been pretty fine.  You're right about the public class declaration.  However the file is in fact complete and here it is in its entirety.  I don't understand the error because I'm not trying to create any class other than the two shown below but it seems to be the line:

 image.createImage(imageData, 0, imageData.length);

that is causing the problem.  Code follows:

----

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import javax.microedition.midlet.*;
import java.io.*;

public class hello extends MIDlet implements CommandListener
{
    Command exitCommand = new Command("exit", Command.EXIT, 1);
    ScreenPic screenPic;

    public hello()
    {
         screenPic = new ScreenPic();
         screenPic.addCommand(exitCommand);
         screenPic.setCommandListener(this);
   }

    protected void startApp()
    {
         System.out.println("starting application");
    }

    protected void pauseApp()
    {
    }

    protected void destroyApp(boolean b)
    {
    }

    public void commandAction(Command c, Displayable d)
    {
         if(c == exitCommand) notifyDestroyed();
    }

}

class ScreenPic extends GameCanvas
{
    Image image;
    Byte imageData;

     public ScreenPic()
    {
         super(true);
         byte[] imageData = new byte[(int)5120*5120];
         image.createImage(imageData, 0, imageData.length);
    }

}

Just want to also say thanks to everyone trying to help me on this!
CEHJCommented:
What happens when that line is commented out?
What is the fully-qualified name of Image?
Mick BarryJava DeveloperCommented:
> I'm not trying to put them in a package at all, there's only the one file so it didn't seem worth it

I'd suggest always putting classes in a package.
Mick BarryJava DeveloperCommented:
Try getting rid of this line:

> System.out.println("starting application");
LornaJaneAuthor Commented:
OK, this is how I figured out why I was getting this error message.  I'm going to get this question closed now, but for reference and in case it helps someone else, this is what happened.

The image I was getting appeared because I was attempting to extend GameCanvas.  GameCanvas is only in MIDP 2 not in MIDP 1.  The emulator I was using (Nokia's Developer Suite) only uses MIDP1, as do most nokia phones at the time of writing (summer 2003).

Thanks again to everyone that tried to help with this unusual problem

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.