Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  ignore  |  Print  
  Exception in thread "main" java.lang.NullPointerException  (Read 6937 times)
0 Members and 1 Guest are viewing this topic.
Offline Ask_Hjorth_Larsen

Junior Member




Java games rock!


« Reply #30 - Posted 2006-04-27 22:44:23 »

Well, then h == null. Why don't you just System.out.println the variables before the exception is thrown as everyone as suggested?

And when you post code you still don't specify which lines the exception propagate through.

And you still call
1  
2  
char[] C = null;
checkInput(IS , C);


Why not just call checkInput(IS, null) ? It looks like if C isn't supposed to be null since you take the trouble to declare it!
Offline harry@dayfamilyweb

Junior Member





« Reply #31 - Posted 2006-04-27 23:08:51 »

check inout sets the  value of C Grin Grin Grin Grin Grin
Online kevglass

JGO Kernel


Medals: 159
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #32 - Posted 2006-04-27 23:22:39 »

Its like a hideous car accident you see on the way home from work, its horrible and you feel sorry for the people involved but you can't help but stare. - sorry, wasn't adding anything

You can't set C inside the function, it doesn't exist, you'd only be setting the local scope pointer in the function. To do what you're aiming for you'd have declared the array, pass that in and set the contents.

Kev

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

Junior Member





« Reply #33 - Posted 2006-04-27 23:33:45 »

 Huh Huh Huh Huh Huh Huh Huh Huh Huh Huh Roll Eyes Cry
Offline Ask_Hjorth_Larsen

Junior Member




Java games rock!


« Reply #34 - Posted 2006-04-28 01:03:45 »

Sigh, I pointed it out in the very first post of this thread, yet it seems to have been forgotten. Anyway, C is a reference to null. When you pass that to the function it will NOT be able to change your reference. It can manipulate the OBJECT which your reference points to, for example it could put values into an array. However it cannot put values into null.

And while the method could create a new array and assigning a reference to it and put things into that, C still points to null.

You need to get hold of some more books.
Offline harry@dayfamilyweb

Junior Member





« Reply #35 - Posted 2006-04-28 01:17:01 »

would it work if c = new char[20] Huh
Offline harry@dayfamilyweb

Junior Member





« Reply #36 - Posted 2006-04-28 01:23:56 »

it works now  Shocked Shocked Grin Cheesy Wink Smiley Wink Cheesy Grin Grin Grin Shocked Shocked Shocked
i turn it into a thread  Grin Grin Grin Grin Grin Grin Grin Grin
                                       ( ),, adra kadabra
                                       /|\/
                                       / \
init:
deps-jar:
compile:
run:
intlizing
startting...
got output stream
starting
yield
BUILD SUCCESSFUL (total time: 4 seconds)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
package testofhsip;

import java.io.IOException;
import org.HSim.net.HSIP.NotStarted;
import org.HSim.net.HSIP.server.ManServe;
/**
 *
 * @author HandE
 */

public class Main {
   
    /** Creates a new instance of Main */
    public Main() {
    }
   
    /**
     * @param args the command line arguments
     */

    public static void main(String[] args) throws IOException {
       
        A a = new A();
        a.start();
       
        // TODO code application logic here
    }
    public static class A extends Thread {
        ManServe s = new ManServe();
        public void start() {
            System.out.println("intlizing");
            try {
                this.sleep(100);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
            s.start();
            this.yield();           
            System.out.println("starting");
            System.out.println("yield");
            try {
                this.sleep(1100);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
            this.yield();           
                     
        }
        public void run() {
            System.out.println("running;-)");
            try {
                System.out.println("................................");
                System.out.println("watting for thred....");
                System.out.println("................................");
                System.out.println("preparing to write!....");   
                this.yield();
                try {this.sleep(1100);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
               
                System.out.println("writing!!!....");
                System.out.println("hi");
                System.out.println("................................");
                s.writeString("hi");
                this.yield();
                try {this.sleep(1100);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }

                System.out.println("writing!!!....");
                System.out.println("................................");
                System.out.println("writting :_)");           
                System.out.println("yo");
                s.writeString("yo");
                this.yield();
                try {this.sleep(1100);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }

                System.out.println("writing!!!....");
                System.out.println("................................");
                System.out.println("cool");
                s.writeString("cool");
                this.yield();
                try {this.sleep(1100);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }

                System.out.println("writing!!!....");
                System.out.println("................................");
                System.out.println("bye");
                s.writeString("bye");
                this.yield();
                try {this.sleep(1100);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }

                System.out.println("preparing to close");
                System.out.println("wating");
                System.out.println("................................");
            } catch (IOException ex) {
                ex.printStackTrace();
            } catch (NotStarted ex) {
                ex.printStackTrace();
            }
            boolean exit = false;
            try {
                s.close(exit);
                this.yield();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            while(exit == false) {
                System.out.println("will not close");
                System.out.println("wil not close");
                System.out.println("clossing");
                try {
                    s.close(exit);
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
                System.out.println("tryed");
            }
            if(exit == true) {
                System.out.println("closed");
            }
        }
    }
   
}
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #37 - Posted 2006-04-28 02:47:31 »

Do you understand that in code like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public void close(boolean closed) throws IOException {
            if(star == true) {
                h.close();
                OSW.close();
                run = false;
                closed = true;
            }  else {
                closed = false;
            }    
           
       
    }

the assignment to 'closed' does absolutely nothing?  'closed' is passed BY VALUE, like everything in Java.  All that code does is change the value of the LOCAL variable 'closed',  the actual variable that you passed when you called the method remains unaffected.

In particular, this block of your latest code
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
            boolean exit = false;
            try {
                s.close(exit);
                this.yield();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            while(exit == false) {
                System.out.println("will not close");
                System.out.println("wil not close");
                System.out.println("clossing");
                try {
                    s.close(exit);
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
                System.out.println("tryed");
            }
            if(exit == true) {
                System.out.println("closed");
            }

has an infinite while-loop because 'exit' = false and it can never change.  Since it is a local variable it can't be touched outside that thread and nothing in that thread changes it after it has been initialized.

I don't intend to sound mean, but your code shows a basic lack of understanding of the Java language in general.  You should probably work on that a bit before you tackle writing a game.  Game programming is usually not beginner-level coding, unless you start with some very simple games, like Tic-Tac-Toe.
Have you gone through the Java tutorials a java.sun.com?  They are a good place to get familiar with the language.   

You should probably post in Newless Clubies unless you are really having a problem with networking as opposed to just general coding issues.

Offline harry@dayfamilyweb

Junior Member





« Reply #38 - Posted 2006-05-06 09:00:57 »

.
Quote
not intierly
Sigh, I pointed it out in the very first post of this thread, yet it seems to have been forgotten. Anyway, C is a reference to null. When you pass that to the function it will NOT be able to change your reference. It can manipulate the OBJECT which your reference points to, for example it could put values into an array. However it cannot put values into null.

And while the method could create a new array and assigning a reference to it and put things into that, C still points to null.

You need to get hold of some more books.
incorect whith arays  Grin becouse any aray can be refrenced from any class in the same JVM becous they are stored in the stack(well this is my gues but it works anyway Grin)my exampl is
1  
2  
3  
4  
5  
char[] c = new char[20];

 
 String s = "s";
 s.getChars(0 , 20 , c , 0);

that should work Grin
 s.getChars(0 , 20 , c , 0); is a void not an char[]
you shoould read the java docs  Grin Grin Grin Tongue Tongue Roll Eyes Cool Cool Shocked Smiley Wink Cheesy
Offline Ask_Hjorth_Larsen

Junior Member




Java games rock!


« Reply #39 - Posted 2006-05-06 13:26:11 »

What the heck are you talking about?

Of course you can manipulate an array from a method by passing a reference to that method, that's completely basic! Arrays can be referenced in exactly the same way as any other object can. And objects are stored on the heap, whereas references as such may be stored on the stack, though this is quite irrelevant to the discussion.

Allow me to reiterate the point with my previous post, namely that a null reference cannot be changed from inside a method to which it is passed. This is because passing a reference actually creates a copy of that reference, thus you cannot manipulate the original reference.
Pages: 1 [2]
  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.

TehJavaDev (13 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (31 views)
2014-08-16 06:45:27

Tekkerue (32 views)
2014-08-16 06:22:17

Tekkerue (19 views)
2014-08-16 06:20:21

Tekkerue (29 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (42 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!