Passing objects (not stones)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NotAsDumbAsILook

    Passing objects (not stones)

    I'm using NetBeans 3.5.1. Why doesn't this work?


    Referenced class:

    public class MyClass {

    ...
    ...

    // All sorts of methods in here that work

    ...
    ...


    public Object objectForValue( int i) {
    // test code
    Object o = "objectForValue ";
    return o;
    }
    }

    Here's where the error is:

    public class MyOtherClass {

    ...
    ...

    // All sorts of methods in here that work

    ...
    ...

    public Object getObjectTest(i nt i) {
    // test code
    MyClass mine = new MyClass();
    Object o = mine.objectForV alue(i); <<== ERROR
    return o;
    }

    }

    The error I get is:

    myTestModel.jav a [40:1] cannot resolve symbol
    symbol : method objectForValue (int)
    location: class MPNode
    Object o = mine.objectForV alue(i);


    I intially just had the getObjectTest method as:

    public Object getObjectTest(i nt i) {
    MyClass mine = new MyClass();
    return mine.objectForV alue(i);
    }

    but that didn't work either. It gave the same error.

    Apparently there is something about the Object class that I don't
    understand. Could someone enlighten me?
  • Ryan Stewart

    #2
    Re: Passing objects (not stones)

    "NotAsDumbAsILo ok" <toyota_trekker @yahoo.com> wrote in message
    news:e3d370c6.0 402251210.1e521 5b3@posting.goo gle.com...[color=blue]
    > I'm using NetBeans 3.5.1. Why doesn't this work?
    >
    >
    > Referenced class:
    >
    > public class MyClass {
    > public Object objectForValue( int i) {
    > // test code
    > Object o = "objectForValue ";
    > return o;
    > }
    > }
    >
    > Here's where the error is:
    >
    > public class MyOtherClass {
    > public Object getObjectTest(i nt i) {
    > // test code
    > MyClass mine = new MyClass();
    > Object o = mine.objectForV alue(i); <<== ERROR
    > return o;
    > }
    > }
    >
    > The error I get is:
    >
    > myTestModel.jav a [40:1] cannot resolve symbol
    > symbol : method objectForValue (int)
    > location: class MPNode
    > Object o = mine.objectForV alue(i);
    >
    >
    > I intially just had the getObjectTest method as:
    >
    > public Object getObjectTest(i nt i) {
    > MyClass mine = new MyClass();
    > return mine.objectForV alue(i);
    > }
    >
    > but that didn't work either. It gave the same error.
    >
    > Apparently there is something about the Object class that I don't
    > understand. Could someone enlighten me?[/color]

    Unless I'm missing something, that code is fine. But you haven't posted code
    that demonstrates your problem. See for suggestions:


    Then post some actual executable code.


    Comment

    • hiwa

      #3
      Re: Passing objects (not stones)

      toyota_trekker@ yahoo.com (NotAsDumbAsILo ok) wrote in message news:<e3d370c6. 0402251210.1e52 15b3@posting.go ogle.com>...[color=blue]
      > I'm using NetBeans 3.5.1. Why doesn't this work?
      >
      >
      > Referenced class:
      >
      > public class MyClass {
      >
      > ...
      > ...
      >
      > // All sorts of methods in here that work
      >
      > ...
      > ...
      >
      >
      > public Object objectForValue( int i) {
      > // test code
      > Object o = "objectForValue ";
      > return o;
      > }
      > }
      >
      > Here's where the error is:
      >
      > public class MyOtherClass {
      >
      > ...
      > ...
      >
      > // All sorts of methods in here that work
      >
      > ...
      > ...
      >
      > public Object getObjectTest(i nt i) {
      > // test code
      > MyClass mine = new MyClass();
      > Object o = mine.objectForV alue(i); <<== ERROR
      > return o;
      > }
      >
      > }
      >
      > The error I get is:
      >
      > myTestModel.jav a [40:1] cannot resolve symbol
      > symbol : method objectForValue (int)
      > location: class MPNode
      > Object o = mine.objectForV alue(i);
      >
      >
      > I intially just had the getObjectTest method as:
      >
      > public Object getObjectTest(i nt i) {
      > MyClass mine = new MyClass();
      > return mine.objectForV alue(i);
      > }
      >
      > but that didn't work either. It gave the same error.
      >
      > Apparently there is something about the Object class that I don't
      > understand. Could someone enlighten me?[/color]

      Wha, wha, wha, what is class MPNode? Isn't it the real problem?

      Comment

      • NotAsDumbAsILook

        #4
        Re: Passing objects (not stones)

        toyota_trekker@ yahoo.com (NotAsDumbAsILo ok) wrote in message news:<e3d370c6. 0402251210.1e52 15b3@posting.go ogle.com>...[color=blue]
        >
        > The error I get is:
        >
        > myTestModel.jav a [40:1] cannot resolve symbol
        > symbol : method objectForValue (int)
        > location: class MPNode
        > Object o = mine.objectForV alue(i);
        >
        >[/color]


        Oops! I was "simplifyin g" the code I posted and didn't rename that
        MPNode as MyClass. That might be a little confusing.

        Anyhoo, I figured out what the problem was, but I don't understand why
        it was a problem. So, I'm going to alter the question.

        Like I said before, I'm using NetBeans 3.5.1. I was putting together a
        little sample application so that I could figure out how to make a
        good TableClass while working with an ArrayList of Objects. Well, in
        order to save time coding, I copied over the class MyClass from
        another project I am working on using the NetBeans Filesystem Explorer
        (you right-click, copy, and then paste-as-copy in the new Filesystem).
        Apparently there is something in the background that was giving
        NetBeans grief. I could declare a new MyClass() object, and then use
        the Code Completion to see the methods and variables in it. But, when
        it came to compile time, the compiler couldn't see those methods, so
        it was giving the "cannot resolve symbol" error.

        I vaguely remembered seeing a similar problem with Delphi a few years
        ago, and I tried a similar fix I used then. I created a new class
        inside of the Filesystem I was working in - by doing a right-click,
        new, java class. Then I cut and pasted the code from the original
        MyClass into this new one, and referenced it instead of the old
        MyClass object. Now the code complies just fine.

        So, the error lies in copying a class from one filesystem into
        another. I know that you normally wouldn't do that, but there is the
        rare occasion where you would. Any thoughts?

        Comment

        • Ryan Stewart

          #5
          Re: Passing objects (not stones)

          "NotAsDumbAsILo ok" <toyota_trekker @yahoo.com> wrote in message
          news:e3d370c6.0 402260942.73c2e 895@posting.goo gle.com...[color=blue]
          > Oops! I was "simplifyin g" the code I posted and didn't rename that
          > MPNode as MyClass. That might be a little confusing.
          >
          > Anyhoo, I figured out what the problem was, but I don't understand why
          > it was a problem. So, I'm going to alter the question.
          >
          > Like I said before, I'm using NetBeans 3.5.1. I was putting together a
          > little sample application so that I could figure out how to make a
          > good TableClass while working with an ArrayList of Objects. Well, in
          > order to save time coding, I copied over the class MyClass from
          > another project I am working on using the NetBeans Filesystem Explorer
          > (you right-click, copy, and then paste-as-copy in the new Filesystem).
          > Apparently there is something in the background that was giving
          > NetBeans grief. I could declare a new MyClass() object, and then use
          > the Code Completion to see the methods and variables in it. But, when
          > it came to compile time, the compiler couldn't see those methods, so
          > it was giving the "cannot resolve symbol" error.
          >
          > I vaguely remembered seeing a similar problem with Delphi a few years
          > ago, and I tried a similar fix I used then. I created a new class
          > inside of the Filesystem I was working in - by doing a right-click,
          > new, java class. Then I cut and pasted the code from the original
          > MyClass into this new one, and referenced it instead of the old
          > MyClass object. Now the code complies just fine.
          >
          > So, the error lies in copying a class from one filesystem into
          > another. I know that you normally wouldn't do that, but there is the
          > rare occasion where you would. Any thoughts?[/color]
          It depends on what exactly you're doing. If you're pasting into a
          subdirectory of a mounted directory, your file is not in the classpath. It's
          considered part of a Java package. Therefore you must have a package
          statement in the source file and import the package in order to use class.


          Comment

          Working...