java code wont compile - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

java code wont compile

rootroot Posts: 103Member
hi trying to get this code to compile but it comes up with errors:


class ExampleOneBeta
{
public static void main(String args[])
{
ExampleOne ExampleOne_object = new ExampleOne();
//The line above is invoking an object of the type ExampleOne
int variable_1 = 10;
double variable_2 =5.5;
char variable_3 ='A';
local_variable_1 = ExampleOne_object.variable_1;
local_variable_2 = ExampleOne_object.variable_2;
local_variable_3 = ExampleOne_object.variable_3;
System.out.print(local_variable_1);
// System.out.print(" ");
// System.out.print(local_variable_2);
// System.out.print(" ");
// System.out.print(local_variable_3);
}
}

the errors are:


example_one.java:5: cannot find symbol
symbol : class ExampleOne
location: class ExampleOneBeta
ExampleOne ExampleOne_object = new ExampleOne();
^
example_one.java:5: cannot find symbol
symbol : class ExampleOne
location: class ExampleOneBeta
ExampleOne ExampleOne_object = new ExampleOne();
^
example_one.java:10: cannot find symbol
symbol : variable local_variable_1
location: class ExampleOneBeta
local_variable_1 = ExampleOne_object.variable_1;
^
example_one.java:11: cannot find symbol
symbol : variable local_variable_2
location: class ExampleOneBeta
local_variable_2 = ExampleOne_object.variable_2;
^
example_one.java:12: cannot find symbol
symbol : variable local_variable_3
location: class ExampleOneBeta
local_variable_3 = ExampleOne_object.variable_3;
^
example_one.java:13: cannot find symbol
symbol : variable local_variable_1
location: class ExampleOneBeta
System.out.print(local_variable_1);
^
6 errors

any ideas ???
i am new to java

Comments

  • zibadianzibadian Posts: 6,349Member
    : hi trying to get this code to compile but it comes up with errors:
    :
    :
    : class ExampleOneBeta
    : {
    : public static void main(String args[])
    : {
    : ExampleOne ExampleOne_object = new ExampleOne();
    : //The line above is invoking an object of the type ExampleOne
    : int variable_1 = 10;
    : double variable_2 =5.5;
    : char variable_3 ='A';
    : local_variable_1 = ExampleOne_object.variable_1;
    : local_variable_2 = ExampleOne_object.variable_2;
    : local_variable_3 = ExampleOne_object.variable_3;
    : System.out.print(local_variable_1);
    : // System.out.print(" ");
    : // System.out.print(local_variable_2);
    : // System.out.print(" ");
    : // System.out.print(local_variable_3);
    : }
    : }
    :
    : the errors are:
    :
    :
    : example_one.java:5: cannot find symbol
    : symbol : class ExampleOne
    : location: class ExampleOneBeta
    : ExampleOne ExampleOne_object = new ExampleOne();
    : ^
    : example_one.java:5: cannot find symbol
    : symbol : class ExampleOne
    : location: class ExampleOneBeta
    : ExampleOne ExampleOne_object = new ExampleOne();
    : ^
    : example_one.java:10: cannot find symbol
    : symbol : variable local_variable_1
    : location: class ExampleOneBeta
    : local_variable_1 = ExampleOne_object.variable_1;
    : ^
    : example_one.java:11: cannot find symbol
    : symbol : variable local_variable_2
    : location: class ExampleOneBeta
    : local_variable_2 = ExampleOne_object.variable_2;
    : ^
    : example_one.java:12: cannot find symbol
    : symbol : variable local_variable_3
    : location: class ExampleOneBeta
    : local_variable_3 = ExampleOne_object.variable_3;
    : ^
    : example_one.java:13: cannot find symbol
    : symbol : variable local_variable_1
    : location: class ExampleOneBeta
    : System.out.print(local_variable_1);
    : ^
    : 6 errors
    :
    : any ideas ???
    : i am new to java
    :
    :
    Your class definition is called ExampleOneBeta, while in your code you use the name ExampleOne. You define various variables using the name variable_#, where # is a number. In your code you use local_variable_# instead of the defined names. This mixing of names confuses the compiler, since it doesn't know what the variable called local_variable_1 stands for, what type it is, how much memory it needs to reserve for it, etc.
  • rootroot Posts: 103Member
    thanks, changed the code to:

    {
    public static void main(String args[])
    {
    ExampleOneBeta ExampleOneBeta_object = new ExampleOneBeta();

    //The line above is invoking an object of the type ExampleOneBeta

    int local_variable_1 = 10;
    double local_variable_2 =5.5;
    char local_variable_3 ='A';

    local_variable_1 = ExampleOneBeta_object.local_variable_1;
    local_variable_2 = ExampleOneBeta_object.local_variable_2;
    local_variable_3 = ExampleOneBeta_object.local_variable_3;

    System.out.print(local_variable_1);
    System.out.print(" ");
    System.out.print(local_variable_2);
    System.out.print(" ");
    System.out.print(local_variable_3);



    now get the following errors:



    example_one.java:13: cannot find symbol
    symbol : variable local_variable_1
    location: class ExampleOneBeta
    local_variable_1 = ExampleOneBeta_object.local_variable_1;
    ^
    example_one.java:14: cannot find symbol
    symbol : variable local_variable_2
    location: class ExampleOneBeta
    local_variable_2 = ExampleOneBeta_object.local_variable_2;
    ^
    example_one.java:15: cannot find symbol
    symbol : variable local_variable_3
    location: class ExampleOneBeta
    local_variable_3 = ExampleOneBeta_object.local_variable_3;
    ^
    3 errors

    thanks
  • zibadianzibadian Posts: 6,349Member
    : thanks, changed the code to:
    :
    : {
    : public static void main(String args[])
    : {
    : ExampleOneBeta ExampleOneBeta_object = new ExampleOneBeta();
    :
    : //The line above is invoking an object of the type ExampleOneBeta
    :
    : int local_variable_1 = 10;
    : double local_variable_2 =5.5;
    : char local_variable_3 ='A';
    :
    : local_variable_1 = ExampleOneBeta_object.local_variable_1;
    : local_variable_2 = ExampleOneBeta_object.local_variable_2;
    : local_variable_3 = ExampleOneBeta_object.local_variable_3;
    :
    : System.out.print(local_variable_1);
    : System.out.print(" ");
    : System.out.print(local_variable_2);
    : System.out.print(" ");
    : System.out.print(local_variable_3);
    :
    :
    :
    : now get the following errors:
    :
    :
    :
    : example_one.java:13: cannot find symbol
    : symbol : variable local_variable_1
    : location: class ExampleOneBeta
    : local_variable_1 = ExampleOneBeta_object.local_variable_1;
    : ^
    : example_one.java:14: cannot find symbol
    : symbol : variable local_variable_2
    : location: class ExampleOneBeta
    : local_variable_2 = ExampleOneBeta_object.local_variable_2;
    : ^
    : example_one.java:15: cannot find symbol
    : symbol : variable local_variable_3
    : location: class ExampleOneBeta
    : local_variable_3 = ExampleOneBeta_object.local_variable_3;
    : ^
    : 3 errors
    :
    : thanks
    :
    In java there are 2 kinds of variables: local and object variables. You have defined 3 local variables, but no object variables. Then in your code you try to assign values from undefined object variables to local variables. In other words: local_variable_1 is [b]not[/b] the same as ExampleOneBeta_object.local_variable_1.
Sign In or Register to comment.