Results 1 to 14 of 14
  1. #1
    zenitis's Avatar
    zenitis is offline Member
    Join Date
    May 2010
    Posts
    33
    Rep Power
    0

    Cool define object outside the function.

    Hello there. I ve stuck with the next problem. I have the class SimpleDriver which include 3 functions. These functions run every milisecond. I have also a class which reads files from txt. I want to read these files in SimpleDriver but outside the functions(as i want to read the files ones). How can i make oject of the the class read_file i have outside the functions in the simpleDriver?

  2. #2
    zenitis's Avatar
    zenitis is offline Member
    Join Date
    May 2010
    Posts
    33
    Rep Power
    0

    Default

    By saying functions I mean methods of the class.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default

    How can i make oject of the the class read_file i have outside the functions in the simpleDriver
    Define the variable that refers to the read_file object at the class level in the simpleDriver class. Ie outside of its methods.
    Java Code:
    class simpleDriver {
      read_file rdFile;  // reference to a read_file object
      void method1() {
      }
    }

  4. #4
    zenitis's Avatar
    zenitis is offline Member
    Join Date
    May 2010
    Posts
    33
    Rep Power
    0

    Default

    Ok i see what you mean. But also i want to initialize the object for example i will create an instance (read_file a;). And after that i want to open the file

    a.OpenfileRead("C/.../.../..txt"); // method in class read_file that open a txt
    a.rEaD(); // method that read a txt.

    I can only make an object how can initialize it outside the methods of the class SimpleDriver?

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default

    how can initialize it
    read_file rdFile = new read_file(); // define and assign it a value

  6. #6
    zenitis's Avatar
    zenitis is offline Member
    Join Date
    May 2010
    Posts
    33
    Rep Power
    0

    Default

    Yea if you use constructor of the class it doesnt work it said to me "identifier expected". Basically tou can make a contructor but when you will try to make an instance of method i said before rdFile.OpenFileRead("..."); i have this message.

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default

    Please post full text of error messages. Don't edit them.

  8. #8
    zenitis's Avatar
    zenitis is offline Member
    Join Date
    May 2010
    Posts
    33
    Rep Power
    0

    Default

    Ok you are right i m very clear with the problem.
    I have
    Java Code:
    class SimpleDriver{
    variables;
    public double [][] w=null; // i want to parse the txt file into a two dimensional array
    
    read_file rdFile = new read_file(); 
    rdFile.OpenReadFile("path");
    rdFile.ReaD();// read returns an array with the elements of the txt
    // so here i ve tried w=rdFile.ReaD();
    void methods(){
    }
    }
    the message is cannot find symbol w identifier expected.

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default

    message is
    Please copy and paste the FULL text of the message. Don't edit it.

  10. #10
    zenitis's Avatar
    zenitis is offline Member
    Join Date
    May 2010
    Posts
    33
    Rep Power
    0

    Default

    I didnt miss something, is exactly the message i have.

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default

    Only that one line? No source line number or program name?
    How are you compiling your programs?

  12. #12
    zenitis's Avatar
    zenitis is offline Member
    Join Date
    May 2010
    Posts
    33
    Rep Power
    0

    Default

    I compile my files in terminal. And i have problems with these lines
    rdFile.OpenReadFile("path");
    rdFile.ReaD();

  13. #13
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    4

    Default

    Again, post the exact error messages.

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default

    To copy contents of command prompt window in windows: Click on icon in upper left, select edit in menu, select all, again click icon, select edit and copy.

Similar Threads

  1. When to define object and when to use "new" only
    By Hossein in forum New To Java
    Replies: 7
    Last Post: 04-22-2010, 09:03 AM
  2. define a variable
    By jperson in forum New To Java
    Replies: 2
    Last Post: 01-29-2010, 02:33 AM
  3. Replies: 3
    Last Post: 12-04-2009, 03:08 PM
  4. Define this error.
    By jaicea in forum New To Java
    Replies: 3
    Last Post: 12-02-2009, 01:07 AM
  5. Passing a Vector object to a function
    By evapisces in forum New To Java
    Replies: 4
    Last Post: 09-27-2008, 03:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •