Malformed URL

ยอดดู 72 ครั้ง
ข้ามไปที่ข้อความที่ยังไม่อ่านรายการแรก

D L H

ยังไม่อ่าน,
23 ก.ค. 2551 09:29:1523/7/51
ถึง Google Web Toolkit
first a little disclaimer: i'm pretty much a newbie when it comes to
gwt and java and ajax.

alright. well, i wanted to create a bit of server-side code to do a
bit of text rendering. so after a bit of work with tutorials and stuff
i came up with this file called TextRenderingServiceImpl.java. while
writing this class, i had a sudden urge to create a new url object, so
i imported java.net.URL.

import java.net.URL;

i then tried to instantiate and initialize a url (within a method)
with the following code:

URL url = new URL("http://www.proprintsgear.com/");

every time i compile this thing with javac, however, it gives me a
MalformedURLException. doesn't matter what i put in there; i've tried
pasting sample url code from various online sources - nothing. here is
the exact error:

TextRenderingServiceImpl.java:15: unreported exception
java.net.MalformedURLException; must be caught or declared to be
thrown
URL url = new URL("http://www.proprintsgear.com/");

i'm not really familiar with compiling in java, so i might be doing
something wrong there. however, i'm pretty sure its not a class path
problem or anything like that.

-DLH

MN

ยังไม่อ่าน,
24 ก.ค. 2551 04:44:3424/7/51
ถึง Google Web Toolkit
you need to read more in java basics about exception handling.
http://java.sun.com/docs/books/tutorial/essential/exceptions/


in short: if a object has declared, that he can throw an expection,
then you have to declare what you will do with this.

solutions:
1) catch it with a try/catch block
2) dont handle the exception directly and let the exception bubble up.
declare that your method can throw this exception with the keyword
"throws [exception name]"


look here for some examples at www.java2s.com
http://www.google.com/custom?q=new+URL&sa=Search+Java&cof=S%3Ahttp%3A%2F%2Fwww.java2s.com&domains=www.java2s.com%2FCode%2FJava%2F&sitesearch=www.java2s.com%2FCode%2FJava%2F

MN

ยังไม่อ่าน,
24 ก.ค. 2551 04:47:1724/7/51
ถึง Google Web Toolkit
next time please use google like this:
http://www.google.com/search?q=unreported+exception+java.net.MalformedURLException


On 24 Jul., 10:44, MN <nietz...@gmail.com> wrote:
> you need to read more in java basics about exception handling.http://java.sun.com/docs/books/tutorial/essential/exceptions/
>
> in short: if a object has declared, that he can throw an expection,
> then you have to declare what you will do with this.
>
> solutions:
> 1) catch it with a try/catch block
> 2) dont handle the exception directly and let the exception bubble up.
> declare that your method can throw this exception with the keyword
> "throws [exception name]"
>
> look here for some examples atwww.java2s.comhttp://www.google.com/custom?q=new+URL&sa=Search+Java&cof=S%3Ahttp%3A...

D L H

ยังไม่อ่าน,
24 ก.ค. 2551 09:24:0424/7/51
ถึง Google Web Toolkit
well that's great, but i don't really want the exception to be thrown
in the first place. i had been using a try/catch, but i had a problem
later in the code because my url had not been properly initialized.

On Jul 24, 4:44 am, MN <nietz...@gmail.com> wrote:
> you need to read more in java basics about exception handling.http://java.sun.com/docs/books/tutorial/essential/exceptions/
>
> in short: if a object has declared, that he can throw an expection,
> then you have to declare what you will do with this.
>
> solutions:
> 1) catch it with a try/catch block
> 2) dont handle the exception directly and let the exception bubble up.
> declare that your method can throw this exception with the keyword
> "throws [exception name]"
>
> look here for some examples atwww.java2s.comhttp://www.google.com/custom?q=new+URL&sa=Search+Java&cof=S%3Ahttp%3A...

Jason Essington

ยังไม่อ่าน,
24 ก.ค. 2551 13:29:5424/7/51
ถึง Google-We...@googlegroups.com
right, if some class or class method has the possibility of throwing
an exception, then you must either deal with that possibility or
declare that someone else should handle it.

In your case, you are using a static string in your URL constructor (a
bit naughty, but we'll skip that discussion), so you are unlikely to
see the exception, but that doesn't trump the fact that the exception
could be thrown.

try something like:

URL url = null;
try {


url = new URL("http://www.proprintsgear.com/");
}

catch (MalformedURLException e) {
// unlikely to happen with the given URL
System.out.println("this should not have happened!");
// this is naughty too
}

if (url == null) {
//ruhrho raggy!
}


-jason

D L H

ยังไม่อ่าน,
24 ก.ค. 2551 13:55:4124/7/51
ถึง Google Web Toolkit
ok, well i will probably write in some kind of exception handling, but
right now i just want to find out why my url was "malformed"
> >> look here for some examples atwww.java2s.comhttp://www.google.com/custom?q=new+URL&sa=Search+Java&c...

MN

ยังไม่อ่าน,
25 ก.ค. 2551 04:59:1825/7/51
ถึง Google Web Toolkit
<quote>
here is the exact error:

TextRenderingServiceImpl.java:15: unreported exception
java.net.MalformedURLException; must be caught or declared to be
thrown
</quote>
this error do NOT say that you url IS malformed, it says only that the
Class URL can MAYBE throw a exception IF sometime the url is
malformed. (instead of a string you can use also a variable with
different urls and so you have to deal with the possible error.


TODO:

please implement the try/catch block and then run your code and then
post the exact error with stacktrace.

walden

ยังไม่อ่าน,
25 ก.ค. 2551 08:02:2125/7/51
ถึง Google Web Toolkit
Ja,

In other words, it's a compile time error, not a runtime error. Don't
argue with the compiler, just make her happy.

Walden
> > > >>> -DLH- Hide quoted text -
>
> - Show quoted text -

Jason Essington

ยังไม่อ่าน,
25 ก.ค. 2551 12:54:0925/7/51
ถึง Google-We...@googlegroups.com
The error wasn't saying that you had a malformed URL, it was saying
that the constructor had the possibility of throwing that particular
type of exception.

All you need to do is handle that exception, and the compiler will
stop whining.

-jason

D L H

ยังไม่อ่าน,
28 ก.ค. 2551 08:21:2828/7/51
ถึง Google Web Toolkit
ok i added this code...

try {
URL url = new URL("http://www.proprintsgear.com/");
} catch (MalformedURLException e) {
}

...and got this error...

TextRenderingServiceImpl.java:20: cannot find symbol
symbol : variable url
location: class com.designLab.server.TextRenderingServiceImpl
img = ImageIO.read(url);

so i'm assuming it threw the exception, executed the empty catch
block, and as a result did not have a url to pass into
ImageIO.read(url).

where do i go from here?


On Jul 25, 12:54 pm, Jason Essington <jason.essing...@gmail.com>

walden

ยังไม่อ่าน,
29 ก.ค. 2551 07:10:4229/7/51
ถึง Google Web Toolkit
You go straight to Java programming bootcamp, where they teach you to
declare variables. Off you go, now.

MN

ยังไม่อ่าน,
29 ก.ค. 2551 07:28:4729/7/51
ถึง Google Web Toolkit
for this type of errors please use google to find a solution it is not
GWT specific:
http://www.google.com/search?q=cannot+find+symbol+symbol+variable

i suggest you also this search:
http://www.google.com/search?q=java+tutorial

D L H

ยังไม่อ่าน,
29 ก.ค. 2551 08:47:1329/7/51
ถึง Google Web Toolkit
so in other words, you have no idea what's wrong with my url variable
declaration, so i need to just keep googling. well i posted on here
because the stuff i was finding on google wasn't helping (including
the tutorials at java.sun.com), but i guess i'll just keep trying.
thanks and goodbye.

Isaac Truett

ยังไม่อ่าน,
29 ก.ค. 2551 08:59:1929/7/51
ถึง Google-We...@googlegroups.com
You're declaring a variable and then referencing it out of scope.

The point that Walden and MN were trying to convey is that you have a
fundamental programming error, not a GWT problem. Google Search can
turn up a number of useful tutorials on Java programming. If you're
having trouble finding one that suits you then perhaps searching
specifically for [Java variable scope] or [Java exception handling]
would be more fruitful. You might also consider buying a book on Java
programming if that's more your learning style.

MN

ยังไม่อ่าน,
29 ก.ค. 2551 09:29:4229/7/51
ถึง Google Web Toolkit

D L H

ยังไม่อ่าน,
29 ก.ค. 2551 09:44:5229/7/51
ถึง Google Web Toolkit
alright well i just experimented and played around with it, and i
finally got it to compile.

URL url = null;
BufferedImage img = null;
try {
url = new URL("http://localhost/proprintsonline/favicon/
favicon.png");
img = ImageIO.read(url);
} catch (MalformedURLException e) {
} catch(IOException e) {
}

not sure if this is correct or conventional or preferable or anything
like that.

On Jul 29, 9:29 am, MN <nietz...@gmail.com> wrote:
> http://groups.google.de/group/comp.lang.java.helphttp://groups.google.de/group/comp.lang.java.programmer

Isaac Truett

ยังไม่อ่าน,
29 ก.ค. 2551 09:48:4329/7/51
ถึง Google-We...@googlegroups.com
For the benefit of every programmer who comes after you I would ask
you to please never, ever, leave a catch block empty. At least log the
exception stack trace.

D L H

ยังไม่อ่าน,
29 ก.ค. 2551 10:19:2029/7/51
ถึง Google Web Toolkit
if i print the stack trace, where does the output show up? does it
show up in the gwt dev shell?

On Jul 29, 9:48 am, "Isaac Truett" <itru...@gmail.com> wrote:
> For the benefit of every programmer who comes after you I would ask
> you to please never, ever, leave a catch block empty. At least log the
> exception stack trace.
>
> On Tue, Jul 29, 2008 at 9:44 AM, D L H <THEd2...@gmail.com> wrote:
>
>
>
> > alright well i just experimented and played around with it, and i
> > finally got it to compile.
>
> > URL url = null;
> > BufferedImage img = null;
> > try {
> >   url = new URL("http://localhost/proprintsonline/favicon/
> > favicon.png");
> >   img = ImageIO.read(url);
> > } catch (MalformedURLException e) {
> > } catch(IOException e) {
> > }
>
> > not sure if this is correct or conventional or preferable or anything
> > like that.
>
> > On Jul 29, 9:29 am, MN <nietz...@gmail.com> wrote:
> >>http://groups.google.de/group/comp.lang.java.helphttp://groups.google...

Isaac Truett

ยังไม่อ่าน,
29 ก.ค. 2551 10:32:2529/7/51
ถึง Google-We...@googlegroups.com
If you print from client code, yes. In web mode client-side print
statements are removed during compilation because they have nowhere to
go in the browser. Server-side printing to standard output will go
wherever your server redirects such things; usually to a log file.

D L H

ยังไม่อ่าน,
29 ก.ค. 2551 12:37:2329/7/51
ถึง Google Web Toolkit
how do i access the server log? i looked through the tomcat directory,
but i didn't find any log files.

On Jul 29, 10:32 am, "Isaac Truett" <itru...@gmail.com> wrote:
> If you print from client code, yes. In web mode client-side print
> statements are removed during compilation because they have nowhere to
> go in the browser. Server-side printing to standard output will go
> wherever your server redirects such things; usually to a log file.
>

Jason Essington

ยังไม่อ่าน,
29 ก.ค. 2551 12:41:5329/7/51
ถึง Google-We...@googlegroups.com
now you are experiencing a "scope" problem.

Since you declared the url variable inside the try/catch block, that
is the only scope that it is available in.

you would need to declare the url outside of the try/catch block (URL
url = null;) then instantiate it inside the block (url = new URL(...))

-jason

Isaac Truett

ยังไม่อ่าน,
29 ก.ค. 2551 12:53:3529/7/51
ถึง Google-We...@googlegroups.com
How are you starting tomcat? If it runs as a Windows Service, for
example, standard output will default to <tomcat>/logs. If you're
running from the command line, standard output will default to the
command prompt window. If you're using Eclipse and the Sysdeo Tomcat
plugin, output will default to the Eclipse Console View.

D L H

ยังไม่อ่าน,
29 ก.ค. 2551 12:55:1529/7/51
ถึง Google Web Toolkit
yeah i noticed that. i think i've got that taken care of, right?

URL url = null;
BufferedImage img = null;
try {
url = new URL("http://localhost/proprintsonline/favicon/
favicon.png");
img = ImageIO.read(url);

} catch (MalformedURLException e) {
} catch(IOException e) {
}

On Jul 29, 12:41 pm, Jason Essington <jason.essing...@gmail.com>

D L H

ยังไม่อ่าน,
29 ก.ค. 2551 13:13:5329/7/51
ถึง Google Web Toolkit
right now i'm just using the built in tomcat in hosted mode

On Jul 29, 12:53 pm, "Isaac Truett" <itru...@gmail.com> wrote:
> How are you starting tomcat? If it runs as a Windows Service, for
> example, standard output will default to <tomcat>/logs. If you're
> running from the command line, standard output will default to the
> command prompt window. If you're using Eclipse and the Sysdeo Tomcat
> plugin, output will default to the Eclipse Console View.
>

Isaac Truett

ยังไม่อ่าน,
29 ก.ค. 2551 13:28:0129/7/51
ถึง Google-We...@googlegroups.com
I haven't run hosted mode without -noserver (i.e., using my own
independent Tomcat server) in a while. I would guess that standard out
goes to the command prompt where you started hosted mode (assuming
you're using the script that was generated for you).

D L H

ยังไม่อ่าน,
29 ก.ค. 2551 13:44:3829/7/51
ถึง Google Web Toolkit
ahh yes. you are correct. i had been bypassing the terminal, so i
didn't see that before.

On Jul 29, 1:28 pm, "Isaac Truett" <itru...@gmail.com> wrote:
> I haven't run hosted mode without -noserver (i.e., using my own
> independent Tomcat server) in a while. I would guess that standard out
> goes to the command prompt where you started hosted mode (assuming
> you're using the script that was generated for you).
>

D L H

ยังไม่อ่าน,
29 ก.ค. 2551 13:49:1829/7/51
ถึง Google Web Toolkit
i think this issue is resolved. thanks for all your help and sorry for
getting frustrated earlier.
ตอบทุกคน
ตอบกลับผู้สร้าง
ส่งต่อ
ข้อความใหม่ 0 รายการ