Исключение: ArrayIndexOutOfBounds
я получилarray index out of bounds exception
при попытке прочитать данные из файла в массив. Файл содержит 700 строк данных, похожих на:
"Vasculitis_PlasmaExchange", "#FCE883", "http://ncbi.nlm.nih.gov/pubmed/18646089", "(252, 232, 131)"
"Vasculitis_Prednisone", "#C5E384", "http://ncbi.nlm.nih.gov/pubmed/19588365", "(197, 227, 132)"
мой код:
static{
COLOR_CODES = new ArrayList<String[]>();
try{
FileReader fr = new FileReader("Crayon.properties");
BufferedReader br = new BufferedReader(fr);
String line;
while ( (line = br.readLine()) != null) {
COLOR_CODES.add(new String[]{line});
}
br.close();
fr.close();
}catch (Exception e){
throw new IllegalStateException("Couldn't load array file");
}
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,
IOException
{
JSONArray fullColorArray;
String query = request.getParameter("q");
try {
int count = 0;
if (query.equals(m_lastQuery)) {
fullColorArray = m_lastResults;
count = m_lastResults.length();
} else {
m_lastQuery = query;
fullColorArray = new JSONArray();
for (String[] colorCode : COLOR_CODES) {
String colorName = colorCode[0];
String lowerColor = colorName.toLowerCase();
int has = lowerColor.indexOf(query.toLowerCase());
if (!query.isEmpty() && (query.equals("*") || has >= 0)) {
JSONObject color = new JSONObject();
color.put("DisplayName", colorName);
color.put("Value", colorCode[1]); // <-------- ArrayIndexOutOfBoundsException
color.put("Description", colorCode[2]);
color.put("RGB", colorCode[3]);
fullColorArray.put(color);
count++;
}
}
m_lastResults = fullColorArray;
}
Исключение нулевого указателя:
ОШИБКА HTTP: 500INTERNAL_SERVER_ERROR
RequestURI = / multivaluesuggestboxexample / цвета
Вызванный:java.lang.NullPointerException в org.spiffyui.spiffynavigation.server.CrayonColorsServlet.doGet (CrayonColorsServlet.java:95) в javax.servlet.http.HttpServlet.service (HttpServlet.htt. служба (HttpServlet.java:820) в org.mortbay.jetty.servlet.ServletHolder.handle (ServletHolder.java:487) в org.mortbay.jetty.servlet.ServletHandler.handle (ServletHandler.java:36bay) в org .jetty.security.SecurityHandler.handle (SecurityHandler.java:216) в org.mortbay.jetty.servlet.SessionHandler.handle (SessionHandler.java:181) в org.mortbay.jetty.handler.ContextHandler.handle (ContextHandler.java). : 726) в org.mortbay.jetty.webapp.WebAppContext.handle (WebAppContext.java:405) в org.mortbay.jetty.handler.ContextHandlerCollection.handle (ContextHandlerCollection.java:206) в org.mortbay.jet. HandlerCollection.handle (HandlerCollection.java:114) в org.mortbay.jetty.handler.HandlerWrapper.handle (HandlerWrapper.java:152) в org.mortbay.jetty.Server.handle (Ser ver.java:324) в org.mortbay.jetty.HttpConnection.handleRequest (HttpConnection.java:505) в org.mortbay.jetty.HttpConnection $ RequestHandler.headerComplete (HttpConnection.java:829) в orgport.serb .parseNext (HttpParser.java:514) по адресу org.mortbay.jetty.HttpParser.parseAvailable (HttpParser.java:211) по адресу org.mortbay.jetty.HttpConnection.handle (HttpConnection.javaio.bay.3b) nio.SelectChannelEndPoint.run (SelectChannelEndPoint.java:395) в org.mortbay.thread.QueuedThreadPool $ PoolThread.run (QueuedThreadPool.java:488)(На основеCrayonColorsServlet.java)
Пожалуйста помоги.
А.М. Мохан Рао