Newsgroup: it.comp.java
Titolo: AIUTO: problema col le eccezzioni

sto cercando di compilare questa classe (RIPORTATA PIù SOTTO) ma non ci
riesco, continuo ad avere questo errore:
*******************************************************
D:\java\ProgettoTesi\src\client>javac WebServiceConnector2.java
WebServiceConnector2.java:63: cannot resolve symbol
symbol  : variable outpw
location: class it.trim.java.webservices.WebServiceConnector2
                outpw.println(request);
                ^
WebServiceConnector2.java:64: cannot resolve symbol
symbol  : variable outpw
location: class it.trim.java.webservices.WebServiceConnector2
                outpw.close();
                ^
WebServiceConnector2.java:75: cannot resolve symbol
symbol  : variable inbr
location: class it.trim.java.webservices.WebServiceConnector2
                        while((inputLine = inbr.readLine()) != nul
                                           ^
WebServiceConnector2.java:82: cannot resolve symbol
symbol  : variable inbr
location: class it.trim.java.webservices.WebServiceConnector2
                        inbr.close();
                        ^
4 errors
******************************************************
package it.trim.java.webservices;
import java.net.*;
import java.io.*;
import java.util.*;
import org.jdom.*;
import it.trim.java.webservices.*;
public class WebServiceConnector2 {
 private Element profileElement;
 private Query query;
 private URL    WebURL;
 private String ResponseXMLContent;
 private HttpURLConnection conn;
 public WebServiceConnector2( String WebServiceURL ){
  Element profileElement = new Element("profile");
  profileElement.addContent(
     new Element("WebServiceURL").addContent(WebServiceURL) );
  try {
       WebURL = new URL( WebServiceURL );
  } catch (MalformedURLException e) {
       System.out.println("MalformedURLException");
  }
 }
 public WebServiceConnector2( String WebServiceURL, String username, String
password ){
  Element profileElement = new Element("profile");
  profileElement.addContent(
     new Element("WebServiceURL").addContent(WebServiceURL) );
  profileElement.addContent(
     new Element("username").addContent(username) );
  profileElement.addContent(
     new Element("password").addContent(password) );
  try {
       WebURL = new URL( WebServiceURL );
  } catch (MalformedURLException e) {
       System.out.println("MalformedURLException");
  }
 }
***********************IN QUESTO METODO SI PRESENTA
L'ERRORE************************
 private String postToURL(URL myURL, String request){
  try {
   conn = (HttpURLConnection) myURL.openConnection();
  } catch (MalformedURLException e) {
       System.out.println("MalformedURLException");
  } catch (IOException e) {
   System.out.println("IOException");
  }
  conn.setDoInput(true);
  conn.setDoOutput(true);
  conn.setUseCaches(false);
  try {
   conn.setRequestMethod("POST");
  } catch (ProtocolException e) {
       System.out.println("ProtocolException");
  }
  try {
   PrintWriter outpw = new PrintWriter(conn.getOutputStream());       /*
QUI GESTISCO LE ECCEZZIONI CHE MI CAUSANO PROBLEMI
  } catch (IOException e) {}
  outpw.println(request);
  outpw.close();
  try {
   BufferedReader inbr = new
BufferedReader(                                /*     QUI GESTISCO LE
ECCEZZIONI CHE MI CAUSANO PROBLEMI
    new InputStreamReader(
    conn.getInputStream()));
  } catch (IOException e) {
       System.out.println("IOException");
  }
  String inputLine;
  StringBuffer response = new StringBuffer();
  try {
   while((inputLine = inbr.readLine()) != null){
   response.append(inputLine + "\n");
   }
  } catch (IOException e) {
       System.out.println("IOException");
  }
  try {
       inbr.close();
      } catch (IOException e) {
       System.out.println("IOException");
  }
      return response.toString();
 }
****************************************************************************
****************************************
************************   HO PROVATO A NON GESTIRE (try..catch..) LE
IOException COME SOPRA E A LANCIARLE AI   ************************   METODI
CONNECT E REQUEST (QUI SOTTO ) DOVE LE GESTIVO E NON HO AVUTO NESSUN
PROBLEMA
************************   CHE SIGNIFICA?
****************************************************************************
*****************************************
public void connect(){
  String XMLRequest = XMLProcessor.createXML( profileElement );
   ResponseXMLContent = postToURL(WebURL,XMLRequest);
  System.out.println(ResponseXMLContent);
 }
 public void request(Query query){
  String XMLRequest = XMLProcessor.createXML( query.getElement() );
   ResponseXMLContent = postToURL(WebURL,XMLRequest);
  System.out.println(ResponseXMLContent);
 }
}

                         while((inputLine = inbr.readLine()) != nul
Ritengo che sia la stessa cosa.
Davide

Normale è solo un problema di visibilità della variabile, infatti la 
variabile outpw la dichiari nel blocco try e la usi nel blocco catch due 
blocchi separati. Sposta la dichiarazione prima del try e vedi che tutto 
funziona


 *****************************************
qualcosa di piu' leggibile senza tutti questi asterischi no eh?
cmq zio e zia si scrivono con una zeta.... ecceZione :)
Kali

grazie mille a tutti!!