G
gbattine
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.doHandlePageException(PageContextImpl.java:821)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.pages.MyForm_jsp._jspService(MyForm_jsp.java:89)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:670)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:637)
org.apache.jsp.pages.index_jsp._jspService(index_jsp.java:43)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.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(ValueBindingImpl.java:206)
com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:154)
javax.faces.component.UIOutput.getValue(UIOutput.java:147)
org.apache.myfaces.custom.fileupload.HtmlFileUploadRenderer.encodeEnd(HtmlFileUploadRenderer.java:59)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:720)
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:443)
com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer..java:233)
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:701)
javax.faces.webapp.UIComponentTag.encodeChildren(UIComponentTag.java:607)
javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:544)
com.sun.faces.taglib.html_basic.PanelGridTag.doEndTag(PanelGridTag.java:460)
org.apache.jsp.pages.MyForm_jsp._jspx_meth_h_panelGrid_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(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:670)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:637)
org.apache.jsp.pages.index_jsp._jspService(index_jsp.java:43)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.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]);
}
}
}
}
}
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.doHandlePageException(PageContextImpl.java:821)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.pages.MyForm_jsp._jspService(MyForm_jsp.java:89)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:670)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:637)
org.apache.jsp.pages.index_jsp._jspService(index_jsp.java:43)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.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(ValueBindingImpl.java:206)
com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:154)
javax.faces.component.UIOutput.getValue(UIOutput.java:147)
org.apache.myfaces.custom.fileupload.HtmlFileUploadRenderer.encodeEnd(HtmlFileUploadRenderer.java:59)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:720)
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:443)
com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer..java:233)
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:701)
javax.faces.webapp.UIComponentTag.encodeChildren(UIComponentTag.java:607)
javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:544)
com.sun.faces.taglib.html_basic.PanelGridTag.doEndTag(PanelGridTag.java:460)
org.apache.jsp.pages.MyForm_jsp._jspx_meth_h_panelGrid_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(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:670)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:637)
org.apache.jsp.pages.index_jsp._jspService(index_jsp.java:43)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.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]);
}
}
}
}
}