Pedro Fonseca

Greenhorn
+ Follow
since Mar 28, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Pedro Fonseca

I guess I don't...?

Gotta be honest, I'm yet to properly wrap my head around everything regarding connections, I understand the very basic bare bones (if that much).

EDIT: How can I add a listener to that code so it allows me to test it?

Something like printing the sent message on the terminal window, but anything will do.
12 years ago
I'm currently doing some server-related exercises, but can't make my localhost accept connections.

I'm using a MacBook Pro running Snow Leopard, the apache is turned on, firewall was off (I did try to turn it on and tell it to enable incoming connections, but didn't work) and I have Growl installed (tried disabling it already).

Here's the code I'm using:

And here's the exception stack

Searching around I found this command line to test the connection, but it gives me a connection refused too.
12 years ago
Whoa, thank you very much, it worked like a charm!

I didn't know/think that it meant declaring a new variable (and I did the same to the question variable).

Looking at it again, the book code doesn't declare them again, so it is most probably something I typed without properly realizing it and then proceeded to focus on the wrong part of the problem.

Anyway, again, I thank you very much for your help, Paul, I was already getting kinda desperate for not figuring what was wrong with the code.
12 years ago
Hello everyone, I'm studying Java with the Head First Java book and currently am at the I/O chapter, so one of the exercises is to make a Quiz Card class, builder and player.

However, I'm having issues with the builder as, for some reason, the program is not being able to read the content in the JTextAreas where you type your desired question and answer, whenever I try to do anything with the data, it throws a NullPointerException at runtime, even if the field is not blank and even after putting a setText() just before it.

If anyone could give me any insight of what is going wrong, I'd really appreciate it as I wasn't able to find any iffy code (I might be wrong) or a way to make it work, trying everything in my still limited knowledge to fix it, such as the aforementioned setText(), checking if the problem was the button, etc.

Here's the code as provided in the book (and from what I've learned so far, it was supposed to work):


It also uses a separate QuizCard class, which anyone using the book should write on their own and mine's as such:


I've considered the possibility of the problem being with my class, however testing everything by removing all instances where the separate class was called still gave me the exception, so it doesn't seem to be the problem (again, might be wrong).

Thanks in advance for any insights.
12 years ago
Good catch, thanks for the replies.

Indeed the problem was another Track.class in the same folder as the MiniMiniMusicApp, I have to be more cautious about this sort of thing in the future.
13 years ago
Ok, at first I typed everything just as in the book and...it didn't work, giving me a message that the Track symbol wasn't found.


But much to my surprise, giving the full address of the Track object suddenly made everything work just fine!



So I'm left wondering why in hell it didn't work previously, why didn't the import line work as intended? Is there any explanation at all?
13 years ago
Ow, duh!

I feel incredibly stupid to let such a simple mistake slip by, but thanks for the help it works like a clockwork now!

And thanks for the tip, it looks like it's indeed time to get an IDE.
13 years ago
Hello everyone, I just recently started studying Java on my own using the book Head First Java and everything was going rather smoothly until the sixth chapter with the battleship-ish game, where I'm getting an error I have no idea how to fix since from what I know so far, the code's supposed to work.

I did check the web for the error and found some answers, however, most of them did not apply here (at least I don't think they do) since I'm declaring a method and the ones that were somewhat similar didn't work at all (for example, there was one that mentioned that the code given in the HFJ website worked once a line was fixed, but here it didn't work either.

For those familiar with the book, both the DotCom and GameHelper classes are on the same folder as the DotComBust and I typed them myself (they both compiled just fine).

And not sure if it makes any difference (shouldn't), but I'm doing all this on a mac, using the text edit to type all the code (but I have converted it to plain text instead of the default rich text).

Well, without further ado, here's the code:


And here's the error list:


The setName method refers to the DotCom class that is in another file at the same folder and is coded to take an n String.
13 years ago