The Artima Developer Community
Sponsored Link

Java Answers Forum
'cannot resolve symbol' - why?

8 replies on 1 page. Most recent reply: Apr 7, 2004 10:57 PM by Sandu Crasteti

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 8 replies on 1 page
Sandu Crasteti

Posts: 13
Nickname: xan
Registered: Feb, 2003

'cannot resolve symbol' - why? Posted: Apr 7, 2004 3:24 AM
Reply to this message Reply
Advertisement
Hello!

For some testing purposes I made an attempt to extend class java.io.PrintStream. But javac 'sent' me this:


B.java:4: cannot resolve symbol
symbol : constructor PrintStream ()
location: class java.io.PrintStream
class B extends PrintStream{
^
1 error


Can somebody help me understand what might cause the error?

Best regards,
Sandu


twc

Posts: 129
Nickname: twc
Registered: Feb, 2004

Re: 'cannot resolve symbol' - why? Posted: Apr 7, 2004 4:54 AM
Reply to this message Reply
> For some testing purposes I made an attempt to extend
> class java.io.PrintStream. But javac 'sent' me this:
>
>

> B.java:4: cannot resolve symbol
> symbol : constructor PrintStream ()
> location: class java.io.PrintStream
> class B extends PrintStream{
> ^
> 1 error
>

>
> Can somebody help me understand what might cause the
> error?

It would be easier to answer this if you had shared the affected code. The error is saying that you are using a name that it does not understand. That could be caused by many different errors from misspelling to trying to use a variable that you haven't declared.

In this case, I suspect that your problem is closer to the latter problem. If you look at the error that you posted, it does not show an argument for the PrintStream constructor. However, all three of the constructors for that class require at least one argument. You are apparently trying to call a constructor that does not exist, which is why the compiler does not recognize it.

I hope this helps.
twc

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: 'cannot resolve symbol' - why? Posted: Apr 7, 2004 6:02 AM
Reply to this message Reply
If you don't call
super(...);
as the first argument in your constructor, javac creates the call
super();

If you don't even hava a constructor in the clas B, the constructor
public B () {
super();
}
will be created.


In this case, the call results in a compiler error, because the constructor PrintStream() does not exist.

Sandu Crasteti

Posts: 13
Nickname: xan
Registered: Feb, 2003

Re: 'cannot resolve symbol' - why? Posted: Apr 7, 2004 6:10 AM
Reply to this message Reply
> However, all three of the constructors for
> that class require at least one argument. You are
> apparently trying to call a constructor that does not
> exist, which is why the compiler does not recognize it.
>
> I hope this helps.
> twc


My intention was to extend PrintStream so that the new class would be ‘PrintStream + some additional variables’:

import java.io // should not be mandatory

class B extends PrintStream{
// int i, j, ...;
}

Considering the fact that the class does not have any constructor without arguments, how should I try to extend it? So far, the only way I know to extend a class is:


‘class MyClass extends BaseClass{ ... }’


without any mention about one constructor or another.

Sandu

Sandu Crasteti

Posts: 13
Nickname: xan
Registered: Feb, 2003

Re: 'cannot resolve symbol' - why? Posted: Apr 7, 2004 6:55 AM
Reply to this message Reply
I knew that a class always has a constructor without arguments, even if it is the empty (default) one.
Is it possible to completely ‘eliminate’ this constructor, keeping only one (or more) with arguments, or what I knew in the first place was wrong?

Sandu

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: 'cannot resolve symbol' - why? Posted: Apr 7, 2004 7:30 AM
Reply to this message Reply
If you want class B to exdend class A completely, you must create a constructor in B for every constructor in class A.

exp:

class A has the folliwing constructors:
class A {
public A () {}
public A (String s) {}
public A (int i, String s) {}
}
If you want to use all possibilities of A, then you must create this constructors for class B
class B extends A {
public A () {
super();
//do something useful
}
public A (String s) {
super(s);
//do something useful
}
public A (int i, String s) {
super (i, s);
//do something useful
}
//additional methods and attributes
}

Sandu Crasteti

Posts: 13
Nickname: xan
Registered: Feb, 2003

Re: 'cannot resolve symbol' - why? Posted: Apr 7, 2004 7:58 AM
Reply to this message Reply
It works -Thank you!

Sandu

twc

Posts: 129
Nickname: twc
Registered: Feb, 2004

Re: 'cannot resolve symbol' - why? Posted: Apr 7, 2004 11:15 AM
Reply to this message Reply
> I knew that a class always has a constructor without
> arguments, even if it is the empty (default) one.

No, this is not true all of the time.

If you do not create any constructors, then the compiler will create a no-argument constructor that only calls the no-argument constructor of the superclass. If you do not specify a superclass, then Object becomes the superclass.

But if you create any constructors, then the compiler does not create one for you.

If you fail to call a constructor of your superclass, then the compiler will call a no-argument constructor. This might be what your problem is. You need to explicitly call one of the constructors of the PrintStream class, and all of those require at least one argument.

> Is it possible to completely ‘eliminate’ this constructor,
> keeping only one (or more) with arguments, or what I knew
> in the first place was wrong?

Obviously, you are NOT required to have a no-argument constructor. Your superclass does not have one. I see no reason to create one.

Sandu Crasteti

Posts: 13
Nickname: xan
Registered: Feb, 2003

Re: 'cannot resolve symbol' - why? Posted: Apr 7, 2004 10:57 PM
Reply to this message Reply
Thank you, twc!

Flat View: This topic has 8 replies on 1 page
Topic: trapping images Previous Topic   Next Topic Topic: Exception in rmi based chat

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use