At first I was going to answer this question by stating I don’t believe it’s true that Japanese people don’t accept foreigners but then I read a summary of a survey that did indeed show “foreigners in Japan face significant levels of discrimination”.
Japan’s Centre for Human Rights Education and Training conducted a survey in 2016 “so that the Justice Ministry could better understand what discrimination and human rights issues foreigners in Japan face, and to find ways protect their rights.” I now think racism does exist in Japan and it’s primarily for the same reason racism exists in other places, many people just don’t like diversity and don’t like people who are different from them.