Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Newbie has simple question

Reply
Thread Tools

Newbie has simple question

 
 
bilsch
Guest
Posts: n/a
 
      05-02-2012
I wrote a loop that reads a text file (NVRAM.TXT) and stores it in a big
character array and prints it out. It works fine. Just for the heck of
it I tried to break it into two files: one that does the reading and the
creation of the array, and another (with main) that prints out the first
10 characters of the array. It doesn't work. There's something wrong
with how I reference the array in the main program. The two files are
shown below, along with the error message that is generated. The
statement causing the error is:

System.out.print(bstr.nvchr[n]);

Please tell me how to make it work (if possible). Here are the two files:

public class NvrWork {
public static void main(String[] args) {
int n;
BigString bstr = new BigString();
for (n = 1; n < 10; n++) {

System.out.print(bstr.nvchr[n]);

}
}
}

public class BigString {

public BigString() {
int fin = 1;
int count = 1;
try {
FileInputStream file = new FileInputStream("NVRAM.TXT");
char[] nvchr = new char [30000];

while (fin != -1) {
fin = file.read();
nvchr[count] = (char) fin;
//System.out.print(nvchr[count]);
count++;
}
System.out.println("Bytes read : " + count);
file.close();
} catch (IOException e){
System.out.println("Could not read file");
}

}
}

OUTPUT:

run:
Bytes read : 26017
Exception in thread "main" java.lang.RuntimeException: Uncompilable
source code - Erroneous tree type: <any>
at NvrWork.main(NvrWork.java:9)
Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)

TIA. Bill S.
 
Reply With Quote
 
 
 
 
Stefan Ram
Guest
Posts: n/a
 
      05-02-2012
bilsch <(E-Mail Removed)> writes:
>statement causing the error is:
>System.out.print(bstr.nvchr[n]);


This requires »nvchr« to be a field of »bstr« (»BigString«),
but »nvchr« is not a field of »bstr« (»BigString«). It is only
a local variable used in its constructor.

 
Reply With Quote
 
 
 
 
bilsch
Guest
Posts: n/a
 
      05-02-2012
On 05/02/2012 05:22 AM, Stefan Ram wrote:
> bilsch<(E-Mail Removed)> writes:
>> statement causing the error is:
>> System.out.print(bstr.nvchr[n]);

>
> This requires »nvchr« to be a field of »bstr« (»BigString«),
> but »nvchr« is not a field of »bstr« (»BigString«). It is only
> a local variable used in its constructor.
>


I don't understand what makes it different than the variables fin and
count which are both printable from the main program. Is there no way
to make it work? What does it mean to be a 'field'? Could you tell me
more?
 
Reply With Quote
 
Silvio Bierman
Guest
Posts: n/a
 
      05-02-2012


On 05/02/2012 02:10 PM, bilsch wrote:
> I wrote a loop that reads a text file (NVRAM.TXT) and stores it in a big
> character array and prints it out. It works fine. Just for the heck of
> it I tried to break it into two files: one that does the reading and the
> creation of the array, and another (with main) that prints out the first
> 10 characters of the array. It doesn't work. There's something wrong
> with how I reference the array in the main program. The two files are
> shown below, along with the error message that is generated. The
> statement causing the error is:
>
> System.out.print(bstr.nvchr[n]);
>
> Please tell me how to make it work (if possible). Here are the two files:
>
> public class NvrWork {
> public static void main(String[] args) {
> int n;
> BigString bstr = new BigString();
> for (n = 1; n < 10; n++) {
>
> System.out.print(bstr.nvchr[n]);
>
> }
> }
> }
>
> public class BigString {
>
> public BigString() {
> int fin = 1;
> int count = 1;
> try {
> FileInputStream file = new FileInputStream("NVRAM.TXT");
> char[] nvchr = new char [30000];
>
> while (fin != -1) {
> fin = file.read();
> nvchr[count] = (char) fin;
> //System.out.print(nvchr[count]);
> count++;
> }
> System.out.println("Bytes read : " + count);
> file.close();
> } catch (IOException e){
> System.out.println("Could not read file");
> }
>
> }
> }
>
> OUTPUT:
>
> run:
> Bytes read : 26017
> Exception in thread "main" java.lang.RuntimeException: Uncompilable
> source code - Erroneous tree type: <any>
> at NvrWork.main(NvrWork.java:9)
> Java Result: 1
> BUILD SUCCESSFUL (total time: 3 seconds)
>
> TIA. Bill S.




You have quite some nerve to abandon an earlier thread and simply start
a new one.

Silvio Bierman
 
Reply With Quote
 
bilsch
Guest
Posts: n/a
 
      05-02-2012
I didn't abandon the previous thread. It was finished. This is a new
question and wouldn't even belong in the previous thread.

>
>
>
> You have quite some nerve to abandon an earlier thread and simply start
> a new one.
>
> Silvio Bierman


 
Reply With Quote
 
Silvio Bierman
Guest
Posts: n/a
 
      05-02-2012
On 05/02/2012 02:57 PM, bilsch wrote:
> I didn't abandon the previous thread. It was finished. This is a new
> question and wouldn't even belong in the previous thread.
>
>>
>>
>>
>> You have quite some nerve to abandon an earlier thread and simply start
>> a new one.
>>
>> Silvio Bierman

>


You obviously have little experience posting to newsgroups.

First of all, do not top-post. Put your replies at the bottom om the
message you are replying to, optionally trimming parts of the original
message. This makes it easier for other people to keep track of the
discussions.

Secondly, a thread you start is not "finished" because you think that
responses are less than helpful and you have lost interest.
If you have resolved your problem, with or without the help of other
thread participants, you are supposed to make such known by posting a
closing message telling people that, and how, you have resolved the
issue. Thanking everyone for their responses at the same time is not
optional.

You are very lucky to have experienced and highly skilled people
available to help you with your programming issues. Handle them with the
grace they deserve and they will continue to be of invaluable help to you.
 
Reply With Quote
 
bilsch
Guest
Posts: n/a
 
      05-02-2012
I told people I had deleted the offending file - therefore I couldn't
provide the error information. Deleting the file ended the problem -
which I said. I've been posting in news groups since before you got out
of grade school.



> Secondly, a thread you start is not "finished" because you think that
> responses are less than helpful and you have lost interest.
> If you have resolved your problem, with or without the help of other
> thread participants, you are supposed to make such known by posting a
> closing message telling people that, and how, you have resolved the
> issue. Thanking everyone for their responses at the same time is not
> optional.

 
Reply With Quote
 
Silvio Bierman
Guest
Posts: n/a
 
      05-02-2012
On 05/02/2012 03:36 PM, bilsch wrote:
> I told people I had deleted the offending file - therefore I couldn't
> provide the error information. Deleting the file ended the problem -
> which I said. I've been posting in news groups since before you got out
> of grade school.
>


All your messages in the thread where responded to by others who did not
understand that the topic was closed. Arveds response to this particular
message contained a number of explicit questions to you that you have
rudely ignored.

I was out of grade school (in fact, close to graduating from university)
when NNTP was invented so that makes your claim unlikely.

Being inexperienced could have been considered an excuse for being rude.
Now you are just that.

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      05-02-2012
bilsch wrote:
> I wrote a loop that reads a text file (NVRAM.TXT) and stores it in a big
> character array and prints it out. It works fine. Just for the heck of
> it I tried to break it into two files: one that does the reading and the
> creation of the array, and another (with main) that prints out the first


Files don't do reading and printing.

Programs do.

> 10 characters of the array. It doesn't work. There's something wrong
> with how I reference the array in the main program. The two files are
> shown below, along with the error message that is generated. The
> statement causing the error is:
>
> System.out.print(bstr.nvchr[n]);
>
> Please tell me how to make it work (if possible). Here are the two files:
>
> public class NvrWork {
> public static void main(String[] args) {
> int n;
> BigString bstr = new BigString();


As Stefan told you, 'bstr' is a local variable. Look up "local variable". Its scope is limited to the 'main()' method of the 'NvrWork' class and is not accessible to another class. Look up "access" as it applies to Java variables, methods and members.

> for (n = 1; n < 10; n++) {
>
> System.out.print(bstr.nvchr[n]);


'nvchr' is not a member variable of the 'BigString' type, much less an accessible one.

Read the Java tutorials.

> }
> }
> }
>
> public class BigString {
>
> public BigString() {
> int fin = 1;
> int count = 1;
> try {
> FileInputStream file = new FileInputStream("NVRAM.TXT");


Don't do all the work in the constructor. The constructor should only construct, not perform the major work.

> char[] nvchr = new char [30000];
>
> while (fin != -1) {
> fin = file.read();
> nvchr[count] = (char) fin;
> //System.out.print(nvchr[count]);
> count++;
> }
> System.out.println("Bytes read : " + count);
> file.close();
> } catch (IOException e){
> System.out.println("Could not read file");
> }
>
> }
> }
>
> OUTPUT:
>
> run:
> Bytes read : 26017
> Exception in thread "main" java.lang.RuntimeException: Uncompilable
> source code - Erroneous tree type: <any>
> at NvrWork.main(NvrWork.java:9)
> Java Result: 1
> BUILD SUCCESSFUL (total time: 3 seconds)


You need to read the Java tutorials.

--
Lew

 
Reply With Quote
 
bilsch
Guest
Posts: n/a
 
      05-02-2012
On 05/02/2012 11:07 AM, Lew wrote:
> bilsch wrote:
>> I wrote a loop that reads a text file (NVRAM.TXT) and stores it in a big
>> character array and prints it out. It works fine. Just for the heck of
>> it I tried to break it into two files: one that does the reading and the
>> creation of the array, and another (with main) that prints out the first

>
> Files don't do reading and printing.
>
> Programs do.
>
>> 10 characters of the array. It doesn't work. There's something wrong
>> with how I reference the array in the main program. The two files are
>> shown below, along with the error message that is generated. The
>> statement causing the error is:
>>
>> System.out.print(bstr.nvchr[n]);
>>
>> Please tell me how to make it work (if possible). Here are the two files:
>>
>> public class NvrWork {
>> public static void main(String[] args) {
>> int n;
>> BigString bstr = new BigString();

>
> As Stefan told you, 'bstr' is a local variable. Look up "local variable". Its scope is limited to the 'main()' method of the 'NvrWork' class and is not accessible to another class. Look up "access" as it applies to Java variables, methods and members.
>
>> for (n = 1; n< 10; n++) {
>>
>> System.out.print(bstr.nvchr[n]);

>
> 'nvchr' is not a member variable of the 'BigString' type, much less an accessible one.
>
> Read the Java tutorials.
>
>> }
>> }
>> }
>>
>> public class BigString {
>>
>> public BigString() {
>> int fin = 1;
>> int count = 1;
>> try {
>> FileInputStream file = new FileInputStream("NVRAM.TXT");

>
> Don't do all the work in the constructor. The constructor should only construct, not perform the major work.
>
>> char[] nvchr = new char [30000];
>>
>> while (fin != -1) {
>> fin = file.read();
>> nvchr[count] = (char) fin;
>> //System.out.print(nvchr[count]);
>> count++;
>> }
>> System.out.println("Bytes read : " + count);
>> file.close();
>> } catch (IOException e){
>> System.out.println("Could not read file");
>> }
>>
>> }
>> }
>>
>> OUTPUT:
>>
>> run:
>> Bytes read : 26017
>> Exception in thread "main" java.lang.RuntimeException: Uncompilable
>> source code - Erroneous tree type:<any>
>> at NvrWork.main(NvrWork.java:9)
>> Java Result: 1
>> BUILD SUCCESSFUL (total time: 3 seconds)

>
> You need to read the Java tutorials.
>


Thank you. I'm not sure where the tutorials are. Do you have a link?

TIA. Bill S.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple question about CGI response after form data has beenprocessed. Ted Byers Perl Misc 2 10-09-2009 09:33 PM
Re: Simple Simple question!!! Kevin Spencer ASP .Net 0 06-25-2004 05:25 PM
Re: Simple Simple question!!! ashelley@inlandkwpp.com ASP .Net 0 06-25-2004 04:18 PM
dumb newbie question (or newbie dumb question) Jerry C. Perl Misc 8 11-23-2003 04:11 AM
A newbie has a lot of errors with a simple Circle program Sphenxes Java 2 09-25-2003 05:18 PM



Advertisments