String knock = "\u042F \u0418\u0433\u043e\u0440\u044c";
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
String knock = "\u042F \u0418\u0433\u043e\u0440\u044c";
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
String knock = "\u042F \u0418\u0433\u043e\u0440\u044c";
Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Campbell Ritchie wrote:That code can easily be put into the constructor for that class.
String knock = "\u042F \u0418\u0433\u043e\u0440\u044c";
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:Here is your code, with some annotations:
String knock = "\u042F \u0418\u0433\u043e\u0440\u044c";
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
String knock = "\u042F \u0418\u0433\u043e\u0440\u044c";
Campbell Ritchie wrote:I would disagree very severely with anybody who uses addActionListener(this) as a routine.
I can't find where your MullPointerException occurred, since line 124 is blank!
String knock = "\u042F \u0418\u0433\u043e\u0440\u044c";
fred rosenberger wrote:Do you know what we mean by a constructor? It is a special method that you have to define yourself. This line:
is CALLING a constructor, but it isn't one itself. If you don't write any constructors, java is kind enough to make a zero-argument one for you, which is what is being called here. However, if you just stuck this code in there somewhere, you still have code NOT IN A METHOD. Adding more code will still not not put your existing code in a method.
Here is a basic example:
(Note: I just whipped this up, it may not be 100% valid)
Here I have done several things. I have defined a member variable "intMember". Then, I have a main() method. I then have two constructors. The important thing about are:
1) They have the EXACT same name as the class itself
2) There is NO return type - not even "void".
One is a no-arg constructor. If you would call "new MyClass()", this is what would happen, and intMember would be set to 17. I ALSO created a second constructor that takes a single int parameter. If you call "new MyClass(12)" or "new MyClass(intVariable)", THAT code would run, setting intMember to the value passed in.
Another note: If I define any constructor at all, Java will not provide by default a no-arg constructor.
So, try writing your own constructor for your class, and put all that bad code inside it. Post it here when you're done (and any compilation errors), and we'll take a look.
String knock = "\u042F \u0418\u0433\u043e\u0440\u044c";
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:you declare the variable sendButton, but you never create the object it refers to. Therefore, you cannot call a method on the object (because it doesn't exist!!!).
String knock = "\u042F \u0418\u0433\u043e\u0440\u044c";
Campbell Ritchie wrote:I never said it was deprecated. I said I disagree with it. I think it isn't object-oriented. See this thread, and the older thread it refers to, and this thread. There are bound to be others if you search.
String knock = "\u042F \u0418\u0433\u043e\u0440\u044c";
Why does "sendButton.addActionListener(this); " prevent the code from running?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:
Why does "sendButton.addActionListener(this); " prevent the code from running?
Impossible to say without seeing your code in it's current state
If you post your code again, please take out those huge comment blocks. They just make it harder to read the important stuff.
Now...does it not RUN, or does it not COMPILE? There is a huge difference. If you are getting the nullpointerexception, see my post above. it appears you may be trying to call a method on an object you never created.
String knock = "\u042F \u0418\u0433\u043e\u0440\u044c";
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
String knock = "\u042F \u0418\u0433\u043e\u0440\u044c";
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|