Kyle Fraser

Greenhorn
+ Follow
since Mar 06, 2014
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kyle Fraser

Thanks so much, Pawel! Turns out the misplacing of the [] was the culprit, but the rest made it a lot clearer, and made way more sense.

Thank you very much!
9 years ago
Hey! So I'm really new to Java, and I'm learning using Headstart Java. I'm working on a side project, which will eventually hopefully be a Pokedex, and I've just been going to it at the end of every chapter and using the stuff I've learned to work on it.

So I just read chapter 3, which is all about variables and teaches how to use arrays.

my question is, does an array have to be declared inside a method? Because I'm trying to create an array inside a class without any methods and without the main, and I continuously get errors. Here's a quick working of my code that won't compile.




The error message focuses on Telling me the 0 should be a ], the = is an illegal start of type, so on and so forth.

The program compiles completely fine if it's within a method, like this:




Or if I have But I'm trying to practice working outside of main.

So does an array have to be within a method, or am I just daft, and missing something obvious?

Thanks in advance.
9 years ago
Yes, that compiled perfectly! Thanks so much!

Just for further understanding though, by this:

This error is because your variables such as "name" are declared inside the main() method giving them method scope only.



Do you mean that variables defined inside main can only be used inside main? Because if so, I actually didn't know that, and would explain a ton of my problems.
9 years ago
Alright, so that made sense, I can't believe I forgot to put System.out.println. That was silly. =p

I changed my code to this:



And now I'm getting the following error:



And so on and so forth for every variable.

I don't know too much about the errors yet, and a google search informs me that symbol errors can mean a great number of things.

I appreciate the assistance I've been given, and I would greatly appreciate any more!
9 years ago
Hey guys, thanks for always being so helpful, even to the silliest of questions I ask. I truly appreciate the ability to have access to such a fantastic community.

So I'm trying to make a real simple Pokedex. Right now, I'm just doing a test entry. I have all the variables and such assigned and ready to go, and it compiles fine. But the moment I start to add a method to put it all together, everything falls apart. This is the code as it stands:



And then I get this error back:




I've tried removing public static void main (String[]]args) and it's brackets, which leads to a huuuuge error list.

So I honestly can't figure it out. I'm following along with Headstart Java if aybody is wondering, just finished chapter 5. This is just a project I'm doing because arrays are still really confusing. So by the time I get this figured out and completed, I should have a pretty darn good understanding of them.

Anyways, any help would be much appreciated, and I can supply any more needed information!
9 years ago
Yes, I have figured it out! This is what I love about programming. A problem gives you such a hard time, you start to feel bad about yourself.

But maaaan, when you figure it out, it feels fantastic. Like one of the best feelings to me.

Thanks a ton to you guys, you are prime reasons why I am always on this forum, even if I don't post much. And also thanks to the mod who pointed out the Code tag to me!
9 years ago
Oh, I also fixed the capitalization, to the same error.
9 years ago
So I tried a different approach, by having two separate classes, Cat and catTest. Defining cry inside Cat, and then creating a new cat object inside catTest, as well as moving main over to catTest. I've done this before, and I don't know what I'm doing wrong. Maybe I'm just brainfarting.









The error when I try and compile catTest:




They are in the same folder. In their own folder for that matter.
9 years ago
Hey guys. So this isn't really for anything, I'm just programming random useless programs to try and get a better grasp of the various areas in Java. I've come to a (probably silly) problem though.

This code just won't compile:



I'm super new to Java, so I'm probably just doing something wrong, or thinking of it like a different language.

As far as I can see, I've created an object of cat, and already defined the int cry variable. But when I try and compile the code, I get this:



I'm trying to get better at reading the error screens, so I can be a bit more self-sufficient, so if it's possible to relate what I'm doing wrong to the error screen in a bit easier to understand language, I would greatly appreciate it!

Thanks in advance!
9 years ago
Hey guys! So I'm brand new to both these forums and Java. The thing I love about the programming community is that it is one of the rare communities that is almost unanimously catering to each-other. Yeah, there is a lot of cross-language rivalry, but I've NEVER encountered a time where I was denied help by anyone, regardless of the language. And you here and Code Ranch seem to exemplify that!

Anyways, I'm setting out on a brave new adventure to try and learn Java, which has been a bit of a life goal of mine. I picked up a copy of Head-First Java (Second Edition), and I have nothing but high praise for it. It's the second most user-friendly programming book I've ever read, behind only "Learn To Program" by Chris Pine. (Ruby fanboy bias.)

My only issue is with the style it teaches. It has you programming a lot of things, but doesn't explain them until a later chapter. It's not a criticism at all, I know some people love to learn that way, I just like to know what I'm working with.

So a few questions:

-I noticed a lot of times, you are required to put an empty () after a lot of things, like when you are calling a method and such. What is the reason for it?

-What is the purpose of declaring (String[]args) after your main method? The bookk made it quite clear it's something you have to do, but never quite explained why.

- What is the purpose of while (true)? I know in some languages, it's to create a never-ending loop. Is that true in Java as well?

Thanks a ton in advance, and I'm thrilled to have found this community!
10 years ago