Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #14128 > unrolled thread
| Started by | bilsch <king621@comcast.net> |
|---|---|
| First post | 2012-05-02 05:10 -0700 |
| Last post | 2012-05-02 14:21 -0700 |
| Articles | 10 — 3 participants |
Back to article view | Back to comp.lang.java.programmer
Newbie has simple question bilsch <king621@comcast.net> - 2012-05-02 05:10 -0700
Re: Newbie has simple question bilsch <king621@comcast.net> - 2012-05-02 05:39 -0700
Re: Newbie has simple question Silvio Bierman <silvio@moc.com> - 2012-05-02 14:43 +0200
Re: Newbie has simple question bilsch <king621@comcast.net> - 2012-05-02 05:57 -0700
Re: Newbie has simple question Silvio Bierman <silvio@moc.com> - 2012-05-02 15:07 +0200
Re: Newbie has simple question bilsch <king621@comcast.net> - 2012-05-02 06:36 -0700
Re: Newbie has simple question Silvio Bierman <silvio@moc.com> - 2012-05-02 16:43 +0200
Re: Newbie has simple question Lew <lewbloch@gmail.com> - 2012-05-02 11:07 -0700
Re: Newbie has simple question bilsch <king621@comcast.net> - 2012-05-02 12:57 -0700
Re: Newbie has simple question Lew <lewbloch@gmail.com> - 2012-05-02 14:21 -0700
| From | bilsch <king621@comcast.net> |
|---|---|
| Date | 2012-05-02 05:10 -0700 |
| Subject | Newbie has simple question |
| Message-ID | <jnr88b$q5s$1@dont-email.me> |
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.
[toc] | [next] | [standalone]
| From | bilsch <king621@comcast.net> |
|---|---|
| Date | 2012-05-02 05:39 -0700 |
| Message-ID | <jnr9u1$4co$1@dont-email.me> |
| In reply to | #14128 |
On 05/02/2012 05:22 AM, Stefan Ram wrote: > bilsch<king621@comcast.net> 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?
[toc] | [prev] | [next] | [standalone]
| From | Silvio Bierman <silvio@moc.com> |
|---|---|
| Date | 2012-05-02 14:43 +0200 |
| Message-ID | <4fa12beb$0$6841$e4fe514c@news2.news.xs4all.nl> |
| In reply to | #14128 |
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
[toc] | [prev] | [next] | [standalone]
| From | bilsch <king621@comcast.net> |
|---|---|
| Date | 2012-05-02 05:57 -0700 |
| Message-ID | <jnrb0e$air$1@dont-email.me> |
| In reply to | #14131 |
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
[toc] | [prev] | [next] | [standalone]
| From | Silvio Bierman <silvio@moc.com> |
|---|---|
| Date | 2012-05-02 15:07 +0200 |
| Message-ID | <4fa131ab$0$6882$e4fe514c@news2.news.xs4all.nl> |
| In reply to | #14132 |
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.
[toc] | [prev] | [next] | [standalone]
| From | bilsch <king621@comcast.net> |
|---|---|
| Date | 2012-05-02 06:36 -0700 |
| Message-ID | <jnrd8p$oad$1@dont-email.me> |
| In reply to | #14133 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Silvio Bierman <silvio@moc.com> |
|---|---|
| Date | 2012-05-02 16:43 +0200 |
| Message-ID | <4fa14828$0$6962$e4fe514c@news2.news.xs4all.nl> |
| In reply to | #14134 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2012-05-02 11:07 -0700 |
| Message-ID | <11204977.1258.1335982056272.JavaMail.geo-discussion-forums@pbgg10> |
| In reply to | #14128 |
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
[toc] | [prev] | [next] | [standalone]
| From | bilsch <king621@comcast.net> |
|---|---|
| Date | 2012-05-02 12:57 -0700 |
| Message-ID | <jns3jg$br6$1@dont-email.me> |
| In reply to | #14139 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2012-05-02 14:21 -0700 |
| Message-ID | <1976208.1374.1335993715853.JavaMail.geo-discussion-forums@pbsp7> |
| In reply to | #14144 |
bilsch wrote: > Lew wrote: >> You need to read the Java tutorials. >> > > Thank you. I'm not sure where the tutorials are. Do you have a link? <http://lmgtfy.com/?q=Java+tutorials> -- Lew
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web