This has been the cause of a royal lot of frustration.
I have two threads and a pipe between them. I want the first thread to send stdout to the second, and a pipe seemed like a convenient way to do this.

public PipedOutputStream p_stdout = new PipedOutputStream();
public PrintStream ps_stdout = new PrintStream(p_stdout, true);
System.setOut(ps_stdout);

(I've made the appropriate imports, obviously.)
The compiler (Sun Java 1.6.0.14) hates that third line.

Javadocs:
System.setOut
PipedOutputStream
PrintStream

NetBeans complains in the following manner:

cannot find symbol
  symbol: class setOut
  location: class java.lang.System

<identifier> expected

cannot find symbol
  symbol: class ps_stdout
  location: class [my project name]

<identifier> expected

Every example I've seen online uses an instantiation of PrintStream, not a class that extends it.
What gives?

Thanks in advance,
-cvp

Too abstract. Make zip appendix of netbeans project and post it.
"The devil is in the details"

I pasted your 3 lines of code into a main(...) method in Eclipse. It required me to remove the "public modifiers, then compiled OK. Also runs without throwing any exceptions. Java 1.6.0.14
Looks like something in the context where your code is placed. "Public" is wrong in a method, "System.setOut" is wrong outside a method... Post enough code to get the context as well.

I pasted your 3 lines of code into a main(...) method in Eclipse. It required me to remove the "public modifiers, then compiled OK. Also runs without throwing any exceptions. Java 1.6.0.14
Looks like something in the context where your code is placed. "Public" is wrong in a method, "System.setOut" is wrong outside a method... Post enough code to get the context as well.

That was exactly it. I placed that line in the same region where I was declaring class variables, outside of any method definitions. I put it in the constructor, and it worked.
I feel dumb, but relieved.

Thanks!
-cvp

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.