Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (575)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [Solved]AWTException createBufferStratergy  (Read 1149 times)
0 Members and 1 Guest are viewing this topic.
Offline Abhi2011

Senior Newbie





« Posted 2013-05-20 11:58:33 »

Hi guys,

I am a newbie to Java. I thought of making a small game with it. (When I mean small I actually mean it.) I am creating a bufferStrategy with the Window class. I just fixed the illegal state exception and now I have a new problem. When the line is executed it throws the AWTException.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
Window w = new Window(frame);
     
      w.setVisible(true);
      try{
      w.createBufferStrategy(2);
      }catch (Exception e){
         System.out.println(e.getLocalizedMessage());
         System.out.println(e.getMessage());
      }
      bs = w.getBufferStrategy();

And I can't continue. This error occurs only when I debug the application in Eclipse. Other wise a NullPointerException occurs. It is basically due to this.
So could some one help me?

Regards,
Abhi2011
Offline Abhi2011

Senior Newbie





« Reply #1 - Posted 2013-05-20 13:25:04 »

Bump
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #2 - Posted 2013-05-21 02:27:09 »

Please do not bump your own threads.

Can you show us how you initialize Frame? Nothing in this code looks wrong.
Also, it is best to call exc.printStackTrace() instead of those two printlns in your code.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



« Reply #3 - Posted 2013-05-21 02:37:22 »

If you knew what a nullpointerexception was, I think you would have more code included, so - a nullpointerexception is thrown when you try to utilize an object that has a value of 'null', or nothing. Usually when you forget to initialize an object. And, yes, please don't bump your threads, especially after only 2 hours. If you really need to, discreetly post an 'update' post.  Wink
Offline davedes
« Reply #4 - Posted 2013-05-21 02:37:36 »

Why are you using AWT Window?

Why are you using Java2D at all? Why not a more modernized framework like JavaFX, or better yet, something based on OpenGL (hint: LibGDX).

Offline Abhi2011

Senior Newbie





« Reply #5 - Posted 2013-05-21 05:47:54 »

Please do not bump your own threads.

Can you show us how you initialize Frame? Nothing in this code looks wrong.
Also, it is best to call exc.printStackTrace() instead of those two printlns in your code.
Sorry for the bump. I will post the code soon. I did the Println just for testing purposes. The exception is never handled either way.
If you knew what a nullpointerexception was, I think you would have more code included, so - a nullpointerexception is thrown when you try to utilize an object that has a value of 'null', or nothing. Usually when you forget to initialize an object. And, yes, please don't bump your threads, especially after only 2 hours. If you really need to, discreetly post an 'update' post.  Wink
I know what a null value and what the exception means. The reason for the null pointer is due to the graphics object never being initialized because the buffer strategy was never created.
And thanks for the bumping tip. Tongue
Why are you using AWT Window?

Why are you using Java2D at all? Why not a more modernized framework like JavaFX, or better yet, something based on OpenGL (hint: LibGDX).
Well for starters, I need to get used to Java's API before I get into anything deeper. And also this is a very small project. I just want to get used to Java. Maybe later on I'll use JavaFX or LibGDX. But still thanks for the framework examples. I haven't heard of either of them.
Offline Abhi2011

Senior Newbie





« Reply #6 - Posted 2013-05-21 06:59:15 »

Sorry for the double post. Didn't want to make to make the prev post big.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
      
      frame.setSize(new Dimension(575,500));
      frame.setLocationRelativeTo(null);
      frame.setResizable(false);
      frame.setVisible(true);
     
      frame.addWindowListener(new WindowAdapter(){
           
         public void windowClosing(WindowEvent e){
            isRunning = false;
         }
      });
     
      isRunning = true;
      main.start();

Edit: It seems that the problem doesn't occur when only single buffering is being used.
Offline Abhi2011

Senior Newbie





« Reply #7 - Posted 2013-05-22 09:42:40 »

BUMP!!
Please help!
Offline Stranger

Senior Duke


Medals: 7



« Reply #8 - Posted 2013-05-22 11:04:45 »

Maybe this will help.

Anton
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #9 - Posted 2013-05-22 17:29:41 »

I just noticed: you never listed the full exception. Please print the full exception you see when you do exc.printStackTrace().

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Abhi2011

Senior Newbie





« Reply #10 - Posted 2013-05-23 10:17:30 »

I solved this. I just added in a Canvas into my JFrame and the Buffer was created.
Thanks for all your help guys.
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



« Reply #11 - Posted 2013-05-23 15:56:34 »

I though it generally wasn't a good idea to mix awt/swing components?
Offline Abhi2011

Senior Newbie





« Reply #12 - Posted 2013-05-24 05:41:34 »

I though it generally wasn't a good idea to mix awt/swing components?
Tell me a better way to do it.
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



« Reply #13 - Posted 2013-05-24 16:25:13 »

Use a JPanel not a Canvas.
Offline Abhi2011

Senior Newbie





« Reply #14 - Posted 2013-05-24 16:29:11 »

Use a JPanel not a Canvas.
Okay thanks. But are there any performance issues due to this?
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



« Reply #15 - Posted 2013-05-24 16:35:14 »

Not really  -but you may find some functionality problems down the road.
http://www.leepoint.net/JavaBasics/gui/gui-commentary/guicom-25-swingawtswtxul.html
http://www.ibm.com/developerworks/grid/library/os-swingswt/
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (35 views)
2014-10-17 03:59:02

Norakomi (26 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (26 views)
2014-10-15 16:18:58

TehJavaDev (50 views)
2014-10-14 00:39:48

TehJavaDev (51 views)
2014-10-14 00:35:47

TehJavaDev (40 views)
2014-10-14 00:32:37

BurntPizza (63 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (75 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!