|
A null pointer is when it returns a Null, right?
I don't see the problem because that part of the code is unchanged. so why return an error now
|
|
|
|
|
You have a serious bug in your newThread() method that causes the nullpointer exception.
|
|
|
|
|
Parsing the Socket into the thread was my screw up, so It was replaced with parameters of the thread.
|
|
|
|
|
OK, here are a few suggestions:
1. I see you are coming from C because you declare all your function local variables at the beginning of the functions (sorry, methods). Declare your variables where you use it, or at least most most-inner scope where you need it.
2. Room does not have to implement the Runnable interface and you dont have to create a new thread for the room in your main(), call the run() method directly and execute it with the main thread.
3. The biggest mistake that causes the nullpointer is in Client.newThread: you should pass in this instead of new Clients(). I would do the work of Client.newThread in the constructor of Client and would create Client only after accepting the socket.
|
|
|
|
|
I really don't understand, this is currently beyond me at the moment.
|
|
|
|
|
Well, object oriented programming is not easy at first. Socket/network programming is also hard. Threading is another beast. And you are mixing all of these, are you sure this is what you wanna do?
|
|
|
|
|
I'm committed to learn it and since I'm self taught, I've decided to throw myself in and learn how it all works then learn in more depth.
|
|
|
|
|
I don't recommend doing so, but good luck!
|
|
|
|
|
how to make session in beanshell ??
|
|
|
|
|
Please try a better title, and a clearer question. You should first try typing this question into Google to see what you get.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
jsp里边有一个内置的对象叫做session,不需要创建直接用就行,调用方法比如session.setAttribute("name","value");
you needn't create but it exeists.
|
|
|
|
|
Hi,
i have a main webpage with this code
<input type="button" value="Maak een bord positie code" onClick="window.open('makeboard.html','makeposition',' width=500,height=700');">
my form is, i think well formed
<form name="post" action="add.php" method="post" name="myform" id="myform"> and also closed
On the child form I have some code
var pa=parent.document.getElementById('myform')
However the var pa is empty.
has someone an idee what is wrong?
Jan
|
|
|
|
|
Are you sure this is java? Looks more like javascript.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
Your right. It's javascript. I didn't know there is another forum for javascript. However I found it after days of looking I posted the question and today I found that I must use 'window.opener.document'
Jan
PS: If there is an admin he/she may move the message to the correct forum
|
|
|
|
|
Okay. The admins may or may not move this, it depends on getting them sober enough for long enough.
BTW, I did not 1 vote your question, I will counter it as it is not deserved.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
hello
I wanna make session between two field in code .bsh (BeanShell) : is sample java code
Internet pages contain the same field Example: Field Name
When entering values in the first field in the first page and move on to the second page must be entered the same values found in the other the right
please i want that code ???
|
|
|
|
|
I want the code to generate everything I need for the project I'm working on, but that doesn't mean I'll get it.
Try to rephrase the question as a first step to make it clearer (I don't understand very much of what you're asking to be honest). And as a second step, try at least to come up with a solution all by yourself, post what you've come up with, and where you got stuck. People will try to help you, but only if you show that you're willing to help yourself.
In the current form of your question, you're highly unlikely to get an answer.
Full-fledged Java/.NET lover, full-fledged PHP hater.
Full-fledged Google/Microsoft lover, full-fledged Apple hater.
Full-fledged Skype lover, full-fledged YM hater.
modified 2-Aug-12 7:03am.
|
|
|
|
|
Hai,can any one help me in this querry.
I am calling a function 'A' which is in a class 'CA', from a function 'B' which is in the Class 'CB'.If there is any exception produced in function 'A' it will generate an error code(intiger Value)in Catch block.How can i get that error code from the Function A to function B only if the exception had occured.
|
|
|
|
|
If the error code generated by method A on exception is unique (meaning that no normal output from A will ever match that error code), you can simply do this (assuming that error code returned on exception is -1):
if(ca.A() == -1) {
}
Conversely, if you have access to the sources and you are allowed to modify them, don't catch the exception. Modify the CA.A() method signature and add throws ExceptionThrownFromCA (just an example). Like this, you don't even need to check the error code, and you can do this:
public void B() {
CA ca = new CA();
try {
ca.A();
} catch(ExceptionThrownFromCA e) {
}
}
Full-fledged Java/.NET lover, full-fledged PHP hater.
Full-fledged Google/Microsoft lover, full-fledged Apple hater.
Full-fledged Skype lover, full-fledged YM hater.
modified 1-Aug-12 10:07am.
|
|
|
|
|
Further to the earlier answer:
0. There are no functions. In the OO world, an object supports methods and, in some cases but not Java, properties.
1. If a class throws an exception it must declare it in it's signature:
void methodName() throws MethodException {
...
}
2. An exception is not an error. An exception should be used when you don't know what to do or cannot continue processing. As an example, if you insert a row into a table and it violates a unique constraint then that is an exception. If you try to read a value from a table and it does not exist that is an error.
3. It is advisable to not use an exception to pass results. The choice should be that if an exception is thrown the calling method defaults a result or the called method's return values must include an error range.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
Thankyou for your reply .
So what you suggest to do for the above case
|
|
|
|
|
I do not have your code so I cannot possibly say which way is better, that is up to the implementation. If the called method knows what to do irrespective of the caller then the exception should not be thrown up the stack.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
Can i make that error code variable as global and when ever i am calling any fuction after that itself i will access the error code and check it.
|
|
|
|
|
There is no such thing as 'global' in java.
One approach is to have an error state within a class, but this may not be appropriate. I would suggest that if you need to have a return code AND an exception then you can always return a composite class:
public class ReturnState {
private final int code;
private final String description;
private final Object object;
private final Exception exception;
public ReturnState (int code,
String description,
Object object,
Exception exception) {
this.code = code;
this.description = description;
this.object = object;
this.exception = exception;
}
public int getCode() {
return this.code;
}
public Exception getException() {
return this.exception;
}
...
}
That said, it is rare that you need BOTH so either have the return codes include errors or use exceptions.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
k
Got it thanks a lot, i will return the exception,according to the exception i will generate the error code in my calling function.
|
|
|
|