-5
    public static void main(String[] args) throws IOException {
    URL urla = new URL("http://translate.google.ru/translate_a/t?client=t&hl=ru&sl=en&tl=ru&ie=UTF-8&oe=UTF-8&multires=1&ssel=0&tsel=0&sc=1&q=Yet%20Another%20App");
    HttpURLConnection conn = (HttpURLConnection) urla.openConnection();

     conn.setRequestProperty("User-Agent", "Translator");
     conn.connect();
     int code=conn.getResponseCode();
     if (code==200) {
         BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));



       if ( in.readLine() != null) {
             result.append(in.readLine());
         }

         in.close();
         conn.disconnect();
         conn=null;
     }
     texto = result;
}
Exception in thread "main" java.lang.NullPointerException
at Main.main(Main.java:25)
Строка 25 (где ошибка)- result.append(in.readLine());

Почему говорит что null, ведь if говорит, что код с нулом не должен исполняться

2 ответа 2

0
String frame;
while ((frame=in.readline)!=null)
  result.append(in.readLine());

in.close();
conn.disconnect();
conn=null;
3
  • Ошибка та же осталась
    – kandi
    4 мая 2013 в 11:03
  • а массив result инициализирован?
    – G1yyK
    4 мая 2013 в 11:17
  • невнимательно прочитал вопрос. ругалось ведь на result, что он не про инициализирован.
    – G1yyK
    4 мая 2013 в 11:18
0

Решил выносом объявления StringBuffer -а в заметодье

static StringBuffer result = new StringBuffer("");
public static void main(String[] args) throws IOException {

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.