javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Did you put that at the url: httt//:localhost:8085//webapp//jsp//index.jsp ?
Because it needs to be:
httt//:localhost:8085/webapp/jsp/index.jsp
Provided that the index.jsp file is at the right location.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First create 2 dies
Then make a button called roll
When roll is clicked
For i = 0; i < 36000; i++
Call random class for numbers from 1 - 6
and save that number as the first die
Call it again and save that number as the second die


If you want the actual code check my site below

This is not a place for you to advertise for free your site. Go away!

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The error is pretty clear:

Cannot invoke compareToIgnoreCase(int) on the primitive type int

String is an object, so it has methods that you can call, like: compareToIgnoreCase. But ints, as well as doubles, ... , are primitive types and don't have methods to call.
Why don't you use this:

private static boolean FloatLargestPriceToTop(Property[] data, int top)
   {
      boolean changed = false;
      Property temp;
      
      // notice we stop at length -2 because of expr. k+1 in loop
      for (int k =0; k < top; k++)
         if (data[k].price > data[k+1].price)
         {
            temp = data[k];
            data[k] = data[k+1];
            data[k+1] = temp;
            changed = true;
         }
       return changed;
   }
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You don't need the StringTokenizer:

BufferedReader br = new BufferedReader(fr);

int numOfVowels = 0;

String line = br.readLine();
while (line!=null) {

  char [] ch = line.toCharArray();  
  // loop the char array. 
  // for each character in the array, if you find a vowel increase the numOfVowels 

  // always the last command to get the next line, before checking again at the begining of the loop if it is not null
  line = br.readLine();
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This: for (int i = 0; i <= array.length; i++) Will throw an Exception. (i=0, ..., array.length)

This: for (int i = 0; i < array.length; i++) Will NOT throw an Exception. (i=0, ..., array.length-1)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well i tried it and it did...must have been something i did :P

What kind of code did you use? Because I find it strange and I am curius.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Write a for loop from 1 to 36000. Check the Random class and use the method return a random number twicwe in the loop. Once for the fist die and second for the second die.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

java.lang.NullPointerException
at javax.swing.plaf.basic.BasicListUI.updateLayoutState(Unknown Source)
at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(Unknown Source)
at javax.swing.plaf.basic.BasicListUI.getCellBounds(Unknown Source)
at javax.swing.JList.getCellBounds(Unknown Source)
at javax.swing.JList.ensureIndexIsVisible(Unknown Source)
at sun.swing.FilePane.ensureIndexIsVisible(Unknown Source)
at sun.swing.FilePane.doDirectoryChanged(Unknown Source)
at sun.swing.FilePane.propertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.awt.Component.firePropertyChange(Unknown Source)
at javax.swing.JFileChooser.setCurrentDirectory(Unknown Source)
at javax.swing.JFileChooser.setSelectedFile(Unknown Source)
at GalleryPanelTest.testGalleryPanel(GalleryPanelTest.java:35)

At line 35 of the file: GalleryPanelTest.java, inside the method testGalleryPanel, you are using something which is null.
Try to print all the objects you are using at that line amd see what is null.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Line 25: System.out.println(object5.mName()); , I doubt that the Month class has a method mName() .
What errors do you get and what are you trying to do?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What do you do when you login? Do you put the username into the session?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It is also could to close what you open. And you also forgot to return the array and increase the index 'i' :) . May I post some similar code?

public class UCTest{

	public String[] run() throws SQLException {
		Connection con = null;
                Statement stmt = null;
                ResultSet res = null;
                String[] test = null;
		try{
			con = new database().getConnection();
			stmt = con.createStatement();

			String sql = "SELECT * FROM test";
			res = stmt.executeQuery(sql);

                        int count = 0;
                        while(res.next()){
                            
                            count++;
                        }
                        
                        res.beforeFirst();
                        int i = 0;
                        test = new String[count];
			while(res.next()){
                            test[i] = res.getString("Q1");
                            //// Continue code from here for obtaining answers

i++;
                        }

                }catch(SQLException e){
                    e.printStackTrace();
                } finally {
                   if (rs!=null) rs.close;
                   if (stmt!=null) stmt.close; 
                   if (con!=null) con.close;
                 }
                 return test;
	}
}

And if you want to return more columns you'd better define a class with attributes the columns and return an array of that object.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The JButton's method (addActionListener) takes as argument an ActionListener interface. If you implement it and look at the API you will see that there is only one method to implement. Whenever you click the button that method is called automatically, so whatever code you put there would be executed.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

javaaddict when he does that wouldn't it return an array out of bounds exception error?

NO, NO, ..... NO.

Why would it?
In java indexes start from 0 till length-1: i=0;i<array.length;

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Because there is no such method. You cannot just invent methods on your own. Look at the API of the JButton.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

For a complete tutorial, look at the Read Me post at the top of the JSP forum that talks about the JSP Database Connectivity

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You have a constructor that has lots of arguments, but you don't pass them to your local variables: this.firstName = firstName; Remove the for loop that you have hanging in the class. It doesn't do anything.
You also don't need anything in the Address class so remove the main method.

In another class, have the main method. Create an array of Addresses or better a Vector of Addresses. Since you already have the Address class why use an array of firstnames?

Vector<Address> addS = new Vector<Address>();

Address ad1 = new Address(.....);
Address ad2 = new Address(.....);
....

addS.add(ad1);
addS.add(ad2);

In the main method put the code that loads and uses the Vector. Search this forum for examples on how to create a menu.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Look at the API of the java.util.Vector class.

In a separate class have a method that roughly does this:

{
Vector<YourObject> v = new Vector<YourObject>();

declare the Statements, ResultSet, .....
execute the query;

while (rs.next()) {
   String jobId = rs.getString("JOBID");
   String sector = rs.getString("SECTOR");
   ....
   create the object
   YourObject yo = new YourObject(jobId, sector, ....);
   v.add(yo);
}

close everything
return v;

}

Call the above method in the servlet, put it into the request and redirect to the page you want it displayed.

Vector<YourObject> v = call of the method
request.setAttribute("somename", v);
request.forward; // search for the syntax of that method on the net

To get the Vector at the jsp:

Vector<YourObject> v = (Vector<YourObject>)request.getAttribute("somename");
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Not to mention that you didn't even need to pass it as parameter because you already had it:

class ArrayGet
{
   [B]int[] a = new int[20];[/B]
..
}

In the same way you call the Display() with no arguments and it takes the correct global array a[], the same you will call the FindMin() . Remove the argument from the declaration. You already have the array inside it.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Learn to use code tags. click the CODE button, when making a post.

Always do this:

double[] array = new double[201];
for (int i = 0; **i < array.length**; i++){

when you print the array values, do you get what you wanted? Is the total sum correct? The code looks ok, What errors do you get?
Calculate the sum with a piece of paper and see if the sum is correct.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you looked at the printStackTrace ?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Quite a snobby reply - people that ask this type of question are obviously new...
..thanks.

If they are new then jsp pages are rather complex for them and they shouldn't even try them, especially if they don't know that equals is used for comparing Strings. Such understating is the essence of the OOP because it distinguish Object to primitive types.
Learning the basics is more important, than just giving an answer that will solve one line of error

Would you lend your 20,000$ Harley to someone that doesn't know that a bicycle has 2 wheels?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The rs is of type ResultSet, the "" is type String. Why do you think that this : rs.equals("") will work, since you are comparing a ResultSet object with a String object. If the query returns no data, then the first call to the rs.next() will return false.

Also it is better to read the database, put the results into a collection (Vector) of objects, and then send that object to the jsp to display it. Never use a servlet for displaying.
Have an object with attributes: JOBID, SECTOR, LOCATION, SALARY, EMAIL, DESCRIPTION, COMPANY

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

How exactly did you write this:

out.print=(String)session.getAttribute("ana") //it prints null

In your code?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you written any code? Look at your requirements:

-Load the data into from a file into an array of address book

So create an AddressBook class. Personaly I don't like the name of the class given by the assignent, because an AddressBook has many entries, but assume fot the exercise that AddressBook is one entry, with data for the person and you will have an array of AdressBooks.

What attributes will the AddressBook have? Write seperate methods that do what is asked in each of the requirements and then have one array of AddressBooks and call them.

Search this forum for examples on how to read files and how to create menus

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Post some lines of the file

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you don't know that the first method is the constructor and that it creates an array of bytes, then there is no point in continuing explaining when all you need to do is some studying on your own.

The code does what it does. It has for-loops, while-loops and it executes the commands one by one. Read the API of the classes that it has. Because the only thing we could do is repeat what the API says.

Example:

read = f.read(_block,0,_blockSize);

'f' is type InputStream from the method processBlock.
Look at the API of the InputStream and read what that method does. If we read the API and repeat the same thing will not do any difference. Only that we will be the ones spending our time searching the net.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Where are you having problems:
- Convert excel to csv
- Read values
- Save to DB

Those are different unrelated issues. You can do one without having done the other.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Thanks. Maybe that'll help.
But, what exactly is the difference between Button and JButton?

I don't know. But it is better to use the latest J classes.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to add an actionListener to the button, so when it is clicked a method would be called.
Look at the API for the Button and for ActionListener.

Also try to use the swing package: javax.swing.*
And the classes: JFrame, JButton, ....

Also it is good to read some more current tutorials about GUI, because your way is not the best way.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to find a way to read the excel file. Once you do that, then it is easy. Call methods that save values to the database and pass as arguments the values read from the excel.

You will need 2 different things. Write methods that write to the database.
Find a way to read the contents of an excel file.

What exactly is your problem?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

'd' is not an array.

Just study some basic java on how to declare variables and arrays.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

count1 is non static. It is an attribute of the MergeSort1 class and must be called the way the non static methods are called:

MergeSort1 marr = new MergeSort1(maxSize);
System.out.println("Number of comparisons: " + marr.count1 );

When you are inside the class MergeSort1 you are ok, because it is a member of that class. But in the main you create an instance of that class, so you need to access the count1 of that class:

MergeSort1 marr1 = new MergeSort1(maxSize);
marr1.count1;

MergeSort1 marr2 = new MergeSort1(maxSize);
marr2.count1;

MergeSort1 marr3 = new MergeSort1(maxSize);
marr3.count1;

Those 3 count1s are different. Each one belongs to their instance and it is not a rule that they will have the same value. For different arrays they will return different results

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The updateHealth method is of the LittleAlien class, so in the method Caught, you can do this:

public void Caught(LittleAlien aLalien)
{
   aLalien.updateHealth();
}

Also more code would be required. And I don't think that LittleAlien should extend BigAlien, but I could be wrong. Post your requirements as well.

ttboy04 commented: 1 +1
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When A.jsp first loads the V is null. So you can do this:

<%
String V = request.getParamater("V");
if (V==null) {
%>

<form onsubmit="return validateSelect()"action="Select.jsp" method="get">
<h2>Select:</h2>
<h3>Enter the URL of the publisher you perfer to publish your ads on: </h3> <br/>
<input type="text" name="SUrl" style="width: 250px;" />
<input TYPE="submit" value="Submit"/>
<input type="hidden" name="V"/>
</form>

<%
} else {
.....
}
%>

There is method called: request.forward ,
if I remember; check it out. To send the V value through a url at the second page use:

String V = request.getParamater("V");
String url = "A.jsp";
if (V!=null) url = url + "?V="+V;

Also it is better not to have multiple forms in a jsp and if statements to determine which to display. Have different jsps, and at the second page, depending on the value of V decide which one to load.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I would suggest to remove the final and make it private. Then add a public method that returns its value.

private static String EXIT=ButtonConstant.getString("BUTTON_CONTENT");

public static String getEXIT() {
  return EXIT;
}

With that way the value changes, but no one can change it programmatically

If this doesn't work, I think it won't, you can try this:

public static String EXIT() {
  return ButtonConstant.getString("BUTTON_CONTENT");
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

yup. i got it!!

1) To get d item from dorpdown menu:
String tvalue_str=(String)t2.getSelectedItem();

2) this is d way i write to display the selected item :
int3.append("Value of T ="+tvalue_str+"\n");

thanks sennat_26

I would like to add that in the same way you added String to the JComboBox, you can add objects:

class SomeObject {
  // many attributes
}
JComboBox t2 = new JComboBox();
// add some SomeObject objects to the JComboBox 


SomeObject so = (SomeObject)t2.getSelectedItem();

Also what will be displayed at the JComboBox will be determined by the toString method of SomeObject class. So don't forget to override it:

class SomeObject {
  // many attributes

  public Stirng toString() {
    return ""; // return whatever you want to be displayed at the options of ComboBox
  }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The API is there for you to read it, not learn it by heart.

As long you know how to call methods with the right number and type of arguments and put the return value inside the right type, you are ok.

Of course that doesn't mean that for every single method you need to look at the API. With extensive use some of the methods you learn them. But If you want to do something different, you don't have to remember everything, just where to find the method that you want.

And I don't believe that anyone knows the entire API even if it is the core java. If such person existed, he wouldn't know nothing about programming, because he would have wasted all his time in learning methods by heart instead of using them.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Your method is returning a single double, rather than a double array, and you index into an array, not a double.

Look at masijade's post. And you made the same mistake to another of your posts.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

'd' is a double, not an array.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then add to the sum the totalTakings

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

oks, it seems we are at peace here.
see you around

Ok, No problem.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to set the appender of the logger:
log4j.properties file:

log4j.logger.log_name=debug, F

log4j.appender.F=org.apache.log4j.DailyRollingFileAppender
log4j.appender.F.File=full_file_path/file.log
log4j.appender.F.DatePattern='.'yyyy-MM-dd

Every day the old file will be renamed according to the pattern, Look at the API for the class: org.apache.log4j.DailyRollingFileAppender and for the Logger class.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Yes there is a function that takes in an int and the object.But my vector is of a particular datastructure and I want to just enter a string in that row.Also i want to get the row dynamically..in the program.How do i achieve that?

You could do this:

Vector v = new Vector();
v.add("1");
v.add(someObject1);
v.add(someObject2);
v.add("2");

for (int i=0;i<v.size();i++) {
   Object obj = v.get(i);
   if (obj instanceof String) {
          // seperate rows
   } else if (obj instanceof SomeObject) {
       SomeObject so = (SomeObject)v.get(i);
   }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I haven't looked at the code but only this part:

pictures = reader.nextInt();
...
title1 = reader.nextLine();

This is why I never use the nextInt methods and I prefer this:

pictures = Integer.parseInt(reader.nextLine());
...
title1 = reader.nextLine();

So here is what happens because it has been discussed many times in previous thread.

You call nextInt, and enter this:
>4
But the nextInt doesn't change lines.
So you read the '4' but the "cursor" doesn't change lines!
The moment you enter <ENTER> you get the '4' and the Scanner waits for the next input AFTER the 4:
>4|
Then you call nextLine. That would mean that scanner will read what is after the 4 until the next END_OF_LINE, which is empty:
>4|.
Then the second call of the nextLine will read what is at the 2nd line till the end:
>4
>name

A solution would be this:

pictures = reader.nextInt();
reader.nextLine();
if (pictures==4) {
   title1 = reader.nextLine();
} else if (...) {
   title1 = reader.nextLine();
} ...
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

what errors do you get after running the code? The toString method seems fine. If it doesn't work, then maybe the problem is in the way you put data at the queArray and the way you define the front, rear

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you look at the API of the Vector class you will see that there is a method that lets you add an element at a specific place. I think it is like this:

add(int i, Object obj);

Look at it, but if I remember correctly, it adds it to the int "place" and whatever was at that place it is shifted to the "end"

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In the main you create 2 instances of the class: TicTacToeGame. Shouldn't you be creating TicTacToeplayer instances?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What do you mean "without a set amount of rolls" ?
You roll the dice and add it to the list. Then you roll it add it again.
But you have to stop eventually.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I am sorry for not reading the entire post. I focused on the code.
...
I think I noticed something that might be the solution. Maybe by the time you read this, you have seen it too, or it is just a typo while you were posting the code:

<select name="[B]lista1[/B]" id="lista1"></select><br/>

String name1 = request.getParameter("[B]list1[/B]");

Try this: String name1 = request.getParameter("[U]lista1[/U]"); Instead of this:" String name1 = request.getParameter("list1"); If this doesn't solve your problem, can you post some more code?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I can't understand the second question. For the first:

Date date = new Date();
// or
Calendar cal = Calendar.getInstance();

Look at their APIs.
http://java.sun.com/j2se/1.5.0/docs/api/java/util/package-summary.html