1

I'm looking at this tutorial about BufferedReader at youtube

https://www.youtube.com/watch?v=yofFVbARIRU

I write the code exactly as he does but I can't get it to work. I cant get the BufferedReader code to work even though I imported it with

import java.io.*;

InputStreamReader stream = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader (stream);

I solved it with this code:

InputStreamReader stream = new InputStreamReader(System.in);
java.io.BufferedReader reader = new java.io.BufferedReader (stream);

And this works as well:

java.io.BufferedReader reader = 
new java.io.BufferedReader (new InputStreamReader(System.in));

Could someone explain to me what's wrong in the first code? Because it works for him who's giving the tutorial

Tapani Yrjölä
  • 168
  • 1
  • 4
  • 15

1 Answers1

1

You've likely got your own class that you've named BufferedReader and whose name is clashing with the core class and thus confusing the Java compiler. Rename it!

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • That's it! I always seem te be stuck with small problems that I have difficulties to find. Is there any problem solving check list that programmers like to use? – Tapani Yrjölä Mar 09 '15 at 03:48
  • @TapaniYrjölä: experience and writing lots and lots and lots of code. And then writing more code. – Hovercraft Full Of Eels Mar 09 '15 at 03:49
  • Sometimes I can be stuck with code for 2 days and it drives me crazy. Always when I solve it it's something really easy and small thing I need to change. Is this common in programming? – Tapani Yrjölä Mar 09 '15 at 03:53
  • 2
    @TapaniYrjölä the trick is not to find a checklist (any such list will always be missing the problem you run into ;) ), but instead to design your code such that small parts can be tested in isolation. In this case, you tried copying the tutorial's code, but had some of your own code mixed in. The first thing to do in that case is copy their code *exactly*, then slowly reintroduce your changes until something breaks. Then you've found your problem. – dimo414 Mar 09 '15 at 12:45
  • 1
    Amen to what @dimo414 says -- reduce cyclomatic complexity! – Hovercraft Full Of Eels Mar 09 '15 at 16:31