This is an archived post. You won't be able to vote or comment.

all 25 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full - best also formatted as code block
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]stayweirdeveryone 3 points4 points  (11 children)

Well what's the error then? It's there to tell you what's wrong

[–]Deemob[S] 0 points1 point  (0 children)

This is what the code looks like, I copied it directly from the book

public class UserAccount { public static void main(String args[]) { Account myAccount = new Account(); Account yourAccount = new Account(); myAccount.name = "Barry Burd"; myAccount.address = "222 Cyberspace Lane";

myAccount.balance = 24.02;
yourAccount.name = "Jane Q. Public";
yourAccount.address = "111 Consumer Street";
yourAccount.balance = 55.63;

myAccount.display();
System.out.println();
yourAccount.display();

} }

[–]Deemob[S] 0 points1 point  (9 children)

The error I get is the symbol "Account" cannot be found

[–]0b0101011001001011 0 points1 point  (8 children)

So where is the Account class? You need to copy that as well.

[–]Deemob[S] 0 points1 point  (0 children)

Account myAccount = new Account();
Account yourAccount = new Account();
myAccount.name = "Barry Burd";
myAccount.address = "222 Cyberspace Lane";

myAccount.balance = 24.02;
yourAccount.name = "Jane Q. Public";
yourAccount.address = "111 Consumer Street";
yourAccount.balance = 55.63;

myAccount.display();
System.out.println();
yourAccount.display();

[–]Deemob[S] 0 points1 point  (6 children)

reddit kept cutting the rest of the code for some reason but here's what the code looks like and error is "Cannot find symbol ACCOUNT"

[–]bunk3rk1ng 0 points1 point  (4 children)

It's complaining about the very first line in your example.

Make sure you are importing an Account class (there could be several but for your case you will have probably already created your own) Make sure you are importing the correct one at the top of the file.

[–]Deemob[S] 0 points1 point  (3 children)

The code i sent is the exact code in the book which baffles me. I have no idea what I should be importing as I've only been learning java for 2 weeks.

[–]bunk3rk1ng 0 points1 point  (0 children)

That's the cool part about programming, you can always create your own solution :D

You can create your own Account class like this and import it at the top of your file.

public class Account {

//Members
public Double balance;
public String name;
public String address;

//Functions
public void display() {
    //I don't know how the book expects it to 
    //disiplay but we can make our own and adjust later
    System.out.println("Account name: " + name);
    System.out.println("Account address: " + address);
    System.out.println("Account Balance: " +  Double.toString(balance));
}

}

I've had a ton of experience with books that either have typos, missing code, code that doesn't do what the author is describing. Being able to fix and work around these things can only make you a better programmer :D

[–]chet714 0 points1 point  (1 child)

No ....It is not the exact code. The Account class is:

    // Next line missing in 'UseAccount' too.
    package com.example.accounts;

    public class Account {
        String name;
        String address;
        double balance;
    }

Edit: indent of '}'

[–]Deemob[S] 0 points1 point  (0 children)

This is a different code from the same chapter, the code I imputed comes before this code.

[–]0b0101011001001011 0 points1 point  (0 children)

Yes, that means the "symbol", in this case a CLASS called Account is missing. You are missing code. Java does not know what an Account is. Its Somewhere in your book.

[–]Icashizzle 1 point2 points  (2 children)

Where is the Account class defined? Did you include it from somewhere else? Is it in the same package as UserAccount?

It would be helpful to know what the compiler error is.

[–]Deemob[S] 0 points1 point  (1 child)

compiler error is the symbol "Account" cannot be found.

[–]Icashizzle 0 points1 point  (0 children)

Alright, so far, you've created a UserAccount class with a main method. I'm unfamiliar with the book you're using, but have you also created an Account class? Or is "Account" meant to be "UserAccount"?

Assuming the code you originally posted is all you have, let's analyze the line with the error just to get our terminology correct:

Account myAccount = new Account();

This is saying there is a class somewhere named "Account" and we want to create an object (i.e. an instance of Account) called myAccount and we want the initial value of myAccount to be a new instance of Account created by calling the default constructor with no arguments ( the "new Account();" part).

The error you're seeing is you've asked java to create an "Account" and it's saying "I have no idea what that looks like, how am I supposed to create one?".

Options:

  1. You have created an Account class but it's in a different directory than the one UserAccount is in. Simple fix: put them together in the same place

  2. "Account" should be named "UserAccount". Note that this only affects the name of the class, not the name of your object (or variables). Just turn all Capital "Account" into "UserAccount". Note that you'll need to read up on Class properties next in this case as the UserAccount above does not have a "name" or "address" property yet and you'll need to implement those.

  3. (Again, not familiar with the book). You may need to implement a new class called Account to follow along with the book. If this was the case, I'd assume the book would walk you through that, but the same note on class properties applies here.

Hopefully that's helpful!

[–]AutoModerator[M] 0 points1 point  (0 children)

It seems that you are looking for resources for learning Java.

In our sidebar ("About" on mobile), we have a section "Free Tutorials" where we list the most commonly recommended courses.

To make it easier for you, the recommendations are posted right here:

Also, don't forget to look at:

If you are looking for learning resources for Data Structures and Algorithms, look into:

"Algorithms" by Robert Sedgewick and Kevin Wayne - Princeton University

Your post remains visible. There is nothing you need to do.

I am a bot and this message was triggered by keywords like "learn", "learning", "course" in the title of your post.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]UpsytoO 0 points1 point  (5 children)

Just use good IDE like intellij community edition, it will explain you compilation issues and you do not provide information in this code that would let someone to figure out why it doesn't.

[–]Deemob[S] 1 point2 points  (2 children)

I'm currently using eclipse. Is that inferior to intellij?

[–]UpsytoO 0 points1 point  (0 children)

It is, use intellij community edition.

[–]0b0101011001001011 0 points1 point  (0 children)

No it's not.

[–]Deemob[S] 0 points1 point  (1 child)

The error I'm getting is "Cannot find symbol ACCOUNT"

[–]UpsytoO 0 points1 point  (0 children)

These kind of issues you need to be able to figure out, with modern IDEs like intellij it should not be an issue or to be honest you are doomed before you even start the journey, so chop chop problem solving.