-1

I tried to collect the data from a socket. For that, I coded :

  InputStream i = socket.getInputStream();
  InputStreamReader rawAnswer= InputStreamReader(i);  

But an error occured ( I use Eclipse as an IDE ) : " The method InputStreamReader(InputStream) is undefined". However, the documentation says that the constructor exists. I then tried to create an InputStreamReader from a FileInputStream and it worked perfectly. Am I missing anything ?

  • 1
    This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting. – Naman Dec 28 '18 at 17:53
  • You need to use `new` to call a constructor. – Peter Lawrey Dec 28 '18 at 18:04

1 Answers1

1

new!

InputStreamReader rawAnswer= new InputStreamReader(i);  
                          // ^^^

Otherwise you are just trying to call a method that unusually has an initial cap.

Another common mistake is to attempt to declare a constructor but add a void return type, thus creating a method with an initial cap. (Funnily enough, in byte code constructors do have void return types but are called <init>.)

Tom Hawtin - tackline
  • 145,806
  • 30
  • 211
  • 305