• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

tictactoe help

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so far i have this,


where are the errors im getting, please help0.0

----jGRASP exec: javac -g tictactoe.java

tictactoe.java:13: <identifier> expected
x = getImage(getCodeBase(),"Black_x.png");
^
tictactoe.java:14: <identifier> expected
o = getImage(getCodeBase(),"o.gif");
^
tictactoe.java:15: <identifier> expected
e = getImage(getCodeBase(),"empty.png");
^
tictactoe.java:16: <identifier> expected
icE=new ImageIcon(e);
^
tictactoe.java:19: <identifier> expected
b1= new JButton(icE);
^
tictactoe.java:20: <identifier> expected
b2= new JButton(icE);
^
tictactoe.java:21: <identifier> expected
b3= new JButton(icE);
^
tictactoe.java:22: <identifier> expected
b4= new JButton(icE);
^
tictactoe.java:23: <identifier> expected
b5= new JButton(icE);
^
tictactoe.java:24: <identifier> expected
b6= new JButton(icE);
^
tictactoe.java:25: <identifier> expected
b7= new JButton(icE);
^
tictactoe.java:26: <identifier> expected
b8= new JButton(icE);
^
tictactoe.java:27: <identifier> expected
b9= new JButton(icE);
^
tictactoe.java:30: <identifier> expected
jlWin= new JLabel(sLetter + " Wins!");
^
tictactoe.java:31: <identifier> expected
jlTie= new JLabel("NO ONE WINS!");
^

please help 0.0 im so confused :-\
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Taking a quick look at this: line 11 is wrong, it should be String instead of string. Remember that Java is case-sensitive!

You cannot put arbitrary statements, which you have in lines 13 - 31, at class level. You can only add variable, constructor and method declarations (optionally with an initialization value for the variable) at class level. Put the statements from lines 13 - 31 in a constructor or method, or combine them with the declaration of the variables just above.
 
Anthony Pena
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you!
 
Anthony Pena
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how do you mean combine them?
 
Anthony Pena
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


got rid of all my errors, but now its not running ? it says it didn initialize
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the Java Console in your system tray, there's probably an exception. Post the full stack trace here.
 
Anthony Pena
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:Check the Java Console in your system tray, there's probably an exception. Post the full stack trace here.


java.lang.NullPointerException
at java.applet.Applet.getCodeBase(Applet.java:152)
at tictactoe.<init>(tictactoe.java:12)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:785)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:714)
at sun.applet.AppletPanel.run(AppletPanel.java:368)
at java.lang.Thread.run(Thread.java:662)
 
Marshal
Posts: 79151
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks as if the problem is on line 12.
You have made things difficult for yourself by trying to write the whole thing in one go. You ought to do it bit by bit.

Try printing the code base URL and the toString method of the Image to screen; then you can narrow down where the error occurs: is it code base or is it the image?

And the length of your actionPerformed method is a good example of why addActionListener(this) is poor, non-object-oriented programming. Even though there are lots of books which show such code.
 
Anthony Pena
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:It looks as if the problem is on line 12.
You have made things difficult for yourself by trying to write the whole thing in one go. You ought to do it bit by bit.

Try printing the code base URL and the toString method of the Image to screen; then you can narrow down where the error occurs: is it code base or is it the image?

And the length of your actionPerformed method is a good example of why addActionListener(this) is poor, non-object-oriented programming. Even though there are lots of books which show such code.



java.lang.NullPointerException

at java.applet.Applet.getCodeBase(Applet.java:152)
at tictactoe.<init>(tictactoe.java:12)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:785)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:714)
at sun.applet.AppletPanel.run(AppletPanel.java:368)
at java.lang.Thread.run(Thread.java:662)
thats the one with the issue i think
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . and have you done anything else with line 12?
 
Anthony Pena
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote: . . . and have you done anything else with line 12?


im not sure what there is to do? i changed the name of the image to something more simple? should i try a different image?
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're trying to run your applet from an IDE, aren't you? Because line 152 of java.awt.Applet says which means that "stub" is null. That field is set by calling setStub on the Applet instance, something that should automatically be done when the applet is called from a browser or the appletviewer application.
 
Ranch Hand
Posts: 96
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tried the code in an Eclipse project. (Had to get some images of my own for this.)


I moved the images to a specific folder in the project and had them loaded from there. This solved the 'not initialized' error. There were some more things to tackle before I could enjoy a game of tic-tac-toe though ;-)

If you want hints:
  • iCount starts at 0; it never changes
  • the 'win label' isn't showing dynamically the winning letter (move the assignment)
  • the actionlistener is working on wrong JButtons in several places


  • If you haven't already, take a look at Oracle's (Sun's) page on creating applets. The tutorial and example there could keep you from falling into some other pitfalls.

    Have fun!
    Wim
     
    Anthony Pena
    Greenhorn
    Posts: 28
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator


    so after alot of work thats what i got, it works, im happy lol
     
    Rob Spoor
    Sheriff
    Posts: 22781
    131
    Eclipse IDE Spring VI Editor Chrome Java Windows
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Well, that of course make sense. You previously initialized the images when the applet was created. At that time it did not have an AppletStub yet. At the time init() is called it does, so getCodeBase() will work at that point.

    So the lesson learned (also for me!): do not call any methods of java.awt.Applet (or javax.swing.JApplet) until init() has been called, as you can't guarantee that they will work before that time.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic