String array sort

String array sort

Hi here is my code. If i run this code I am getting exception as java.lang.NllPointerException. I think its because of at the line Arrays.sort(route_number1). Please suggest some solution for this.

<html>
<body>

<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.util.Arrays"%>
<%@ page import="java.text.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<%@ page language="java"%>
<%@ page session="true"%>
<%
    Connection connection=null;
    PreparedStatement prepared_statement=null;
    ResultSet result_set=null;
    String route_number[]=new String[1000];
    String route_number1[]=new String[1000];
    route_number1[0]=" ";
    int counter=0,count=0;
    try
    {
        String url="jdbc:mysql://localhost:3306/bus";
        Class.forName("com.mysql.jdbc.Driver");
        connection=DriverManager.getConnection(url,"mysql","mysql");

        response.setContentType("text/html");
        prepared_statement=connection.prepareStatement("select * from bus_tab");
        result_set=prepared_statement.executeQuery();

        while(result_set.next())
        {
            route_number[counter]=result_set.getString("route_number");
            counter++;
        }
        int k=0;
        /* The following for loop is to identify the duplicate values in the source and replace it as null*/
        for(int i=0;i<counter;i++)
        {
                    for(int j=i+1;j<counter;j++)
                    {
                            if(route_number[i].equals(route_number[j]))
                            {
                                    route_number[j]=" ";
                            }
                    }
        }
        /*The following for loop is to remove the null from the source array*/
        for(int i=0;i<counter;i++)
        {
            if(!(route_number[i].equals(" ")))
            {
                route_number1[k]=route_number[i];
                k++;
            }
        }
                Arrays.sort(route_number1);

    %>
<form action="../bus/route_search.jsp">
  <table width="297" height="123" border="0">
    <tr>
      <th height="63"><p class="style5">Route-wise Information</p>
        </th>
    </tr>
    <tr>
      <td width="100" bgcolor="fc8895">Route No:</td>  
      <td width="96" bgcolor="fc8895"><select name="route_number">
      <%
        for(count=0;count<k;count++)
        {
        %>
                <option><%out.println(route_number1[count]);%></option>
        <%
        }
        %>
        </select></td>
    </tr>
    <tr bgcolor="#FC8895">
        <td>

            <input type="submit" name="Submit" value="Search">
           </td>
          <td>

              <input type="reset" name="Reset" value="Reset">
              </td>
    </tr>
  </table>
  <p>&nbsp;</p>
  </form>
  <%
        }
        catch(Exception e)
        {
            out.println("Exception:  "+e);
        }
        finally
        {
            connection.close();
            prepared_statement.close();
            result_set.close();
        }
  %>

</body>
</html>
View Answers









Related Tutorials/Questions & Answers:
string array sort
string array sort  Hi. How to sort a string array
string array sort
string array sort  Hi. How to sort a string array
Advertisements
string array sort
string array sort  Hi. How to sort a string array
string array sort
string array sort  Hi. How to sort a string array
string array sort
string array sort  Hi. How to sort a string array
String array sort
String array sort  Hi here is my code. If i run this code I am... result_set=null; String route_number[]=new String[1000]; String route_number1[]=new String[1000]; route_number1[0]=" "; int counter=0,count=0
String array sort
String array sort  Hi here is my code. If i run this code I am... result_set=null; String route_number[]=new String[1000]; String route_number1[]=new String[1000]; route_number1[0]=" "; int counter=0,count=0
Merge Sort String Array in Java
Merge Sort String Array in Java  Hello, I am trying to implement a merge sort algorithm that sorts an array of Strings. I have seen numerous examples of merge-sorting integers but i can not understand how to this with String
Java insertion sort with string array
Java insertion sort with string array In this tutorial, you will learn how to sort array of strings using string array with Insertion Sort. For this, we...++){ System.out.println(sortedArray[i]); } } public static String[] sort_sub(String array[], int
Array sort
Array sort  Program that uses a function to sort an array of integers
php array sort by field
php array sort by field  Array sort by field in PHP
php array sort by key
php array sort by key  php script to sort array by key
php array sort by value
php array sort by value  an example to sort the array by value
php array sort functions
php array sort functions  Sort function in php
array sort - Java Beginners
array sort  hi all, can anybody tell me how to sort an array...; } } public static void main(String a[]){ int i; int array... array[], int len){ for (int i = 1; i < len; i++){ int j = i
array string
array string  how to sort strings with out using any functions
array to string
array to string  hello how to assign value from array to string. nsstring *abc = [array objectAtindex:1];   you can use this codeADS_TO_REPLACE_1 NSString *abc = [NSString stringWithString:[array objectAtIndex:i
string array
string array   Hi hw to print string array element in ascending r... StringArray { public static void main(String[] args) { String arr...); System.out.println("Array Elements in Ascending Order: "); for(int i=0;i<
array of string
array of string  Waht is the problem in this code? import java.util.Scanner; public class LastCheck { public static void main(String args[]){ int a; Scanner s= new Scanner(System.in); a=s.nextInt(); String ar[]=new
sorting an array of string with duplicate values - Java Beginners
sorting an array of string  Example to sort array string
php array sort
PHP Array sort function is used to sort the given array in ascending order. Example of PHP Array Sort <?php $ar1=array("jack","mac","rock","barak");ADS_TO_REPLACE_1 sort($ar1); foreach ($ar1 as $a) echo " ".$a;ADS
string array based problem
string array based problem  R/sir, firstly thanks to help me so much. but now it can sort string very well but in case of integers... string: "); String[] array = new String[5]; for(int i=0;i<5;i++){ array[i
PHP Array Sort in Reverse Order
PHP Array Sort in Reverse Order  Hi, I have just started learning... the PHP Array Sort in Reverse Order. Please suggest any online reference or example... programming language there are three types of functions used to sort the array
array and string based problem
array and string based problem  this program is accepting only... main(String a[]){ Scanner input=new Scanner(System.in); int array[]=new..."); System.out.println("Values Before the sort:\n"); for(i = 0; i < array.length; i++){ array
array and string based problem
array and string based problem  this program is accepting only... main(String a[]){ Scanner input=new Scanner(System.in); int array[]=new..."); System.out.println("Values Before the sort:\n"); for(i = 0; i < array.length; i++){ array
array and string based problem
array and string based problem  this program is accepting only... main(String a[]){ Scanner input=new Scanner(System.in); int array[]=new..."); System.out.println("Values Before the sort:\n"); for(i = 0; i < array.length; i++){ array
sorting an array of string with duplicate values - Java Beginners
sorting an array of string with duplicate values  I have a sort method which sorts an array of strings. But if there are duplicates in the array it would not sort properly
JavaScript array sort alphabetically
JavaScript array sort alphabetically       We can sort the JavaScript array elements by using the sort() method of Array class in JavaScript. Syntax of the sort method
C array sort example
C array sort example       In this section, you will learn how to sort an array in C. For sorting...;i;   qsort(array, 10, sizeof(int), sort);   
php parse string into array
php parse string into array  How can i parse a string into array and convert an array into string
String sort() Method
String sort() Method       In this program you will learn how to sort words in a String... have used sort(); method to sort that array of characters.  The code
Array /string based problem....
Array /string based problem....  thanx to help me.but again a problem...("Enter string: "); String[] array = new String[5]; for(int i=0;i<5;i...]+" "); } } static String[] selectionSort(String[] array) { for (int i = 1
JavaScript array functions sort
JavaScript array functions sort   ... to understand the concept of JavaScript array function sort. The code create... to array. The function show( )  include array. sort( ) method. array. sort
JavaScript array sort numerically
JavaScript array sort numerically   ... alphabetically we have used the default sort method to sort array elements but here... array sort() numerically </title> <script type="text/javascript">
JavaScript split string into array
; Description: The split() method is used to split a string into an array...JavaScript split string into array  How to split the string into array?   <html> <head> <title></title> <script
String Array - Java Beginners
String Array  From where can I get, all the functions that are needed for me to manipulate a String Array. For Example, I had a String Array ("3d4..., as to by which method can I separate the Integers from this Array of String
PHP Sort Array
PHP Sort Array: Sometimes we need to store data in a single entity called... array, how to sort values of an array, and how to sort the keys... to know how to use array in PHP. PHP Sort Array Example: <?phpADS
String Array - Java Beginners
for me to manipulate a String Array. For Example, I had a String Array ("3d4..., as to by which method can I separate the Integers from this Array of String... this question to you before, now the problem comes if my String Array consisted
Array List and string operation
Array List and string operation  hi, I want to search an arraylist element in a a given file. example I have a name called "mac" in my arraylist and I have a txt file which contains mac, how many times "mac" appears in the txt
array split string
array split string  array split string   class StringSplitExample { public static void main(String[] args) { String st = "Hello_World"; String str[] = st.split("_"); for (int i = 0; i <
array, index, string
array, index, string  how can i make dictionary using array...please help
String Array
Java String Array      ... how to make use of string array. In the java programming tutorial string, which... in this program we are going to use string type array. We have to used array as data
String Array - Java Beginners
String Array  Thanks for the help you had provided,,, Your solution did worked... I worked on the previous solution given by you and it worked.... I am able to solve the question with that, that's in front of me..... Thanks
java String array - Java Beginners
java String array  I want to print values stored in array of string ("1","2","3","4","5" ...) in the form 1 2 3 4 5 6 7 8 9 10 11 12 how... { public static void main(String[] args) { int k=0; String str[]={"1","2
C Array of String
C Array of String       In this section you will learn how to create an array of string in C. A String is an array of char objects. An array of string can be declared
create a string from an array using JavaScript
create a string from an array using JavaScript  How to use "join()" to create a string from an array using JavaScript
Convert Array to String
Convert Array to String       In this program we have taken an array of type String as "String stringarray[] = {"chandan", " " ,"tamana"
PHP Array Sub String Search
PHP Array Search Sub-String In PHP if we need to search a sub-string within an array then we can use in_array() function. The format of in_array is much... of $array1 is: array(4) { [0]=> string(5) "India" [1]=>
Heap Sort in Java
Heap Sort in Java is used to sort integer values of an array. Like quicksort..._Sort{ public static void main(String a[]){ int i; int arr[] = {1,3,4,5,2...:\array\sorting>java heap_Sort Heap Sort --------------- Unsorted Array 1 3
String Array In Java
String Array In Java       In this section, you will learn how to use string array in Java. Here, you will see how to declare a string array and the syntax for using in the program

Ads