Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #14139

Re: Newbie has simple question

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Newbie has simple question
Date Wed, 2 May 2012 11:07:35 -0700 (PDT)
Organization http://groups.google.com
Lines 80
Message-ID <11204977.1258.1335982056272.JavaMail.geo-discussion-forums@pbgg10> (permalink)
References <jnr88b$q5s$1@dont-email.me>
NNTP-Posting-Host 69.28.149.29
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
X-Trace posting.google.com 1335982136 8734 127.0.0.1 (2 May 2012 18:08:56 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Wed, 2 May 2012 18:08:56 +0000 (UTC)
In-Reply-To <jnr88b$q5s$1@dont-email.me>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=69.28.149.29; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T
User-Agent G2/1.0
X-Received-Bytes 3480
Xref csiph.com comp.lang.java.programmer:14139

Show key headers only | View raw


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

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web