JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The only way I can see for that to generate an NPE is for a to be un-initialised.
Insert a System.out.println(i + " " + a); immediately before that line and let's see exactly what's happening.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
class X {

   public void main(...) {
     ...
     myMethod(); // call method
   }

   void myMethod() { // define method
      ...
   }

}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have put the method definitions inside the definition of the main method. That's illegal. You must put them in the class, but outside any other methods.
Then you just need to call them from inside the main method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When Java displays the Exception it tells you the number of the line where the Exception was created, as in
"at ImagesTest.RefHist(ImagesTest.java:149)"
This is essential information for debugging.

However, it's useless without a line-numbered program listing of the exact code that caused the NPE. The code you posted is not the exact code that you were running when you got the NPE - it has a line 149, but that is not the same line 149 that the NPE message refers to - so its unhelpful.

Please post the relevant code showing the exact line that is referred to in the Java error message.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So which line (according to the code you posted earlier) does the NPE point to?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It would help if the code you posted corresponded to the error messages. Line 149 is for(i=0;i<256;i++) - no NPE there!
After that you loop thru all 256 elements of the array, but you previously populated only as many elements as there lines in the data file, so if there are <256 lines in the file yo will have un-populated elements in the array after that, hence NPE when you try to refernce them?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can use a boolean to tell you which letter to use. Instead of line 23 test the boolean, assign the appropriate char, then toggle the boolean true -> false or false -> true so that next time thru the loop you will print the other char.
Or
Get a bit a paper and write down the value of (row+col) for each square. Notice how the result goes odd/even in alternating squares? It's easy to test for odd/even...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think this is anew topic and deserves its own thread, but... there's no way to answer this without a lit more info about where the points come from - a file? user mouse clicks?
Suggest you start a new thread and describe the situation in much more detail.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's easy to split up a string into an array of strings, using (eg) a blank as a delimiter

String s = "abc 123";
String[] parts = s.split(" ");
// now   parts[0] = "abc", parts[1] = "123"

To convert the score from String to int you can use the Integer.parseInt method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You don't have a variable with the split string in it yet. You need to create a new String array to hold the split-up string, then loop thru that array parsing the Doubles one at a time.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
// determines whether each indiviual character of the user entered string is a letter (is counting cumilative for each string still)
for (int x = 0; x < inputLine.length(); x++)
  if (Character.isLetter(inputLine.charAt(x)))
    letter++;

This little piece of your code examines the String inputLine and sets the variable letter to be the number of letters in the String. That's good.
It's very easy to make this into a method that takes the String as its parameter and returns an integer for the count of letters.
You can then easily replace this block of code with a call to your new method.

You may need to revise your course materials on how to define and call a method.

Give it a try and come back here if you have problems (don't forget to post whatever you have done so far).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You carefully trim and split the string to print it (that's good), but then you ignore that and try to parse the original un-split string.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

~s.o.s~ and I have already told you what the problem is. You still haven't done what we said. Read our posts again.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry, I have no experience with that library, nor with Java installation under OSX. Hopefully someone else can help here.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, gameLoop looks like the main method here.
It's normally considered bad practice to put too much code in main() because this hinders any possible re-use. The ideal main() just instantiates an instance of the class, and calls an instance method that does whatever needs to be done.
So, the public static void main(String[] args) method should just create a new FPCameraController and call its gameLoop method.
The gameLoop method should not create a new instance, ie no line 77. ganeLoop is an instance method, so there must have already been an instance created before this method can be called!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry if I undermined what you were trying to do. It seemed to me that the O/P was still completely stuck, so I tried to give a bit more of a steer without actually providing a detailed solution or actual code (or solutions to the next set of questions (and we both know what they will be!)). I am a complete believer in giving just enough info to unstick the problem while leaving the maximum possible scope for the poster to do their own research and learning. Cheers. J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you have an array of (say) 26 letters you can generate a random integer between 0 and 25, then use that as an index into the array, thus selecting a random letter. Do that in a loop to generate a sequence of random letters ...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

lines 92-98 the editing has got screwed up here -
Object source = e.getSource(); needs to inside ActionPerformed

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Show us the relevant code & data.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm looking at lines 90-100
I see you read a line and then split it into tokens, but then you try to parse the whole line as just one Double value. If the line contains multiple tokens, then it presumably has more than 1 Double in it. Maybe you should be parsing each token individually?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm finding it hard to understand exactly what you are trying to achieve here.
F contains a HashTable; in P you want to perform a lookup on that HashTable - is that right?
If so, you can:
1. Make the HashTable public in F so P can access it directly
or
2. you can provide a getter method in F that returns the HashTable so P can use it.
or (probably best, depending on exactly what you want)
3. Keep the HashTable private in F, and have a public method in F that does lookups (accept the key as parameter, return the value). P can then call that to get the result of a lookup without having to know anything about the details of how the lookup works.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Can't tell without the your code, but if you're trying to parse that "{" at the beginning of your input string, that could be the cause of your problem.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are comparing one instance of class Score to another instance of class Score.
The method will be called by the sort routing sonething like this:
score1.compareTo(score2);
so in your compareTo method you are comparing "this" with the Score passed as a parameter. If those two instances are the same instance, just return 0 (ie "equal").

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sure you can create a new thread and sleep in that and use invokeLater, and that should work. But it's a pretty tortuous way to achieve a result for which the swing timer was created, and which timer does in far less code.
Swing timer is actually the class used internally by swing for things like popping up mouse-over tooltips. It's designed to be very efficient and its, obviously, totally integrated into the whole swing infrastructure.
To stop or start your animated icons, just stop or start the timer.
so
No, there;s nothing wrong with it, but it's definitely the second-best solution.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I would have put all characters (upper and lower cases) that I would like to use in the same collection, unlike you put it in four different. Take it size and run random generator on collection size number of times declared by me or user.

That's good if you want a really random string with minimum code, but if the requirement is to have (eg) at least one lower case, at least 1 upper case, at least 1 number (etc), and other chars may or may not be acceptable, then the four arrays may not be such a bad idea.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have a look at the java.util.Random class in the API. You can use this to select random letters etc from your arrays.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I need to do different things on each call and Timer triggers the same function (or the same set of functions) every 1 sec. How to achieve that ?

Simple switch with a var to tell which icon we need to set each time

int step = 1;
...
public void actionPerformed(ActionEvent e) { // called by Timer
  switch (step ) {
   case 1: {
     // set 1st icon
     step = 2;   
     break;
   }
   case 2: {
     // set 2nd icon
     step = 3;   
     break;
   }
   // etc
}

or (better) have the icons pre-loaded into an array of ImageIcons, then

int iconNum = 0;

public void actionPerformed(ActionEvent e) { // called by Timer
  button.setIcon(imageIcons[iconNum ])
  iconNum ++;
  if (iconNum >= imageIcons.length) iconNum = 0
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

how to get the information inside the while loop

Wrong question. Don't use an infinite loop at all. Use a timer. You don't actually have a long-running task, you just have a task that has to be run regularly.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Never - that is NEVER - use sleep anywhere near Swing. Your while(true) loop runs on the EDT and never returns, thus blocking everything.
For that kind of timing use a javax.swing.timer
Use it to call your button changing method every x millisecs. In that method just change the icon to the next icon and return immediately.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why not just build the string userName + " " + password + "\n"
and use indexOf to see if that complete String is present in the textarea

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A default ResultSet object ... has a cursor that moves forward only.

- which is incompatible with beforeFirst(). (although you should have got an SQL exception if that was the problem)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Can't see anything yet - still looking.
BTW: Is the record that you get the first or the last record?

Also: confused by your last post: if the returned value is 0 that implies the last line of loop is never executed. Yet the presence of (some?) data in array[0] implies the rest of the loop is executed once.

Is it possible that any of the set methods are throwing a runtime exception?
Try putting a print at lines 24 and 35 to be certain of what's going on.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I can't make any sensible comment because I can't see any of the code leading up to that loop. At least you now have a ckue as to where the problem lies.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sounds like the loop in your first posted code is only being executed once. Have you tried a print in that loop to see how many times it's executed?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
17.        if(order.length > 0){
18.            out.println(order[1].getPhoneType());
19.        }

If order is of length 1 this code will always give an NPE (arrays are zero-based)

Was it intended to be a loop?, as in

for (int i = 0; i < order.length; i++ ) {
   out.println(order[i].getPhoneType());
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Lines 60-62
In the loop you remove 1 char from endstring with the intention of adding it to begstring on for the call on line 62 line.
Problem is that you remove the char THEN you try to get it by using charAt, but it's too late, you've already removed it!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"conceptually" I would stick with thinking of them as static final variables containing references to the different enum instances. Its only constant-specific methods that don't fit the simple summary. They are generated by the equivalent of something like this:
enum Month{ JAN(31), etc
is like:
enum Month {
public static Month JAN = new Month(31);
etc

I'm away now till tomorrow. Good luck.

NewOrder commented: okay, thanks james +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

enums are a thing in their own right - and have characteristics that ordinary classes do not, particularly constant-specific methods. However, these are so rare in practice that you can not worry about them. In Java words like "variables", "inherit", "class" have absolutely specific meanings, so a statement like "static enum variables inherit from enum class" conveys a general feel of what happens, but is a false statement. variables cannot inherit.

As for your code:
What's the point of the Games class? All it does is provide a set of covers for methods that need no cover. It seems to be pure overhead with no value.
You have used constant-specific methods, presumably because we were talking about them, but there's no need for them in your example. They are a log and tedious way to achieve that result. The code will be shorter and clearer if you make description, price, isWorthy and name simple variables and set them in a constructor. Like this:

enum Charactaristics{
  FALLOUTVEGAS("Awesome Game , but worth downloading cause there is no multiplayer",
               200, true, "1. Fallout New Vegas"),

  GODOFWAR("Good Game, the only good game on the psp"  ... etc

  private String decription;
  private int price;
  private boolean isWorthy;
  private String name;

  Charactaristics(String decription, int price, boolean isWorthy, String name) {
    this .decsription = description;
    etc
  }

   public String getDescription() {return description;}
   etc
}

Finally, you use two arrays fro game names and enum constants, and build a map to relate them.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

As I said, its like a final static enum; I was trying to keep things simple. It's actually more complicated than that.
The example you show is defining an overridden version of the SayHello() method for each instance of the enum. There's also one override of the getPrice() method, although it doesn't make any sense. (These methods are known as constant-specific methods.)
This is a fairly advanced and rare facility, which you won't see often. This is the point where the simple analogy of class/static vars breaks down - there is no corresponding construct for an ordinary class (unless someone else can correct me on that?), it's more like defining inner sub-classes of the enum, but its not exactly that either, It just is what it is.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

BURI and AMNON are not classes, and you cannot treat them as classes.
They are not instance variables, and you cannot treat them as instance variables.
They are like static final references to two instances of the enum
Yoi cannot "open" them.
The code you posted is not valid.

All it is saying is that there are exactly two Fishs, one called BURI one called AMNON. They both have an attribute called "x", which has the value 20 for BURI and 50 for AMNON.

ps. Please be careful with your capitalisation. Java is case-sensitive. There is no such thing as an Enum (well, strictly there is, but you don't use it), nor are there Fishs called Amnon or Buri.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

An enum is just like a class that has a number of instances defined at compile time. You can think of it as if Fishes is a class, with exactly two instances.
BURI and AMNON are like two public static final variables that hold references to the two instances.
Lines 22-24 are the constructor for Fishes. It's called with the parameters 20 and 50 for the two instances, and it stores the values 20 and 50 in the instance variable x.
The getX method does exact.ly what you would expect.
The print on line 10 should therefore print 50.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Lines 2,3,4 also suspect, the array references will only be executed if the array index is negative and therefore out of bounds.

6,7 seem to take xy coords in the range 1024,768 and scale them to fit the actual size of the current component. They also invert them so the origin is the bottom right corner (seems normal for y, unusual for x - I would expect bottom LH corner)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hrmmm I see. Unfortunately I don't see any other methods that will read more than one. The rest seem to read strings.

Yes, read string and parse for int/float etc. Integer.parseInt etc methods - google them.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

read() reads a single char, so it's probably not what you need to read mutli-character ints, you are reading the char '5' and assigning it to an int - ASCII 53. Ditto read '7' is ASCII 55.

I have to go offline now till tomorrow, so good luck. I'll look again in the morning. An up-to-date source listing may be useful.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Time to start putting a few more System.out.println lines into the code to see exactly where things are going wrong.
What's J/p ?

It's always a bit dangerous using array sizes fixed in the code to read data from a file - if they don't match it all goes to ratsh*t. what happens when the number of periods/rates has to change?
It's a better idea to add a line to the data file, just before that data, showing how many periods/rates to expect. Then you read that number, create arrays of that size, then read the actual data. Futureproofed.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

My code was just an example of the syntax. I deliberately didn't give you the exact line of code because you will learn more by working it out yourself. I didn't mean that you should use floats, just use whatever the arrays need to be, but initialise/create them following the pattern from my code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Well, yes.
float[] myArray; just declares a reference variable (pointer).
To have an actual array you need to create a "new" array and define its size
float[] myArray = new float[99];

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

and make sure we have a listing of the code lines it refers to.

The line numbers in your exceptions do not correspond to the code you have posted.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's odd kramerd - I thought I had already said exactly the same thing, and in more detail!