473,325 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Exception with String array in Java

sunsolaris2000
I have 3 sql tables: **professors(prof_id, name)**, **professors_courses(prof_id, course_id)** and **courses(course_id, title)**.

**professors_courses** is the bridge table between professors and courses.

In *CourseAssignments.java* I search which courses belong to professor x, after user enters a professor "name".

**Course.java**

Expand|Select|Wrap|Line Numbers
  1.   public class Course {
  2.         private int course_id;
  3.         private String title;
  4.  
  5.         public Course(int id, String title){
  6.             super();
  7.             this.course_id = id;
  8.             this.title = title;
  9.         }
  10.  
  11.         public int getCourse_id(){
  12.             return course_id;
  13.         }
  14.  
  15.         public String getTitle(){
  16.             return title;
  17.         }

Expand|Select|Wrap|Line Numbers
  1. Same with **Professor.java**:
  2.  
  3.     public class Professor {
  4.        private int prof_id;
  5.        private String name;
...................

Expand|Select|Wrap|Line Numbers
  1. Same with **PC.java**:
  2.  
  3.     public class PC {
  4.       private int prof_id;
  5.       private int course_id;
..................

**
Expand|Select|Wrap|Line Numbers
  1. ArrayList<PC> results** contains prof_id <-> course_id
**
Expand|Select|Wrap|Line Numbers
  1. ArrayList<Course> courses** contains course_id <-> title (identical with the table "courses")
I need these for example because let's say:

In "professors" table we have prof_id: 5, name: John;
In "professors_courses" we have prof_id: 5, course_id: 1
prof_id: 5, course_id: 9
In "courses" table we have course_id: 1, title: French
course_id: 9, title: Spanish

User enters: "John"

In ArrayList "results" I store:
prof_id: 5, course_id: 1 and prof_id: 5, course_id: 9
So it's similar with the bridge table, but only contains the info regarding "John".

In String cs[] I want to store all the courses of "John", so cs[] = {"French", "Spanish"}

All in all I want to take only the "title" fields from ArrayList "courses" and store them into a String array (cs[]).

In JSP I would display the titles:

Expand|Select|Wrap|Line Numbers
  1.    <%     
  2.         //all the courses that a professor has
  3.         String titles[] = CourseAssignments.getInstance().bridge1("John");
  4.         %>
  5.  
  6.         <html>
  7.            <head></head>
  8.              <body>
  9.              <center>
  10.                 <table border="1" cellspacing="1" cellpadding="8" bgcolor= "33FFCC"> 
  11.                     <tr>
  12.                         <td bgcolor= #FF9966><b>Course</b></td>
  13.                     </tr>
  14.                          <%
  15.                         for (int i = 0; i < titles.length; i++){
  16.                             if(titles[i] != null){
  17.                         %>
  18.                         <tr>
  19.                           <td><%= titles[i]%></td>
  20.                         </tr>
  21.                         <%
  22.                              }
  23.                         }
  24.         %>
  25.                     </table>
I have Exception at the array:

org.apache.jasper.JasperException: java.lang.NullPointerException
Jul 20 '12 #1
0 1620

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Sunny | last post by:
Hi, I am at present working on a jsp page which has a single text field. Upon entering a value in the field, i am trigerring an onChangeEvent() which calls a method of javascript. I am also...
8
by: Jeff Johnson | last post by:
Hi, I've begun converting an ASP site over to .NET and I'm a novice at both the new platform as well as C#. I have a COM+ object that returns a string array when it is called. The size of...
6
by: Sudha | last post by:
Hi All, I am trying to use COM DLL in my C#. I have added this DLL in referance and all interface are working fine. I have one issue in calling function decleared like: void...
2
by: John Salerno | last post by:
All this time I've been using a string array for my program, but I think I might want to actually use the values (0s and 1s) as integers, so is there an easy way to convert this? Should it happen...
11
by: Zordiac | last post by:
How do I dynamically populate a string array? I hope there is something obvious that I'm missing here Option Strict On dim s() as string dim sTmp as string = "test" dim i as integer ...
6
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
2
by: Earl | last post by:
I'm trying to do a cast and I'm not sure where I'm going wrong here. I load up the ColorExtIntID column (int) into a list array (no problem there). For binding to a 3rd party component, it has to...
0
by: Rik Moed | last post by:
Hi all, I encounter a problem with a library method that should create a multi dimensional string array. Below is the method:...
9
by: =?Utf-8?B?U0FM?= | last post by:
Is it possible to Cast an Object to a String Array the way I'm doing it in the code below? I'm trying to reuse code I have without creating new code if I can. Dim asNames() As String Dim...
5
by: sarabonn | last post by:
hallo, I have a function which takes 2 values as input and i want to return that 2 values, so how should write the return statement to return 2 values of String array. I also i should...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.