masijade 1,351 Industrious Poster Team Colleague Featured Poster

Read the API for one of the Timer Classes. The one you want is probably javax.swing.Timer.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Uhhm, awk is a really large subject. O'Reilly publishing http://www.oreilly.com/ produces an entire book (and a good one at that) dedicated to sed and awk. Try that.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

No, it will compile just fine without it. main, as far as the compiler is concerned, is a method just like any other, but when you try to execute a class and the method definition public static void main(String[] args) does not exist, you will get the exact error message you are showing. The method must be defined exactly as above with the following possible variations

1) args can be any name you want, it does not have to be exactly args 2) String[] args may also be String args[] (keeping point 1 in mind)

Those are the only variations allowable (as they are not really variations, the definition is the same, it is just typed a little differently). Having something else will prevent you from executing your program, but it will still compile with ease.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, you can remove files and directories from your path with a single find command as follows: find /path/to/backup/root -mtime 4 -exec rm -f {} \; If you also want a list of files deleted in this manner than do as follows: find /path/to/backup/root -mtime 4 -exec rm -f {} \; -print It is not necessary to write any kind of real script for this simple task. This is, of course, assuming that you are using a unix/linux variant.

Edit: Well directoriews won't be deleted, but you can do as follows with a second command to get empty (and only empty) directories find /path/to/backup/root -mtime 4 -type d -exec rmdir {} \; -print

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, start coding. If you have a problem post again, with your code and a description of your problem, along with any error messages (complete) and we will help, but we are not going to write it for you.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I haven't even looked at that code, because you haven't really asked a question.

What part of this are you having problems with?

Are you getting errors while compiling? If so, post them.

Are you getting errors while running? If so post them.

Are you seeing results other than what you expect? If so, post what you expect, and what you are getting.

Is there some part of the assignment that you do not understand? If so, ask the teacher, that is what he is there for.

Now, after you have read these questions, and decided you want to post here again, then please, repost the code as well, and this time use code tags. (Use the "Go Advanced" button below, then the "Code" button that you find there.)

masijade 1,351 Industrious Poster Team Colleague Featured Poster

A note on the file separator, the command line intrepreter is the complete reason why "\" is always used on Windows. Almost, if not, all programming languages can use "/" for paths in Windows, but the command line interpretor interprets "/" as the option argument indicator, so it needs something else for the file separator, and that became "\".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

First of all, never place anyting into the "bin" directory of jdk (or really in any directory of the jdk/jre).

Second of all, does your class contain the following method defintion:

public static void main(String[] args) {
  // your code here
}

and I mean that exact method definition? Bcause the error you listed, says it does not.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Hi, I'm trying to use the replace() method to take out all instances of " "
, (space) with an underscore, ("_"). I'm doing this because I'm using URLs to connect to a servlet. I keep getting this error:

replace(char,char) in java.lang.String cannot be applied to (java.lang.String,java.lang.String)

url.replace(" ", "_");

This is how I wrote my code:

url = url.replace(" ", "_");

What am I doing wrong? Any suggestions would be most welcome.

Thanks,
chuck

Do you notice something about the highlighted protions of the error message?

change url.replace(" ", "_"); to url.replace(' ', '_');

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Look at this from your code:

try { //Reads keyboard input and acts accordingly
            input = stdin.readLine();
        }catch (IOException ex) {
            System.out.println("Problem reading from the keyboard");
        
        iInput = Integer.valueOf(input); // convert String to Integer
        }

You convert your string input to an integer only when an exception happens. You need to move the closing brace from the catch block to a point before the iInput = line.

And, as a matter of fact, your indenting implies this to the reader, but the braces define something else, and it's the braces that count.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

i found your problem...

this is not a constructor.... :) i think you put void mistakenly

Aach. Completely overlooked that. Yes, that is the problem. And also the reason why display is null, because since that is not a constructor, display never gets initialised.

I am such a fool sometimes.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I assume, since you're using a textarea, that you are sending the mail in HTML format, right?

So simply place the href directly after the textarea. If it is not in HTML format, then simply placce the link (with the http(s)://) as plain text in the email, and if the mail program the user uses recognises links, it will automatically make it usable as a link.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Strange. The only thing I can suggest now, is to try running it in a debugger and observe what happens. I can't really suggest a debugger for a MIDlet as I have not tried any.

The only other suggestion is to make sure that that line is actually the one throwing an NPE.

And, as a general suggestion, to clean up the code a bit, I would move those commented parts of the constructor into their own private methods (one per commented part), and then call those methods from the constructor.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Place it as a normal link directly under the textarea.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

According to the documentation for Form and Display, and if this is actually the line throwing the null pointer exception, then display is the only thing that even can be null, since the setCurrent method will accept a null value, so currentForm is allowed to be null.

Take out all the dots and attempt to run the Class exactly as it is portrayed here. If that works, then the problem lies somewhere else in your code. Maybe there is some process somewhere in your class that sets display to null again. I don't know since I can't see the rest of the code.

As I said, however, reading the Display and Form API pages from this lcdui package, indicates that display is the only thing in that line that even could cause a NullPointerExcpetion.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

And that says nothing. Those classes are those classes, this class is this class. If you do not wish to provide the info we would need to help you, then at least don't waste our time.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Don't put the link in a textarea. It won't work.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Here is a sample of your code:

public static void main (String[] args) {
  String inputSuite;
  int nightsA;  // Here you declare, but do not define nightsA

  ...

  inputSuite = keyboard.nextLine();

  if (inputSuite.equalsIgnoreCase("A")) {
    System.out.println("How many nights do you plan on staying at the R & R?");
    nightsA = keyboard.nextInt();  // Here you define nightsA
  } else {
    System.out.println("Try one of our other suites. They might suit you better. ");
  }
  /* if the last if statement has not as yet
   * evaluated as true nightsA is not defined here
   * the compiler realizes this and flags it as an
   * error.  Change the line where you declare
   * nightsA to also make it a declaration.  i.e.
   * int nightsA = 0;
   * Or, you can set nightsA in the else side of
   * the above if statement.
   */
  if (nightsA <= 5 || nightsA >=1) {    suiteApricenoDCst = (suiteA * stateTax);
    suiteApricenoDCft = (suiteA * federalTax);
    suiteApricenoDC = (suiteA + suiteApricenoDCst + suiteApricenoDCft * nightsA); // or here
    System.out.println("Your price for your stay is " + suiteApricenoDC);
  } else if (nightsA > 5) {  // or here
    suiteADC = (suiteA * discount);
    suiteApriceDCst = (suiteADC * stateTax);
    suiteApriceDCft = (suiteADC * federalTax);
    suiteApriceDC = (suiteADC + suiteApricenoDCst + suiteApricenoDCft * nightsA);
    System.out.println("Your price for your stay is " + suiteApricenoDC);
  } else {
    System.out.println("ERROR!!!");
  }

  ...

}

Like jwenting said, you must explicitly declare all local variables. That means, before your code attempts to do anything with it, …

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Do Your Own Homework.

Salem commented: You tell 'em +6
thekashyap commented: Can't beleive they have so much pocket money now-a-days.. ! +2
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Thanks for replying, as I stated in my post, I'm a NOOB at this & I posted this to see if anybody could give me a suggestion on how to fix this error.

No, judging from this post, you came here for someone to give you the code to complete and functional program. Well, I'm sorry (no I'm not), but that is not how it works. Read jwenting's post again, consider his recommendation, study your code, and attempt to fix it. Surely, you have learned how to initialise variables.

(His response "No I haven't, and stop calling me Shirley!" Both halves of that sentence as senseless as the other.)

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Gods, what a bunch of lazy a**holes. Do your own homework. No one here, who has even a half an ounce of either sense and/or honor, will do it for you. God forbid if we did, and then had to work with your lazy, cheating a**es.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What about the Class Display.

Is it at all possible that display = Display.getDisplay(this); returns null?

Please provide this getDisplay method, or if it comes from some thrid party API, then please provide the JavaDoc from this method.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Some more code is needed. According to the method showed (in a cupsule like it was) display definately would be null, since there is no evidence otherwise. Post the entire class.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Maybe the NullPointerException refers to "display".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

No. You can obfuscate your code, or possibly try to create a native executable rather than a jarfile but both of these are equally useless. If someone wants your code they are going to get it.

The only way you prevent them getting your code is to not distribute it. In otherwords provide a web service or web site so that the consumer never gets your code onto his computer. But even then, reverser engineering can still be performed by determined people.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

No. Java is pass-by-value and pass-by-value only.

When you pass an object rather than a primitive, you are not actually passing an object. What you have is a variable that is only a reference to an object, and when you pass this, what happens is that the reference value is copied, and the copy is passed. Now you have two references to the same object.

Because of this you can use the methods of the object and see the result outside of the method, but changing the variable inside of the method will have absolutely no effect outside of the method.

You should probably read the following two articles. The second one is the one that is important, but you probably won't understand the terms they use if you do not read the first one.

http://www.javaranch.com/campfire/StoryCups.jsp
http://www.javaranch.com/campfire/StoryPassBy.jsp

BestJewSinceJC commented: A very old post, but a great explanation. I keep seeing people have this problem too... +4
masijade 1,351 Industrious Poster Team Colleague Featured Poster

I'm sorry, I don't mean to sound mean-spirited or sarcastic, but try a JavaScript Forum. Java != JavaScript

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, supplying the errors you are getting would be helpful.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

That is a pure personal choice design question. If it is going to be local intranet anyway, you could do simple multicast and let each "client" receive and broadcast the messages themselves, without any kind of a server.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Because you are defining the variable inside the loop. Change the following:

for(int i = 0; rst2.next(); i++){ 
  String ca1 = request.getParameter("ca1_"+i);
  String sa1 = request.getParameter("sa1_"+i);
  String ca2 = request.getParameter("ca2_"+i);
  String sa2 = request.getParameter("sa2_"+i);
}

to

String ca1 = "";
String sa1 = "";
String ca2 = "";
String sa2 = "";

for(int i = 0; rst2.next(); i++){ 
  ca1 += request.getParameter("ca1_"+i) + " ";
  sa1 += request.getParameter("sa1_"+i) + " ";
  ca2 += request.getParameter("ca2_"+i) + " ";
  sa2 += request.getParameter("sa2_"+i) + " ";
}

ca1 = ca1.trim();
sa1 = sa1.trim();
ca2 = ca2.trim();
sa2 = sa2.trim();
masijade 1,351 Industrious Poster Team Colleague Featured Poster

I think you can extropolate my answer from your other thread to fit this one. It seems to be the same thing.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

If what you mean, is that you want to concatenate all values into one string and then insert that then change

for(int i = 0; rst2.next(); i++){ 
  if(request.getParameter("ca1_"+i) !=null){
    Childic = rst2.getString("Childic") ;
    String query2 = "INSERT into results(ca1) values ('"+Childic+"')";
    stm2.executeUpdate(query2);
  } else {
    // whatever it is you want here
  }
}

to

for(int i = 0; rst2.next(); i++){ 
  if(request.getParameter("ca1_"+i) !=null){
    Childic = Childic + rst2.getString("Childic") ;
  } else {
    // whatever it is you want here
  }
}
String query2 = "INSERT into results(ca1) values ('"+Childic+"')";
stm2.executeUpdate(query2);
masijade 1,351 Industrious Poster Team Colleague Featured Poster
String ca1 = request.getParameter("ca1_<%=i%>");

should this not be

String ca1 = request.getParameter("ca1_" + i);

Assuming the parameter names are ca1_0, ca1_1, ca1_2, etc.

At this point in the code you are already inside a scriptlet tag (at least I assume you are), so additional scriptlet tags are nothing but syntax errors.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

System is a class, using it directly in this manner means you want to use a public static item from it.

out is the public static item you are using. It is an OutputStream that is used for the Standard Output (STDOUT, there is another for STDERR) of the running java application.

println() is of course a method of an OutputStream object that prints bytes to the device pointed to by the OutputStream object. In this case, usually the command line or an Application Console, unless redirected.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I coould be completely wrong, because I always put it against the left edge anyway, but I believe the "END_SCRIPT" marker you are using to end the so-called here document, needs to be against the left hand side, in otherwords at the beginning of the new line.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

No problem. And have fun.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Looking at your string I assume that the different parts of the string are
seperate4d by a TAB character. If so do the following:

String line = "BATHROOM TOI    48157   Y   DOVE BWASH MCDAMIA 375ML             6  NEW" ;
String[] parts = line.split("\\t");
//parts[0] = "BATHROOM TOI";
//parts[1] = "48157";
// etc. etc
masijade 1,351 Industrious Poster Team Colleague Featured Poster

I won't claim to know why you are converting this to a GregorianCalendar, but I
will show you two things that you can try. In both these examples the line
from your post for creating "sdf" and "dateField2" should be kept and the line
creating startDate thrown out.

Here the first:
String reqdt = sdf.format(dateField2) ;

Here the second:
GregorianCalendar startDate = new GregorianCalendar( ) ;
startDate.setTime(dateField2) ;
String reqdt = sdf.format(startDate.getTime( ) ) ;