I am writting an android application to download a file from the network , but I keep getting the following error :
java.lang.NullPointerException at jcifs.smb.ServerMessageBlock.writeString(ServerMessageBlock.java:213) at jcifs.smb.ServerMessageBlock.writeString(ServerMessageBlock.java:202) at jcifs.smb.SmbComNTCreateAndX.writeBytesWireFormat(SmbComNTCreateAndX.java:170) at jcifs.smb.AndXServerMessageBlock.writeAndXWireFormat(AndXServerMessageBlock.java:101) at jcifs.smb.AndXServerMessageBlock.encode(AndXServerMessageBlock.java:65) at jcifs.smb.SmbTransport.doSend(SmbTransport.java:415) at jcifs.util.transport.Transport.sendrecv(Transport.java:70) at jcifs.smb.SmbTransport.send(SmbTransport.java:619) at jcifs.smb.SmbSession.send(SmbSession.java:240) at jcifs.smb.SmbTree.send(SmbTree.java:111) at jcifs.smb.SmbFile.send(SmbFile.java:721) at jcifs.smb.SmbFile.open0(SmbFile.java:926) at jcifs.smb.SmbFile.open(SmbFile.java:943) at jcifs.smb.SmbFileOutputStream.(SmbFileOutputStream.java:142) at jcifs.smb.SmbFileOutputStream.(SmbFileOutputStream.java:97) at jcifs.smb.SmbFileOutputStream.(SmbFileOutputStream.java:67) at za.co.ver_tex.itqueries.NetworkShareFileCopy.copyFileUsingJcifs(NetworkShareFileCopy.java:80) at za.co.ver_tex.itqueries.ViewQuery.ViewFile(ViewQuery.java:780) at za.co.ver_tex.itqueries.ViewQuery$4.onClick(ViewQuery.java:375) at android.view.View.performClick(View.java:4633) at android.view.View$PerformClick.run(View.java:19330) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:157) at android.app.ActivityThread.main(ActivityThread.java:5356) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) at dalvik.system.NativeStart.main(Native Method)
Here is my code :
public void copyFromNetwork(String NetworkFile, String DestinationFile) {
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("Domain",
"User", "Password");
SmbFile remoteFile;
try {
remoteFile = new SmbFile("smb:" + NetworkFile, auth);
OutputStream os = new FileOutputStream(DestinationFile);
InputStream is = null;
is = remoteFile.getInputStream();
int bufferSize = 5096;
byte[] b = new byte[bufferSize];
int noOfBytes = 0;
while ((noOfBytes = is.read(b)) != -1) {
os.write(b, 0, noOfBytes);
}
os.close();
is.close();
} catch (Exception ex) {
Log.w("FileCopy", ex);
}
}