Finding Error in Applet.

S

Sanny

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
 
A

Andrew Thompson

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/>
 
S

Sanny

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 (.).


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/>

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
 
A

Andrew Thompson

(big snip)

Please learn how to trim!

*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.
 
S

Sanny

(big snip)

Please learn how to trim!


*What is the answer to this question?*


NoSuchMethodError *


Are you using AWT?  Why?


NoClassDefFoundError *


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.

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
 
R

Roedy Green

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.
 
S

Sanny

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. Seehttp://mindprod.com/jgloss/debugging.html

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
 
S

Sanny

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

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
 
L

Lew

Sanny said:
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.

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.
 
S

Sanny

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.

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
 
L

Lew

Sanny said:
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>
 
L

Lew

Sanny said:
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.
 
R

Roedy Green

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.
 
R

Roedy Green

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.
 
R

Roedy Green

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.
 
A

Andrew Thompson

...

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.

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

Patricia Shanahan

Lew said:
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
 
L

Lew

Andrew said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top