javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In that case, I would assume that there is something wrong with the sort method.
Write a small program in another class:

class Test {
 public static void main(String [] args) {
   int [] array = { 
    63, 44, 55, 83, 71, 93, 91, 95, 62, 97, 12, 57, 7, 35, 50, 30, 49, 41
     /* put here the numbers you want to sort */ 
   };
   // call the sort method
   // print the array
 }
}

Check if the sort method works. Post the code of the sort method as well as the results of the above code

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need first to populate all the array and then sort. What you do is this:

for () {
 array[i] = number;
 sort;  
}

But with that you put the first number and you sort an array that has only 1 number. Then you add a second number and again you sort an almost empty array.
First finish with populating the array with all the numbers and then sort the full array.

When you say you get a lot of zeros when that happens? What is saved in the file? What is printed.

Also I think that you should write your own sorting method. But you'd better ask your teacher if you can use the Array.sort method or write your own.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can you try to print the pbeKeySpec value and see what it has?
Also is there any specific reason that you need to read the input character by character and then copy it to another array? Can you just use the Scanner class to read the whole line and get the password?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Yes but this: 2323237777777 is an int. And int numbers can not handle that; it is too big.
This is a long: 2323237777777L

long me = 2323237777777L;
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you want to add a picture at the GUI, you need to look at the API of the JLabel class.
It has a constructor that takes as argument an Icon. Or you can the method: setIcon. From the API the argument (Icon) is an interface, so you need to look at the class ImageIcon that implements the Icon interface.

So create an ImageIcon instance with your image and put it to a JLabel. Then display that JLabel.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Check out the indexOf method of the String class:

String s1 = "www.google.com/search/"
String s2 = "google"

int index = s1.indexOf(s2);
System.out.println(index); // 4

If "index" is -1 then the s2 is not inside the s1. Else it returns the position of the s2 inside the s1, which is 4. "google" starts at the 4th character in the s1 String (starting from 0)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

it returns something like

com.login.entry.dao.UserInfo@7f906b

n times

That is not null. And read my previous comments:

If you are going to call the toString method better override it in your UserInfo class because what you call is the inherited method of the Object class.

What you get is what the toString method of the Object class returns, because you haven't overridden it in your class.
And you shouldn't be using that in the first place. Use the get methods to display whatever you want.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In the catch block, you set the LoginEntryException to be null and then you one of its methods. That will give you a NullPointerException. What is the point of setting something to be null and then use it. You need to initialize it. Just do e.printStackTrace and see what is going on. There are exceptions that you don't print

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You are calling the next method twice, without checking if it has a next element:

out.print("coming..................:"+itr.next());
out.println(itr.next().toString());

The first next call will return since you did that check at the while, but the second will not because you take the next element and you don't know of it has one.
If you are going to call the toString method better override it in your UserInfo class because what you call is the inherited method of the Object class.
Also you need to pass allUsers instance at the request to a jsp page. Then iterate, take each object and use the get methods. What is the point of having get method if you are not going to use them.
Check the method: request.setAttribute("users", allUsers)
At the jsp do:

List<UserInfo> users = request.getAttribute("users");

Check the RequestDispatcher class to send the above request to a jsp.

After you got the users instance use a loop to get each element and then use the get methods to create a table. Check the <table> tag.

And don't use this:

out.print("..");
out.println("...");

Don't use servlets to display data at the browser.

Check the tutorials at the top of the JSP forum

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Your code is unformatted and you failed to indicate where the error is. Reade the error messages that you get. Don't expect others to do it for you:

Exception in thread "main" java.lang.NullPointerException
at Bank.main(Bank.java:25)

At the file Bank.java line 25 you got a NullPointerException. You are trying to use at that line something which is null. Make sure that at the line all the objects are initialized and have value.

What line is it at your code.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at TheatreRevenue$CalcButtonListener.actionPerformed(TheatreRevenue.java:99)

At that line and file: TheatreRevenue.java:99 you are using something which is null. Go to tha line and see what is null and make sure it is initialized.

Also the code tags you are using should end with

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Better use the log4j.properties option better. Or if you look at the API you can programaticaly configure the log4j.

Also check this out:
http://www.vipan.com/htdocs/log4jhelp.html

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It is not good to add the throws exception at the main method. Exception are meant to be caught and handled, not thrown at the main. Also the close needs to be in a finally. But if you try this:

try {
     BufferedWriter bw = new BufferedWriter(new FileWriter("write.txt"));
} catch (IOException ioe) {
     System.out.println(ioe.getMessage());
} finally {
    bw.close();
}

It will not compile because the BufferedWriter is declared in the try and it is not visible in the finally. So declare it outside the try, so it will be visible in the finally, and initialize it in the try.

You will also need an extra try, catch because bw.close() also throws an exception, so:

} finally {
    try {bw.close();} catch (Exception e) {/*you don't need anything here*/}
}
import java.io.*;
      class Writefile{

      public static void main(String []args) {
            // Declared here
            BufferedReader br = null;
            String name = null;
            BufferedWriter bw = null;
try {
      // Initialized here
      br = new BufferedReader(new InputStreamReader(System.in));
      bw = new BufferedWriter(new FileWriter("write.txt"));

      System.out.println("Write into the file write.txt. To finish typing input \"end\".");

      while(true){ //loop continues unless typing in the "end" line
        name = br.readLine(); // read each line of strings you typed in

        if (name.equals("end")) // check the content of input. If it is "end"
            break; // then jump out of the while loop
    
        bw.write(name);
        bw.newLine(); // for changing line when writing to a file.
      }

      bw.close();
} catch (IOException ioe) {
  System.out.println("Error: "+ioe.getMessage());
} finally {
    // finally start …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try to read what the hashCode method really does and what it is used for.
Check the API of the Object class, as well as the API of the HashMap.

Also don't use '==' to compare Strings. Use the equals method of the String class. And you also need to check, in the equals method that o and name are not null, before calling any method on them.
The d1, d2 will not be equal with the way you have defined the equals method.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

From the errors I assume that we are dealing with Applets so there shouldn't be any main method. If you want to use something anywhere then declare it, create it and initialize it.

Without some code to go with the errors it is difficult to suggest anything than speculations

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

what error do you get ?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

can you tell me why we create constructor?

We use/call constructors to create instances of objects. In that way we can call the methods of the class.

We define different constructors for different functionality based on their arguments.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This is a java forum. What you wrote is javascript

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try to print the query, and then take it the way it is and run to an sql editor:

String q="select order_num from Order where recev_fname='"+itemn+"'";
System.out.println("Qeury: "+q);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You do this: crt.CusDetails.derCusData and this: crt.derCusData.derCusData

What type are the crt, CusDetails, derCusData.
Is CusDetails inside the MyShoppingCartNew like an inner class? If yes then you don't need that.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

That is not how you call methods:

crt.CusDetails.derCusData(String fname,String sname,String phone,String email,String address1,String street,String address3,String area,String ddate,String dtime)

Your error is very basic and has nothing to do with jsp or web programming. I don't want to sound harsh but if you can't fix this error then you go back to learn better the basics.

In case in was an honest mistake that you just missed and didn't correct it even if you knew the answer then that is ok.

It is up to you to decide what you need:

crt.CusDetails.derCusData(fname,sname,phone,email,address1,String street,address3,area,ddate,dtime)

Also after that line you do this:

int crt=crt.getcost();

That is no correct either. You declare an int: crt, and you have above another variable with the same name: crt.CusDetails

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In One jsp have the form with all the fields and a submit button:

<form [B]action="two.jsp"[/B] name="someName">
.....
<SELECT name="month">
  <OPTION selected value="01">1</OPTION>
  <OPTION value="02">2</OPTION> 
</SELECT>
.....
<input type="submit" value="I authorised this transaction">
</form>

And in the other jsp:
two.jsp

String monthSelected = request.getParameter("month");
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/java/math/BigInteger.html

//BigInteger(String val)
//Translates the decimal String representation of a BigInteger into a BigInteger.

BigInteger bi1 = new BigInteger("123123414123412341241243");

If you look at that link you will find the methods that do what you want. Create 2 BigInteger objects and then call the methods you want:

BigInteger bi1 = new BigInteger("123123414123412341241243");
bi1.method(<argumnets>);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Just look at the API of the class BigInteger. Use the constructor to create the object and use the methods it has for adding, subtracting, ....

BigInteger bi1 = new BigInteger("123123414123412341241243");
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you tried looking at the BigInteger class:
http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/java/math/BigInteger.html

Have you looked at the link I provided?
What is the point of making questions if you don't bother to read people's answers?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Posting the error message that you get, would help a lot.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You have 2 for loops one inside the other. And if you omit the code inside them you get something like this:

for (count=0;count<11;count++) {
  for (count=0;count<frequency.length;count++) {

  }
}

You are using the same variable to access two entire different arrays. And the fact that they might have the same length doesn't mean anything. When the inner loop finishes execution the count would have the value of frequency.length. Then its value will increase because of the outer loop and since it is not lower than 11 the outer loop will exit.

Try using this code from now on:

int[] array = new int[11];

for (int count=0;count<[B]array.length[/B];count++) {
  array[count]
  ....

  for (int k=0;k<[B]frequency.length[/B];k++) {
      frequency[k]
  }
}

Never hard code numbers.


Also another error:

input = JOptionPane.showInputDialog( "Enter a number between 0 - 99: ");
        num = Integer.parseInt(input);
        while (num < 0 || num > 99)
        {
          JOptionPane.showMessageDialog( null, "Must be between 0 and 99",
                                        "ERROR!", JOptionPane.ERROR_MESSAGE );
         num = Integer.parseInt(input);
         input = JOptionPane.showInputDialog( "Enter a number between 0 - 99: ");//Suggested by professor Imroz.
        }

num = Integer.parseInt(input)
input = JOptionPane.showInputDialog( "Enter a number between 0 - 99: ")

If the number is not between 1,99 then you should ask the user for a new number. But you first use the same input, which would be wrong, and then you ask for a new input.
Imagine entering -10, (input="-10", num=-10)
You go inside the while and after the …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It should be && instead of ||
And why do you use the + It is not necessary.
Also you don't need this:

(uInput1 > uInput2 || uInput1 > uInput3)? +uInput1: +uInput2

If the uInput1 is not the max, then why do you assume that the uInput2 is the max?
Use simple if-else if-else statements

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Also, you put "pieces" in some of the elements of the array. The rest are unfilled, so they are null. I would suggest to fill all the array with empty Strings "" in order to avoid the NullPointerException.
Then put to the elements you want the "pieces".

And if you want to compare them use the equals method:

if (jPieces[x][y].equals("wPawn")) {

}

Also whenever you move a piece, put an empty String "" at the previous position after you have moved the piece to the new position

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Actually you have a small misunderstanding with that logic. The API says:
"The ordering imposed by a Comparator c on a set of elements S is said to be consistent with equals if and only if "

The API says at some point that the compare method does not have to be consistent with equals. Even if you implement it, you don't have to make sure that when equals returns true the compare method will also return 0.

The API only said:
"The ordering imposed by a Comparator c on a set of elements S is said to be consistent with equals if and only if "
They don't have to have the same behavior. It simply stated that if you want to say that they are consistent, the equals must behave like the compare. If they don't then that is also ok.

Also this: "if the compare function serves the test for equality too"
That is wrong. Just because 2 objects are equal with each other doesn't mean that their compare methods will return 0 and the other way around.

And we do need both.
Equals for determining equality and compare for sorting. Some classes like java.lang.String are consistent. The compare method and equals method have the same results. Others not.

And a practical example why they are different:
Assuming you have a person class with an id and a name:

class Person {
  private int id …
stephen84s commented: Good Explanation +5
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Check the API of ArrayList. Never assume that classes and methods do what you think they do. The argument you have specified is the initial capacity of the ArrayList, not the size.

Check the constructors of the ArrayList class.

From the API:

Each ArrayList instance has a capacity. The capacity is the size of the array used to store the elements in the list. It is always at least as large as the list size. As elements are added to an ArrayList, its capacity grows automatically. The details of the growth policy are not specified beyond the fact that adding an element has constant amortized time cost.

An application can increase the capacity of an ArrayList instance before adding a large number of elements using the ensureCapacity operation. This may reduce the amount of incremental reallocation.

Every time you add an element, the size of the list increases. When the size reaches its initial capacity, the list increases its capacity by a default value. Then you keep on adding elements and if you reach again its capacity, it will again increase.

Meaning that if you have the initial capacity to be small (in your case 2) and you add 1000 elements, then you will have many increases which takes time.
If you use a large initial capacity(2000) then the add method calls will be fast. Not many increases would be needed, but you would have wasted a lot of space.

In general for small applications …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Check the constructor of the class java.util.Date at the API. I doubt the there is one that takes as argument the String that you are trying to pass
txtFieldArray.getText()

Check the API of java.util.Date as well as the class: java.text.SimpleDateFormat
And you will get your answers:
http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The only thing I see commented is the JColorChooser not the JFileChooser.
Can you make that clear? I am talking about the first few lines of the openFile method.
All the JFileChooser are there. Do they work?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

r u a nut chirag.
have u ever used netbeans? i dont think so .

you r totally wrong.

No he is not wrong. He is absolutely right.
You cannot run a java file. When you click the run button at the NetBeans (something that anybody can do), Netbeans creates a jar file with all the classes of the projects and it runs the jar files.
Practically it runs the .class file.

> The original poster asked how to run the program from outside the Net Beans.
What if you make a program and want to run it to another computer? Will you carry the entire Net Beans installation with you.
Or do you think that if someone has a project and they want to run it, they open first the IDE, then load the source code and the click the run button. I am sure that nobody has ever thought something better.

Perhaps this:

c:\yourfolder> javac filename.java
c:\yourfolder> java filename

Now that is something that apparently not anybody can do

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

U have to do it by your self my dear
and submit to me in ur class on Saterday

Regard
Ms.Kavita

If this post is for real then 2 thumbs up. LOL!

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What you are trying to do is very simple and explained in all basic GUI tutorials. Try to search some at the site of SUN

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In one code you do this:

System.out.println(moviesList.get(1).printMovies());

Which is correct.
And at the other, you do this:

inputLine = n_moviesList.get[i].printMovies();

which is wrong.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You hardly use session. Maybe you should put it in request and use request dispathcer to send the request to another jsp or servlet.
Use the request.setAttribute(String, Object) and the request.getAttribute(String)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When the button is clicked you can hide, or better dispose(I think that that is the name of the method of the JFrame class) and create new window.

class JLogin extends JFrame ... {

..

  public void methodUsedWhenLoginButtonClicked(ActionEvent evt) {
      JMainPage mainPage = new JMainPage();
      mainPage.setVisible(true);
      this.dispose(); // use this if you don't want to keep the state of the class. Meaning if you want to close completely the window and forget lose all the values of its attributes.
  }

..

}

For making a back-forward page:

class JFirstPage extends JFrame .... {
   private JSecondPage secondPage = null;   

   public JFirstPage() {
     super();
     ......
   }

   public void buttonClicked(ActiobEvent evt) {
      this.setvisible(false); // hiding this window
      if (secondPage==null) secondPage = new JSecondPage(this); // passing it to the next window
      secondPage.setVisible(true); // showing the next window
   }

}
class JSecondPage extends JFrame .... {
   private JFirstPage firstPage = null;   

   public JSecondPage(JFirstPage firstPage) {
     super();
     this.firstPage= firstPage;
     ......
   }

   public void buttonClicked(ActiobEvent evt) {
      this.setvisible(false); // hiding this window
      firstPage.setVisible(true); // showing the previous window. Keeping ALL the values it had (the values of the text fields or anything else)
   }

}

With the first way you "dispose" the window and you lose the values it had and if you want to open it again, you need to make a new one.

With the second way you pass the same instance to the other window through the constructor and you can hide or show which ever window you want

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You don't initialize c by calling its methods. You need first to initialize it then call them. c is null, you only created the array, not its elements:

c = new College()

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

ok..but I'm trying to initialise c using the read(); is there something wrong with that ?

How are you going to call the read() method if the c doesn't exist!
Study how object are initialized. Obj o = new Obj()

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

No, c is an array of objects. c is the object which is null because you haven't initialized it. c is null, c is a College object, c is an array

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
<%
String init= "3";
%>

<select name="dropDown">
  <option value="1" <%= ( "1".equals(init) )?"selected":"" %> >One</option>
  <option value="2" <%= ( "2".equals(init) )?"selected":"" %> >Two</option>
  <option value="3" <%= ( "3".equals(init) )?"selected":"" %> >Three</option>
  <option value="4" <%= ( "4".equals(init) )?"selected":"" %> >Four</option>
  <option value="5" <%= ( "5".equals(init) )?"selected":"" %> >Five</option>
</select>

Although it is better to use a for loop for these things (<select>)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I would suggest to make these changes:

for (int i = 0; i < schoolofdbTables.length; i++) {
            PreparedStatement ps = null;
            String query = "";
            try {
               query = ModelUtils.getXMLResource(schoolofdbTables[i].trim());
                ps = (PreparedStatement) conn.prepareStatement(query);
                ps.execute();
                bCreatedTables = true;
                ps.close();
               System.out.println("created table: "+schoolofdbTables[i]);
            } catch (SQLException ex) {
                ex.printStackTrace();
System.out.println("Table was not created: "+schoolofdbTables[i]);
System.out.println("Error at:"+schoolofdbTables[i]+":"+query);
            }
        }

With that way you can see which query went wrong. With your code the System.out.println("created table: "+schoolofdbTables[i]); was always executed because it is outside the try-catch.

Also the errors tell you the line of the file that occured. Check it out. And it is good to print the query run. Try the code again and see the queries that went wrong.

java.sql.SQLException: SQL text pointer is null.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.newSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement40.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver40.newEmbedPreparedStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at model.dao.ConnectDerbyDAO.bCreatedTables(ConnectDerbyDAO.java:193)
at model.dao.ConnectDerbyDAO.createDatabase(ConnectDerbyDAO.java:149)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The String class has the charAt method. "Loop" the String using its length and get each character of the String.

Then if you take that character and put it into an int, you have the ASCII:

for-loop {
char ch = yourString.charAt(i);
int ascii = ch;
System.out.println(ascii);
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I removed anything pertaining to user or password from my properties as I believe that it will be needed for the user to access the db.

I think it is connected now.

would any of this output suggest it is connected?

You wrote the code and you want it to do something. Why don't you check the database and see if the query did what you want. Create the table for example.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't know if I understood correctly or you already know it. You are supposed to enter the username, password of your own database. Are you saying that the sa, manager are just examples from some code snippet?!

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Post your latest code

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This is the html code you are displaying at the page:

<a href=\"welcome.jsp\"> </a>

But there is nothing between the <a> </a> , so the link is there and you can click it. The problem is that you don't display anything to show the user where the link is:

<a href=\"welcome.jsp\">Click me</a>

And finally. DON'T DO THAT. Remove the code you have in the welcome.jsp. Put all the database code in a separate class inside a method. Call that method from the jsp. And I would suggest if the login is successful not to show a link that goes to the same page.

From your code you send the username, password to the welcome page, and if the login is successful you again show a link to go to the welcome.jsp. Shouldn't go to the main page?