strange netbeans glitch not finding java classes

G

gwlucas

I've just had something strange happen to me in Netbeans 6.1.

I was editing a file when, all of the sudden, Netbeans became unable
to find things like java.awt.event.MouseEvent and java.lang.Runnable.
I have never seen anything like this before. Does anyone have
experience with that kind of thing? Any suggestions?

My guess is that somekind of behind-the-scenes updater or something
ran and broke something (why anyone thinks that behind-the-scenes
processes that modify your computer environment are a good idea is
beyond me). I've re-installed Java and am in the process of re-
installing Netbeans. Anything I should look for?

Gary
 
G

gwlucas

Okay, I found the source of the problem and it's almost a little
funny...

While I was working, I was creating a new class file when somebody
came in to the office and interrupted. I attmpted to bail out of the
creation wizard, but being a little distracted, somehow managed to
create a file called "java.java"

This turned out to be toxic to Netbeans and the Java compiler. When I
used Netbeans to edit or compile a file which included a reference to
one of the Java API classes, such as java.lang.Runtime, it decided
that I wanted it to find the reference inside the class named
java.java. While clearly inappropriate, that was the correct behavior
based on the rules for resolving classpath and reference. So chalk it
up to operator error.

This is one of the stranger problems I've seen in a long time.

I suppose that I would have found it sooner if I had paid more
attention to the compiler warnings. I just assumed that Netbeans was
being flakey... Sometimes when you are debugging, it will get into a
confused state and the only way to correct the problem is to terminate
and restart the IDE... so having gotten used to the idea that the
program would misbehave, I wrongly assumed it was misbehaving again.
The real problem was, of course, that it was doing exactly what it was
supposed to do.

Gary
 
R

Roedy Green

Here is some code I use to select a "random" quotation to put an a web
page. It changes every 4 hours.

/**
* 86,400,000 the number of milliseconds in 24 hour day. Easily
fits into an int.
* We change the quotations every 4 hours, UTC.
*/
private static final int CHANGE_INTERVAL_IN_MILLIS = 4 * 60 * 60 *
1000;



final Adler32 digester = new Adler32();
int seed = ( int ) ( System.currentTimeMillis() /
CHANGE_INTERVAL_IN_MILLIS );
/// digester.update(int) not clearly documented, probably
wants ubyte.
digester.update( ( byte ) ( seed & 0xff ) );
digester.update( ( byte ) ( ( seed >>> 8 ) & 0xff ) );
digester.update( ( byte ) ( ( seed >>> 16 ) & 0xff ) );
digester.update( ( byte ) ( ( seed >>> 24 ) & 0xff ) );
digester.update( fileBeingProcessed.getPath().getBytes(
"UTF-8" ) );

// get rid of high sign bit, and low bit, which seem to be
1 disproportionately.
final int digest = (( ( int ) digester.getValue() ) << 1) final String[] candidates = category.getQuotations();

final String chosenQuote = candidates[ digest %
candidates.length ];

However it often SEEMS to sometimes pick the same quote for two
different pages, more often than I would intutitively think it would.

Further it SEEMS to favour certain quotes in the collection. I wonder
if this just my imagination, or there is some flaw in the algorithm.
 
J

John B. Matthews

Roedy Green said:
Here is some code I use to select a "random" quotation to put an a web
page. It changes every 4 hours.

/**
* 86,400,000 the number of milliseconds in 24 hour day. Easily
fits into an int.
* We change the quotations every 4 hours, UTC.
*/
private static final int CHANGE_INTERVAL_IN_MILLIS = 4 * 60 * 60 *
1000;



final Adler32 digester = new Adler32();
int seed = ( int ) ( System.currentTimeMillis() /
CHANGE_INTERVAL_IN_MILLIS );
/// digester.update(int) not clearly documented, probably
wants ubyte.
digester.update( ( byte ) ( seed & 0xff ) );
digester.update( ( byte ) ( ( seed >>> 8 ) & 0xff ) );
digester.update( ( byte ) ( ( seed >>> 16 ) & 0xff ) );
digester.update( ( byte ) ( ( seed >>> 24 ) & 0xff ) );
digester.update( fileBeingProcessed.getPath().getBytes(
"UTF-8" ) );

// get rid of high sign bit, and low bit, which seem to be
1 disproportionately.
final int digest = (( ( int ) digester.getValue() ) << 1)final String[] candidates = category.getQuotations();

final String chosenQuote = candidates[ digest %
candidates.length ];

However it often SEEMS to sometimes pick the same quote for two
different pages, more often than I would intutitively think it would.

Further it SEEMS to favour certain quotes in the collection. I wonder
if this just my imagination, or there is some flaw in the algorithm.

Are you trying to make the sequence of quotes depend on the last
processed file? Maybe something like this:

// initially
Random random = new Random();
Adler32 digester = new Adler32();
...
// each new file
digester.update(fileBeingProcessed.getPath().getBytes("UTF-8"));
...
// every n hours
random.setSeed(digester.getValue());
chosenQuote = candidates[random.nextInt(candidates.length)];

John
 
T

Tom Anderson

Here is some code I use to select a "random" quotation to put an a web
page. It changes every 4 hours.

/**
* 86,400,000 the number of milliseconds in 24 hour day. Easily
fits into an int.
* We change the quotations every 4 hours, UTC.
*/
private static final int CHANGE_INTERVAL_IN_MILLIS = 4 * 60 * 60 *
1000;

final Adler32 digester = new Adler32();
int seed = ( int ) ( System.currentTimeMillis() /
CHANGE_INTERVAL_IN_MILLIS );
/// digester.update(int) not clearly documented, probably
wants ubyte.
digester.update( ( byte ) ( seed & 0xff ) );
digester.update( ( byte ) ( ( seed >>> 8 ) & 0xff ) );
digester.update( ( byte ) ( ( seed >>> 16 ) & 0xff ) );
digester.update( ( byte ) ( ( seed >>> 24 ) & 0xff ) );
digester.update( fileBeingProcessed.getPath().getBytes(
"UTF-8" ) );

// get rid of high sign bit, and low bit, which seem to be
1 disproportionately.
final int digest = (( ( int ) digester.getValue() ) << 1)final String[] candidates = category.getQuotations();

final String chosenQuote = candidates[ digest %
candidates.length ];

Why are you doing all this? Why not just new Random(), generate and throw
away a few ints, and then pick one out and use it?
However it often SEEMS to sometimes pick the same quote for two
different pages, more often than I would intutitively think it would.

Further it SEEMS to favour certain quotes in the collection. I wonder
if this just my imagination, or there is some flaw in the algorithm.

I also have a random quote selector, and i also notice this. There are
even times when i think it's picking quotes specifically tailored for the
email i'm about to write. I think it's an illusion - if you randomly pick
quotes, you don't expect them all to appear at the same frequency, but for
some to, by chance, come up more often. Isn't it a binomial distribution
or something? Anyway, it's exactly the kind of thing that the human brain
interprets as a pattern.

tom
 

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,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top