사용자가 입력 할 때 중복 문자열을 찾기 위해 아래 코드를 사용하여지도에서 키를 제거 할 수 있습니다. (앞으로 그렇게 할 것입니다. , 지금은 문자열에 중복 값이 있습니다). 그러나 if 문에서 NullPointerException 오류가 발생합니다. 왜 이런 일이 일어나는 걸까요? 전체 코드는 아래에 있습니다.문자열 비교에서 null 값을 얻는 이유
import java.io.*;
import java.util.*;
public class Testing
{
public static void main (String [] args) throws FileNotFoundException
{
int i=0,j,k,map_addr;
String [] inp_value = new String[100];
String [] inp_addr_val = new String[100];
String [] inp_addr = new String[100];
String addr_path,sCurrentLine;
BufferedReader reader = null;
Scanner inp = new Scanner(System.in);
Map<String, String> map = new HashMap<>();
Iterator map_iterator = map.keySet().iterator();
System.out.println("Welcome! Please enter the addresses");
while(i!=100)
{
System.out.println("Enter address:");
inp_addr[i] = inp.nextLine();
try
{
reader = new BufferedReader(new FileReader(inp_addr[i]));
while ((sCurrentLine = reader.readLine()) != null)
{
inp_value[i]=reader.readLine();
inp_addr_val[i]=Integer.toString(i);
map.put(inp_addr_val[i],inp_value[i]);
i++;
System.out.println(map.get(inp_addr_val[i]));
}
for(j=0;j<=i;j++)
{
if(inp_value[j].equals(inp_value[i]))
{
System.out.println("File already exists, skipping this file.");
i--;
}
}
}catch (IOException ex) {
System.out.println("Something bad happened. Program is exiting now...");
System.exit(0);
}
}
}}
감사합니다.
스택 트레이스를 붙여주세요. –
SO는 디버깅 도구가 아닙니다. 혼자 코드를 디버깅하려 했습니까? –
이 질문은 코드 디버깅 요청이기 때문에 논제가 아닌 것으로 보입니다. – hexafraction