1. Problem description
Here is the object array
LocHistory[] history = new LocHistory[list2.size()];
When assigning a value to the history object, the following error is reported
2. Reasons for error reporting
LocHistory[] history = new LocHistory[list2.size()]; Only the size of the array is given, but the instantiated object is not given at the corresponding position. The premise to obtain history [i] is that there is an object under coordinate I.
3. Solutions
Create a new object for each object reference
History [i] = new lochistory();
The specific codes are as follows:
LocHistory[] history = new LocHistory[list2.size()];
for (int i = 0; i < list2.size(); i++) {
history[i] = new LocHistory();
String PageX = list2.get(i).getPageX();
String PageY = list2.get(i).getPageY();
history[i].setPageX(PageX);
history[i].setPageY(PageY);
Read More:
- Two dimensional array and pointer to one dimensional array
- Failed to get the resources path in the jar package, reporting an error null pointer
- How to use C + + function pointer array
- The @ Autowired annotation in springboot is invalid in ordinary classes. How to solve and use the null pointer exception java.lang.nullpointerexception
- Array of PHP_ diff,array_ intersect,array_ merge, in_ Is there a limit on the number of arrays in array?
- Solve the interceptor calling service layer to display null pointer.
- Use of HQL query.list () is a null pointer exception, but the database can find out the result
- After the go pointer is declared and assigned, a panic: runtime error: invalid memory address or nil pointer reference appears
- When the spring MVC project is running on idea, an error is reported when the controller is a null pointer
- Leetcode solution 189 Rotate Array Java version
- Error:null value in entry: incrementalFolder=null
- [solved] error: valueerror: expected 2D array, got scalar array instead
- “Could not import PIL.Image . The use of array_ to_ The solution of img requires PIL. “
- Abnormal crash of APP startup — pointer being free was not allocated * * set a breakpoint in malloc_ error_ break to debug
- The solution of Hibernate query returning all null lists
- Error in dev C + + running pointer
- org.apache.ibatis.type.TypeException: Error setting non null for parameter #4 with JdbcType null
- Variable type error: error of array occurs when TP5 controller receives the array of post
- JavaScript removes the number specified in the array
- [debug notes] pointer error when STD:: vector is used in VTK “access conflict when reading location XXX”