Вылетает NullPointerException в Matcher, когда число больше 12, если заменить на число до 13 то все ок. Почему так происходит? package com.javarush.task.task19.task1924; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; /* Замена чисел */ public class Solution { public static Map<Integer, String> map = new HashMap<Integer, String>(); static { map.put(0,"ноль"); map.put(1,"один"); map.put(2,"два"); map.put(3,"три"); map.put(4,"четыре"); map.put(5,"пять"); map.put(6,"шесть"); map.put(7,"семь"); map.put(8,"восемь"); map.put(9,"девять"); map.put(10,"десять"); map.put(11,"одиннадцать"); map.put(12,"двенадцать"); } public static void main(String[] args) throws IOException{ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String fileName = "C:/1.txt";//reader.readLine(); BufferedReader fileReader = new BufferedReader(new FileReader(fileName)); StringBuilder sb = new StringBuilder(); while (fileReader.ready()){ sb.append(fileReader.readLine()); } reader.close(); fileReader.close(); String text = sb.toString().replace(".",". "); String[] full = text.split(" "); for (String s:full){ System.out.print("["+s+"]"); } System.out.println(); for(int i = 0;i< full.length;i++){ if(isDigit(full[i])){ int x = Integer.parseInt(full[i]); full[i]=map.get(x); } Pattern regex = Pattern.compile("[\\p{P}]"); Pattern regex1 = Pattern.compile("[0-9]"); Matcher matcher = regex.matcher(full[i]); Matcher matcher1 = regex1.matcher(full[i]); if((matcher.find())&&(matcher1.find())){ String[] s=full[i].split("\\p{P}"); System.out.println(s[0]); if(isDigit(s[0])&&Integer.parseInt(s[0])<13){ int x = Integer.parseInt(s[0]); full[i]=map.get(x)+full[i].substring(full[i].length()-1); } } } for (String s:full){ System.out.print(s+" "); } } private static boolean isDigit(String s) throws NumberFormatException { try { Integer.parseInt(s); return true; } catch (NumberFormatException e) { return false; } } }