Currently I have a need in local http file server in Android app and I decided to use NanoHttpd SimpleWebServer. But I encountered such exception:
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.io.InputStream.read(byte[])' on a null object reference
at fi.iki.elonen.SimpleWebServer.<clinit>(SimpleWebServer.java:83)
And the crashing part is actually static constructor
static {
mimeTypes();
InputStream stream = SimpleWebServer.class.getResourceAsStream("/LICENSE.txt");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int count;
String text;
try {
while ((count = stream.read(buffer)) >= 0) {
bytes.write(buffer, 0, count);
}
text = bytes.toString("UTF-8");
} catch (IOException e) {
text = "unknown";
}
LICENCE = text;
}
Apparently, library is trying to load some license file but fails. So, the server is not created and not started.
Does anybody know how to overcome this issue? Thanks in advance!
(I use Android Studio 1.5.1 and included library via gradle dependency 'org.nanohttpd:nanohttpd-webserver:2.2.0'
)