내가 묻는 이유는 null 포인터 예외가 발생합니다. 이미지를 바이트 배열과 바이트 배열로 구문 분석하는 SRSI.java라는 클래스가 있습니다. 다른 클래스 계정의 setter 메서드에 저장 오전. 이제 다른 세 번째 클래스에서이 setter 값을 사용하여 getter 메서드를 사용하여 작업 클래스에서 말할 수 있습니다.하지만 NPE를 얻고 있습니다. // 아래 내가 처리하고 DB에 저장하고 있어요 SRSI 클래스의 코드는 같은 시간에 내가다른 클래스의 객체에 동일한 참조 변수 얻기 java
String fromLocal ="D://1-123456.jpg";
long accountId = account.getId();
File file = new File(fromLocal);
System.out.println("Length--> " + file.length());
InputStream inputStream = null;
byte[] bFile= null;
byte[] imageData = null;
try {
inputStream = new BufferedInputStream(new FileInputStream(file));
ByteArrayOutputStream baos = new ByteArrayOutputStream(8192);
bFile = new byte[8192];
int count;
while((count = inputStream.read(bFile))> 0){
baos.write(bFile, 0, count);
}
bFile = baos.toByteArray();
if(bFile.length > 0){
imageData = bFile;
}
baos.flush();
inputStream.close();
} catch (Exception ioe) {
//throw ioe;
}
//storing the above byte array which contains image into account class setter method here account is reference of account class.
account.setImageData(imageData);
//here what account class getter and setter methods looks like
private byte[] imageData;
public void setImageData(byte[] imageData){
if(null!=imageData){
this.imageData = imageData;
}
}
public byte[] getImageData(){
return imageData;
}
Now what i need this same value in getter method in 3rd class i.e.Action.What i am doing is
Action action = new Action();
action.getImageData();
내가 그것을 새로운 개체를 만드는 것이로 알고 세터 방법으로 저장하고 있으며 그 이유입니다 NPE를 반환합니다. 하지만 액션 클래스와 액션 클래스와 SRSI, 계정에 다른 패키지에 setter의 동일한 가치가 필요합니다.
미리 감사드립니다.