This is what I write Java code :
static String BeiJingMyMemRegTimePath = "D:"+File.separator+"MyDoc"+File.separator+"Dport"+File.separator+"BeiJing"+File.separator+"BeiJingSysMemRegTime.txt";
I define a "String type my operating system address path " ..
my operating system corresponding to the file path "BeiJingSysMemRegTime.txt", which his path location system as follows:
contents of the file that I record the user's " authorization code from the filing date January 1, 1970 the number of milliseconds ," I want to do " authorization expires ," the validation of writing ...
contents of the document images is as follows :
after my code, wrote the following " store at the Long data type of " MyArrayList
code is as follows :
static MyArrayList MyBJMemUserAuthorizeTime,MyBJCusUserAuthorizeTime,MyYCMemUserAuthorizeTime,MyYCCusUserAuthorizeTime = new MyArrayList();
because I want to be here, "ArrayList" object arrays have " to work with after a long integer numbers together and " capability , and reserves the ArrayList object arrays " entities are able to add their own " new elements " function "in order to get my program to face the" continuous registered to my system user "" to the user's own storage represented by the field attribute " ; users "operations expand the number of clients " capability .
So, I will be above the ArrayList array had a " below MyArrayList" rewrite ... :
package d_port_package;
import java.util.*;
public class MyArrayList{
private static ArrayList<Long> list = new ArrayList<Long>();
public void add(long value){
list.add(value);
}
public void calculate(int index, long value){
if(index >= list.size()){
throw new RuntimeException("下标越界 " + index);
}
list.set(index, list.get(index) + value);
}
}
However, in my program, I run in my code , my compiler MyEclipse reported the following runtime error:
compiler Show:
figure above 89 lines of code , a " null pointer exception" ..
compiler error message is as follows:
Ask the experts:
my code, what is wrong ... ?
how to modify ... ?
Thank you, master coaching ! !
hundred points offer ! !
a perfect running day and night to build toward the dreamer
October 7, 2013 Monday 6:40
------ Solution - -------------------------------------------
evidently should be ReadText.logData.get (i) at i is equal to the specified value returns null .
but carefully read the code they feel impossible. Unless you give the code or the environment description insufficiency. ( For example, you were more threads case )
MyBJMemUserAuthorizeTime
ReadTxt
ReadTxt.logData
These feelings can not be null.
is no way you have only 89 rows in front of it
MyBJMemUserAuthorizeTime
ReadTxt
ReadTxt.logData
are printed out to see to confirm whether it is null. (Sysout)
ReadText.logData.get (i) this is too much trouble . Circulating inside to write about
if (ReadText.logData.get (i) == null) {System.out.println (" Dad, I was wrong, I became a null !! i:" + i) }
------ For reference only ---------------------------------- -----
I used to read the data in txt file code is:
(ReadTxt category )
package d_port_package;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class ReadTxt {
static ArrayList<String> logData = new ArrayList<String>();
static String text = null;
public static void read(String filePath) {
try {
FileReader input = new FileReader(filePath);
BufferedReader br = new BufferedReader(input);
while (( text = br.readLine()) != null) {
logData.add(text);
}
br.close();
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void readMemoryData(String data){
logData.add(data);
}
public static void readMemoryArrayData(String[] data){
int len = data.length;
for(int i = 0;i<len;i++){
logData.add(data[i]);
}
}
}
------ For reference only ----------------------------------- ----
want to be a master of coaching:
my mistake , there is what is the principle reason for cause ... ?
hope to get expert help solve the problem as soon as possible ! !
Thank you, master ! !
------ For reference only -------------------------- -------------
that list there are no data bars
methods on how to read the back of the line 89
you try to export the file path address is correct it
------ For reference only ---------------------------------- -----
null pointer clearly, their debug a look, a look which line newspaper , to find the reason should be able to solve ! ! ! I wish you good luck. . .
------ For reference only -------------------------------------- -
Also you write java code is not a style, but a lot of problems inside. Wording basically anti-patterns , there are many problems are not surprising. Slowly debugging.
没有评论:
发表评论