Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2008

Tip: Looking for answers? Try searching our database.

Finding Error in Applet.

Thread view: 
Sanny - 13 Jan 2008 06:17 GMT
I have an Applet which gives no compilation error. But hangs sometimes
when running.

It works most of the time. But sometime it hangs in between. It has 20
functions and I want to know at which function it hangs. The Applet
cannot be run using Applet Viewer It can only run on a web browser. So
I cannot use the debug feature.

What I want is incase it gets into error I catch the error and report
that error to the web server. Can I use Try/Catch in the main program
to know which function is causing that error?

Like Below

Appletmain(){
try{
function1()
function2()
function3()
function4()
.
.
.
function19()
function20()
} catch outofbounds{
Senderrormessage()
}
}

The things I want to know is
1. What type of error causes the program to hang.
2. Which function this hang occurs.
3. Which Variable Causes this hang.
4. Values of that Variable during that hang.
5. Stack of functions being referred.

These things are possible in C++ Is it also possible in Java. The Big
problem is that I cannot use Debugger as the Applet only runs in
Browser.

Bye
Sanny
Andrew Thompson - 13 Jan 2008 06:46 GMT
...
> These things are possible in C++ Is it also possible in Java.

Is that a question?  Questions in English are
denoted by adding a question mark (?) to the
end of the sentence, instead of a full-stop (.).

>..The Big
> problem is that I cannot use Debugger as the Applet only runs in
> Browser.

Browsers have a console, applets also run in
the applet viewer, and most IDEs will allow
you to debug an applet in the applet viewer
(or similar - shrugs) from a 'menu command'
in the IDE.

BTW - had you considered webstart for this
deployment?  Much nicer, many fewer hassles.
e.g. <http://www.physci.org/jws/>

--
Andrew T.
PhySci.org
Sanny - 13 Jan 2008 07:26 GMT
> ...
>
[quoted text clipped - 21 lines]
> Andrew T.
> PhySci.org

I use double buffering  and Paint Method first create the image and
then paints on the Canvas. It works on Browsers but It gives
nullException when I use IDEs

Bye
Sanny
Andrew Thompson - 13 Jan 2008 08:08 GMT
(big snip)

Please learn how to trim!

> > BTW - had you considered webstart for this
> > deployment?  

*What is the answer to this question?*

> I use double buffering  and Paint Method

NoSuchMethodError *

>..first create the image and
> then paints on the Canvas.

Are you using AWT?  Why?

> ...It works on Browsers but It gives
> nullException

NoClassDefFoundError *

> ..when I use IDEs

After that kind of pathetic statement,
I am compelled to add..
"I'd guess that is because the code is crap.
Have you considered hiring a (Java) programmer?"

If you want to appear *less* pathetic, you
might try providing the code used, and/or
linking to a web page with the (broken) applet.

* And please stop wasting our time and bandwidth
with paraphrased class names or error messages.
Retype them *exactly* as you see them, or
better still, copy/paste.

--
Andrew T.
PhySci.org
Sanny - 13 Jan 2008 08:28 GMT
> (big snip)
>
[quoted text clipped - 38 lines]
> Andrew T.
> PhySci.org

You are talking on other matters instead of the problem

1. Why I do not put "?" Mark. That has nothing to do with what I
asked.

2. How to Trim Again nothing to do with my problem

3. Write nullException as NoClassDefFoundError

My Question is Simple and I restate again

I use double buffering in my applet. I hope you understand what is
double buffering. So my applet cannot be launch by Java Viewer as it
gives nullException.

But my Applet runs without any problem on Web Browsers like Explorer/
Netscape etc.

Sometimes 1 in 10 times it hangs. I just want to get details of
function/ Variable which hang the Program. And also what type of error
is called.

1. Arrayoutof Bounds
2. Division by Zero
3. Memore Full

And also I would like to get the Variables values when it hangs.

For that I want to use try{ } Catch Statement. But I am not aware how
to do it on all functions?

Do I need to put try{}catch seperately on each function or I can put a
try{  } catch to all function by some way. I just want to know why the
Program hangs 1 in 10 times.

Bye
Sanny
Lew - 13 Jan 2008 09:04 GMT
> You are talking on other matters instead of the problem
>
> 1. Why I do not put "?" Mark. That has nothing to do with what I
> asked.

Why are you unwilling to use question marks to mark your questions?

> 2. How to Trim Again nothing to do with my problem

But everything to do with people's willingness and ability to volunteer their
precious time to help you with it.

> 3. Write nullException as NoClassDefFoundError

If you report the situation inaccurately, advice given will be inaccurate and
likely useless.

Accurate and rigorous information is needed to be of any assistance.  Are you
sure you don't want to provide that?

> My Question is Simple and I restate again
>
> I use double buffering in my applet. I hope you understand what is
> double buffering. So my applet cannot be launch by Java Viewer as it
> gives nullException.

There is no such exception in the standard Java API.  Did you mean
NullPointerException?

If so, you should say so.  Inaccurate information leads to inaccurate and
useless diagnoses.

> But my Applet runs without any problem on Web Browsers like Explorer/
> Netscape etc.
>
> Sometimes 1 in 10 times it hangs. I just want to get details of
> function/ Variable which hang the Program. And also what type of error
> is called.

There may not be an error.  If an Exception or Error or any other Throwable
were thrown, you'd have gotten a message to that effect already.

Did you?

> 1. Arrayoutof Bounds
> 2. Division by Zero
> 3. Memore Full

These are very different categories of problems, reported by different types
of Throwable in Java.

Division by zero doesn't even necessarily throw an exception.  It could just
yield a valid value.

> And also I would like to get the Variables [sic] values when it hangs.

You need a reliable way to detect a hang and break out of it for that to
happen.  Infinite loops and thread deadlock are examples of situations that
will not spin out any throwables.

A good logging package, like the inbuilt java.util.logging package or the
open-source log4j library, can report the type of information you seek.

If you log at FINE (java.util.logging) or DEBUG (log4j) level, or more
detailed, you can spin off log information at various points in your algorithm
that can help diagnose even such problems as infinite loops and thread deadlock.

> For that I want to use try{ } Catch Statement. But I am not aware how
> to do it on all functions?
>
> Do I need to put try{}catch seperately on each function or I can put a
> try{  } catch to all function by some way. I just want to know why the
> Program hangs 1 in 10 times.

try-catch probably will not reveal the source of your problem.

Use try-catch whenever the code explicitly has a path that might throw an
exception.  In the catch block be sure to use your logging library to report
the exception.

In other situations where try-catch will not help, logging still will.

<http://java.sun.com/javase/6/docs/api/java/util/logging/package-summary.html>
<http://logging.apache.org/log4j/1.2/index.html>

Signature

Lew

Roedy Green - 13 Jan 2008 10:56 GMT
On Sun, 13 Jan 2008 00:08:26 -0800 (PST), Andrew Thompson
<andrewthommo@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>After that kind of pathetic statement,
>I am compelled to add..
>"I'd guess that is because the code is crap.
>Have you considered hiring a (Java) programmer?"

CUT THAT OUT!.  He as a newbie. You were one once too. If people were
as rude to you back then an you are to him, you would unlikely be
programming today.

Signature

Roedy Green, Canadian Mind Products
The Java Glossary, http://mindprod.com

Andrew Thompson - 13 Jan 2008 11:46 GMT
On Jan 13, 9:56 pm, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> On Sun, 13 Jan 2008 00:08:26 -0800 (PST), Andrew Thompson
> <andrewtho...@gmail.com> wrote, quoted or indirectly quoted someone
> who said :
...
> >After that kind of pathetic statement,
> >I am compelled to add..
[quoted text clipped - 4 lines]
> as rude to you back then an you are to him, you would unlikely be
> programming today.

If people had continued to be so 'nice' to me
as not to point out the basic realities, I might
still be a 'newbie'.

--
Andrew T.
Lew - 13 Jan 2008 16:32 GMT
> If people had continued to be so 'nice' to me
> as not to point out the basic realities, I might
> still be a 'newbie'.

I suspect Roedy isn't addressing the useful content but the undiplomatic tone.

I favor blunt but objective technical comments, but the comment about a
"pathetic statement" would tend to close someone's ears to your helpful advice.

As for you newbies and other folks - disregard the tone of messages online,
which will always tend to be harsher than they'd sound in person, and focus on
the content.  You can register objections:

"The statement isn't pathetic.  Here's why ..."

or agreement:

"You're right, the code is crap, that's why I'm asking for help."

or obtain that gold nugget of good advice and acknowledge it:

"Thank you, Andrew, hiring a consultant is a good idea for us.  We hadn't
thought of it."

or request clarification:

"What about my post led you to conclude that it's pathetic?"

All of these are potential responses to the content, without getting too
wrapped up in diversionary emotional issues.

I suggest not directly addressing the person's attitude if it offended you
personally.  Since I am not offended by Andrew, in fact, I rather like him, I
feel free to criticize him roundly where I feel it's justified.  He knows
where I'm coming from.

Signature

Lew

Roedy Green - 13 Jan 2008 08:36 GMT
On Sat, 12 Jan 2008 22:17:53 -0800 (PST), Sanny
<softtanks@hotmail.com> wrote, quoted or indirectly quoted someone who
said :

>1. What type of error causes the program to hang.

I my hang I presume you mean freeze up without error message.  The
classic way to do that is an endless loop. You might try tracing to
track it down. See http://mindprod.com/jgloss/debugging.html
Signature

Roedy Green, Canadian Mind Products
The Java Glossary, http://mindprod.com

Sanny - 13 Jan 2008 08:46 GMT
On Jan 13, 1:36 pm, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> On Sat, 12 Jan 2008 22:17:53 -0800 (PST), Sanny
> <softta...@hotmail.com> wrote, quoted or indirectly quoted someone who
[quoted text clipped - 8 lines]
> Roedy Green, Canadian Mind Products
> The Java Glossary,http://mindprod.com

I went through it. I would like to put an try{ }catch on all functions
and whenever there is some error the error be sent to server with
details like Function Name, Variable Name, Error Type and Line Number.

So that I understand where that error occur. I can only use the applet
on a Browser, As it has to take data from Server after loading using
appletcontext and also it uses double buffering So it gives null
Exception when using Debuggers.

Bye
Sanny
Lew - 13 Jan 2008 08:52 GMT
> I would like to put an try{ }catch on all functions
> and whenever there is some error the error be sent to server with
[quoted text clipped - 4 lines]
> appletcontext and also it uses double buffering So it gives null
> Exception when using Debuggers.

If you would provide a simple, self-contained compilable example it would help
people answer your question.

As Roedy pointed out, one classic cause of a program hang is an infinite loop.
 Another is thread deadlock.  Neither of these throws an exception, so your
try{}-catch{} will not help.

Debug tracing and source-code inspection are two techniques to diagnose such
difficulties.  We can do neither without a code sample that evinces your problem.

Signature

Lew

Sanny - 13 Jan 2008 09:00 GMT
> > I would like to put an try{ }catch on all functions
> > and whenever there is some error the error be sent to server with
[quoted text clipped - 17 lines]
> --
> Lew

There is nothing wrong with the code as When the program runs It hangs
one 1/10 times. Other 10 times it performs and give results as
expected. But sometimes for same input it hangs. But when I restart
the Applet it works 9/10 time.

Is there any debugger which downloads applet just like a browser and
then provide error details when it hangs.

Bye
Sanny
Lew - 13 Jan 2008 09:05 GMT
> There is nothing wrong with the code as When the program runs It hangs
> one 1/10 times. Other 10 times it performs and give results as
> expected. But sometimes for same input it hangs. But when I restart
> the Applet it works 9/10 time.

Clearly there is something wrong with the code.

Signature

Lew

Patricia Shanahan - 13 Jan 2008 14:52 GMT
>> There is nothing wrong with the code as When the program runs It hangs
>> one 1/10 times. Other 10 times it performs and give results as
>> expected. But sometimes for same input it hangs. But when I restart
>> the Applet it works 9/10 time.
>
> Clearly there is something wrong with the code.

More specifically, the code probably contains a bug in the interactions
between threads that depends on two or more events in the code happening
in particular time relationships to each other. In addition to any
suggestions for live debug after the problem has happened, I would
recommend a design review of the synchronization between threads.

Patricia
Lew - 13 Jan 2008 16:36 GMT
>>> There is nothing wrong with the code as When the program runs It hangs
>>> one 1/10 times. Other 10 times it performs and give results as
[quoted text clipped - 8 lines]
> suggestions for live debug after the problem has happened, I would
> recommend a design review of the synchronization between threads.

With which we could help, Sanny, if you would

** provide a simple, self-contained, compilable example (SSCCE)! **

Signature

Lew

Patricia Shanahan - 13 Jan 2008 16:46 GMT
>>>> There is nothing wrong with the code as When the program runs It hangs
>>>> one 1/10 times. Other 10 times it performs and give results as
[quoted text clipped - 12 lines]
>
> ** provide a simple, self-contained, compilable example (SSCCE)! **

That may be difficult to do in this situation. This type of behavior
tends to be an emergent property of the whole program. Removing
something can make the problem appear to go away, by changing timings,
without fixing it.

In any case, I would rather help Sanny learn how to debug this sort of
problem.

Patricia
Lew - 13 Jan 2008 16:54 GMT
Lew wrote:
>> ** provide a simple, self-contained, compilable example (SSCCE)! **

> That may be difficult to do in this situation. This type of behavior
> tends to be an emergent property of the whole program. Removing
[quoted text clipped - 3 lines]
> In any case, I would rather help Sanny learn how to debug this sort of
> problem.

Both excellent points, Patricia.

OTOH, preparing an SSCCE, when feasible, helps debug many sorts of problems.
Failing to create one teaches much in the attempt.  Having others review one
and provide hints, rather than spoon-fed answers, could also help with that
latter objective.

In any event the OP has not responded to the suggestion to provide an SSCCE,
so we do not know if that is "difficult to do in this situation" or not.

Signature

Lew

Patricia Shanahan - 13 Jan 2008 16:44 GMT
...
> There is nothing wrong with the code as When the program runs It hangs
> one 1/10 times. Other 10 times it performs and give results as
[quoted text clipped - 3 lines]
> Is there any debugger which downloads applet just like a browser and
> then provide error details when it hangs.

In this situation I would avoid investing a lot of time and effort in
changing the environment. *Anything* you do to debug this carries the
risk of reducing the failure frequency without removing the underlying
bug. A 1-in-10 failure is far easier to debug than a 1-in-100 failure.

Instead go with desk-checking combined with inserting System.err.println
statements in potentially relevant places. The sort of thing you should
be looking for is a situation in which you have a loop in the set of
resources that can be held by a thread while waiting for another resource.

For example, suppose you have a pair of objects A and B that are both
used for wait-notify, and you have two threads such that:

Thread 1 owns the lock associated with A, and is waiting for B.

Thread 2 owns the lock associated with B, and is waiting for A.

Obviously, neither thread can make progress.

In general, you should be able to write an ordered list of lockable
resources such that a thread waiting for a resource never holds anything
that appears later in the list.

Also, check that all graphics component manipulation is in the event
dispatch thread.

See http://home.earthlink.net/~patricia_shanahan/debug/ for some more
ideas on debug.

Patricia
Roedy Green - 13 Jan 2008 10:55 GMT
On Sun, 13 Jan 2008 00:46:07 -0800 (PST), Sanny
<softtanks@hotmail.com> wrote, quoted or indirectly quoted someone who
said :

>So that I understand where that error occur. I can only use the applet
>on a Browser, As it has to take data from Server after loading using
>appletcontext and also it uses double buffering So it gives null
>Exception when using Debuggers.

Either use a debugger which simulates the AppletContext, or put in
some code to temporarily bypass that usage. That way you can figure
out if the problem is in the AppletContext stuff or the rest.
Signature

Roedy Green, Canadian Mind Products
The Java Glossary, http://mindprod.com

Roedy Green - 13 Jan 2008 08:38 GMT
On Sat, 12 Jan 2008 22:17:53 -0800 (PST), Sanny
<softtanks@hotmail.com> wrote, quoted or indirectly quoted someone who
said :

>The Big
>problem is that I cannot use Debugger as the Applet only runs in
>Browser.

It is trivially easy to convert an Applet to an application for
debugging.  I call them "hybrids" ..
http://mindprod.com/jgloss/applet.html
for how.
Signature

Roedy Green, Canadian Mind Products
The Java Glossary, http://mindprod.com

Roedy Green - 13 Jan 2008 08:39 GMT
On Sat, 12 Jan 2008 22:17:53 -0800 (PST), Sanny
<softtanks@hotmail.com> wrote, quoted or indirectly quoted someone who
said :

>The Big
>problem is that I cannot use Debugger as the Applet only runs in
>Browser.

The IntelliJ Idea IDE will let you run and debug Applets directly.  It
simulates a browser environment.
Signature

Roedy Green, Canadian Mind Products
The Java Glossary, http://mindprod.com

Sanny - 13 Jan 2008 08:49 GMT
On Jan 13, 1:39 pm, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> On Sat, 12 Jan 2008 22:17:53 -0800 (PST), Sanny
> <softta...@hotmail.com> wrote, quoted or indirectly quoted someone who
[quoted text clipped - 9 lines]
> Roedy Green, Canadian Mind Products
> The Java Glossary,http://mindprod.com

Will it download the Classes from the server like regular Browsers. As
my Applet has to exchange data with Server before initialization.
[Login/Passwords etc]

Where can I download this IDE

Bye
Sanny
Roedy Green - 13 Jan 2008 11:01 GMT
On Sun, 13 Jan 2008 00:49:12 -0800 (PST), Sanny
<softtanks@hotmail.com> wrote, quoted or indirectly quoted someone who
said :

>Will it download the Classes from the server like regular Browsers. As
>my Applet has to exchange data with Server before initialization.
>[Login/Passwords etc]
>
>Where can I download this IDE

see http://mindprod.com/jgloss/intellij.html

There is a free trial, probably a month.  It is not free like most of
the others, but that might be long enough to solve your problem.

You might also try NetBeans and Eclipse to see how the are for
debugging Applets.  It has been a while so I don't recall if they can.
see http://mindprod.com/jgloss/ide.html

The big advantage of paying is there are staff to answer questions,
and they have to be polite even when you ask questions you "should"
know the answer to.
Signature

Roedy Green, Canadian Mind Products
The Java Glossary, http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.