Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > java.lang.NullPointerException..help me!

Reply
Thread Tools

java.lang.NullPointerException..help me!

 
 
gbattine
Guest
Posts: n/a
 
      06-06-2006
Hy guys,
I'm developing a Jsf application and i have a question.
My application allow user to upload a file and show to user number of
columns and rows,thanks to a javabean called MyBean.java.
My error is

message

description The server encountered an internal error () that prevented
it from fulfilling this request.

exception

javax.servlet.ServletException: javax.servlet.jsp.JspException:
javax.faces.FacesException: javax.faces.FacesException: Can't
instantiate class: 'com.devsphere.articles.jsfupload.MyBean'.. class
com.devsphere.articles.jsfupload.MyBean :
java.lang.NullPointerException
org.apache.jasper.runtime.PageContextImpl.doHandle PageException(PageContextImpl.java:821)
org.apache.jasper.runtime.PageContextImpl.handlePa geException(PageContextImpl.java:75
org.apache.jsp.pages.MyForm_jsp._jspService(MyForm _jsp.java:89)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
com.sun.faces.context.ExternalContextImpl.dispatch (ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderVi ew(ViewHandlerImpl.java:130)
com.sun.faces.lifecycle.RenderResponsePhase.execut e(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(Lifecy cleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(Lifec ycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServl et.java:19
org.apache.jasper.runtime.PageContextImpl.doForwar d(PageContextImpl.java:670)
org.apache.jasper.runtime.PageContextImpl.forward( PageContextImpl.java:637)
org.apache.jsp.pages.index_jsp._jspService(index_j sp.java:43)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)


root cause

javax.faces.el.EvaluationException: javax.faces.FacesException:
javax.faces.FacesException: Can't instantiate class:
'com.devsphere.articles.jsfupload.MyBean'.. class
com.devsphere.articles.jsfupload.MyBean :
java.lang.NullPointerException
com.sun.faces.el.ValueBindingImpl.getValue(ValueBi ndingImpl.java:206)
com.sun.faces.el.ValueBindingImpl.getValue(ValueBi ndingImpl.java:154)
javax.faces.component.UIOutput.getValue(UIOutput.j ava:147)
org.apache.myfaces.custom.fileupload.HtmlFileUploa dRenderer.encodeEnd(HtmlFileUploadRenderer.java:59 )
javax.faces.component.UIComponentBase.encodeEnd(UI ComponentBase.java:720)
com.sun.faces.renderkit.html_basic.HtmlBasicRender er.encodeRecursive(HtmlBasicRenderer.java:443)
com.sun.faces.renderkit.html_basic.GridRenderer.en codeChildren(GridRenderer..java:233)
javax.faces.component.UIComponentBase.encodeChildr en(UIComponentBase.java:701)
javax.faces.webapp.UIComponentTag.encodeChildren(U IComponentTag.java:607)
javax.faces.webapp.UIComponentTag.doEndTag(UICompo nentTag.java:544)
com.sun.faces.taglib.html_basic.PanelGridTag.doEnd Tag(PanelGridTag.java:460)
org.apache.jsp.pages.MyForm_jsp._jspx_meth_h_panel Grid_0(MyForm_jsp.java:223)
org.apache.jsp.pages.MyForm_jsp._jspx_meth_h_form_ 0(MyForm_jsp.java:151)
org.apache.jsp.pages.MyForm_jsp._jspx_meth_f_view_ 0(MyForm_jsp.java:114)
org.apache.jsp.pages.MyForm_jsp._jspService(MyForm _jsp.java:80)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
com.sun.faces.context.ExternalContextImpl.dispatch (ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderVi ew(ViewHandlerImpl.java:130)
com.sun.faces.lifecycle.RenderResponsePhase.execut e(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(Lifecy cleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(Lifec ycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServl et.java:19
org.apache.jasper.runtime.PageContextImpl.doForwar d(PageContextImpl.java:670)
org.apache.jasper.runtime.PageContextImpl.forward( PageContextImpl.java:637)
org.apache.jsp.pages.index_jsp._jspService(index_j sp.java:43)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)


note The full stack trace of the root cause is available in the Apache
Tomcat/5.0.28 logs.


I show you my MyBean.jva

package com.devsphere.articles.jsfupload;

import org.apache.myfaces.custom.fileupload.UploadedFile;
import java.io.IOException;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.io.*;

public class MyBean {
private UploadedFile myFile;
private Map <String, double[]>dataMap = null;
private int Nrows=0;
private int Ncol=0;
private int numberOfNumericColumns =0;

public UploadedFile getMyFile() {
return myFile;
}

public void setMyFile(UploadedFile myFile) {
this.myFile = myFile;
}

public static void main(String[] args) throws IOException {
new MyBean();
}

public MyBean() throws IOException { //constructor
// Get a reference to the input file.
BufferedReader br= new BufferedReader(new
InputStreamReader(myFile.getInputStream()));

// Create the empty map.
this.dataMap = new HashMap<String, double[]>();
//Constructs an empty HashMap with the default initial capacity (16)
and the default load factor (0.75).
// Populate the map from the input file.
populateMap(br);
//int Dim=(dataMap.size());//include the first string row
//System.out.println("Il size del datamap e'"+Dim);
Ncol=(numberOfNumericColumns+1);
System.out.println("Il numero di colonne e'"+(Ncol));
//System.out.println("Il numero di colonne del file
č"+dataMap.size());
// Display the contents of the map.
displayMap(this.dataMap);
// Close the reader.
br.close();
}
public Map populateMap(BufferedReader bufferedReader) throws
IOException
{
System.out.println("Caricamento dell'array di double in corso.....");
// Store each line of the input file as a separate key and entry in the
Map.
String line = null;
while ((line = bufferedReader.readLine()) != null) {
line = line.replace (',', '.');
Nrows++;
// Create a tokenizer for the line.
StringTokenizer st = new StringTokenizer(line);
// Assuming that the first column of every row is a String and
//the remaining columns are numbers, count the number of numeric
columns.

numberOfNumericColumns = (st.countTokens()-1);

// Get the first token from the line. It will be a String and
//its value will be a unique key for the rest of the row.

String key = st.nextToken().trim();
// Create the array for the numbers which make up the rest of the line.

double[] array = new double[numberOfNumericColumns];
// Populate the array by parsing the rest of the line.
for (int column = 0; column < numberOfNumericColumns; column++){
array[column] = Double.parseDouble(st.nextToken().trim());
}
// Store the first column as the key and the array as the entry.

this.dataMap.put(key, array); //Associates the specified value with
//the specified key in this map.

}
System.out.println("Il numero di colonne numeriche del file
e'"+numberOfNumericColumns);
System.out.println("Il numero di righe del file e'"+Nrows);
//System.out.println("Il numero di colonne del file
č"+dataMap.size());
return this.dataMap;
}


public void displayMap(Map<String,double[]> myMap) {
/* Iterate through the values of the map, displaying each key and
its corresponding array. */
for (Map.Entry<String, double[]> entry : myMap.entrySet()) {
/* Get and display the key. */
System.out.print(entry.getKey() + " : ");
/* Get the array. */
double[] myArray = entry.getValue();
/*
* Display each value in the array. Put a semicolon after each
value except the last.
* Keep all the values for a given key on a single line.
*/
for (int ix = 0; ix < myArray.length; ix++) {
if (ix < myArray.length - 1) { //the value is not the last one in the
array ,allora metti ;
System.out.print(myArray[ix] + "; ");
} else { //the value is the last one in the array ,la linea finisce
cosė
System.out.println(myArray[ix]);
}
}
}
}
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57