Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
java code wont compile Posted by root on 10 Jan 2007 at 11:52 AM
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

Report
Re: java code wont compile Posted by zibadian on 10 Jan 2007 at 3:40 PM
: 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.
Report
Re: java code wont compile Posted by root on 10 Jan 2007 at 4:04 PM
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
Report
Re: java code wont compile Posted by zibadian on 10 Jan 2007 at 4:19 PM
: 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 not the same as ExampleOneBeta_object.local_variable_1.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.