Problème en JAVA
Dernière réponse : dans Programmation
Bonjour,
Voici, avec quelques collègues nous sommes sur un grand projet. Malheureusement, il me faut un fichier en Jar que l'on exécute avec la commande CMD. Il bug.
J'aurais voulu un coup de main de votre part, je ne trouve pas l'erreur dans l'archive.
C'est un peu long.
Mon erreur est:
Merci de bien vouloir m'aider.
Voici, avec quelques collègues nous sommes sur un grand projet. Malheureusement, il me faut un fichier en Jar que l'on exécute avec la commande CMD. Il bug.
J'aurais voulu un coup de main de votre part, je ne trouve pas l'erreur dans l'archive.
C'est un peu long.
import com.sonyericsson.cs.generic.c.c;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.*;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
class U5flash
{
private static String str;
private static U5flash me = null;
private static int my_ch;
private static final boolean isNeedDump = false;
private int lastflags;
private static Logger logger = null;
private static com.sonyericsson.cs.usbflashnative.a.a my_a = null;
U5flash()
{
}
private byte[] readReply()
{
try
{
byte ret[] = my_a.readBytes(my_ch, 0x10000);
int cmd = -1;
int flags = -1;
int length = -1;
byte abyte0[] = ret;
byte tmpB[] = new byte[4];
System.arraycopy(abyte0, 0, tmpB, 0, 4);
cmd = c.c(tmpB, false);
if((cmd & 0xfffffff0) == 0)
{
System.arraycopy(abyte0, 4, tmpB, 0, 4);
flags = c.c(tmpB, false);
if((flags & -8) == 0)
{
System.arraycopy(abyte0, 8, tmpB, 0, 4);
length = c.c(tmpB, false);
if((length & 0xfffe0000) == 0)
{
byte sum1 = d.calcSum(abyte0);
if(sum1 == abyte0[12])
{
lastflags = flags;
logger.log(Level.INFO, (new StringBuilder("<<< cmd=")).append(cmd).append(",flags=").append(flags).append(",length=").append(length).toString());
if(length != 0)
{
if(length >= 0x10000)
{
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
for(; length != 0; length -= ret.length)
{
byte out[] = my_a.readBytes(my_ch, 0x10000);
try
{
dataoutputstream.write(out);
continue;
}
catch(IOException ioexception) { }
break;
}
ret = bytearrayoutputstream.toByteArray();
} else
{
ret = my_a.readBytes(my_ch, 0x10000);
}
} else
{
byte b[] = new byte[0];
ret = b;
}
byte tmp[] = my_a.readBytes(my_ch, 4096);
int sum = -1;
int sum2 = -1;
if(tmp.length == 4)
sum = c.c(tmp, false);
d testD = new d(cmd, false, false, false, ret);
byte sumed[] = testD.getByteArray();
byte sumed2[] = new byte[4];
System.arraycopy(sumed, sumed.length - 4, sumed2, 0, 4);
sum2 = c.c(sumed2, false);
if(sum != sum2)
logger.log(Level.INFO, (new StringBuilder("### read filed : checksum err! ")).append(hd.toHex(sum)).append("!=").append(hd.toHex(sum2)).toString());
return ret;
}
}
}
}
}
catch(Exception exception) { }
return null;
}
private void testPluged()
{
byte ret[] = readReply();
logger.log(Level.INFO, (new StringBuilder("<<<")).append(new String(ret)).toString());
}
private void writeCmd(int cmd, byte body[])
{
d my_d = new d(cmd, false, true, false, body);
logger.log(Level.INFO, (new StringBuilder("write(cmd=")).append(cmd).append(") (finish)").toString());
try
{
my_a.writeBytes(my_ch, my_d.getByteArray());
}
catch(IOException e)
{
logger.log(Level.INFO, "### write failed");
}
}
private void writeCmd2(int cmd, byte body[])
{
d my_d = new d(cmd, false, true, true, body);
logger.log(Level.INFO, (new StringBuilder("write(cmd=")).append(cmd).append(") (continue)").toString());
try
{
my_a.writeBytes(my_ch, my_d.getByteArray());
}
catch(IOException e)
{
logger.log(Level.INFO, "### write failed");
}
}
private void testCmd01()
{
byte body[] = new byte[0];
writeCmd(1, body);
byte ret[] = readReply();
logger.log(Level.INFO, (new StringBuilder("<<<")).append(new String(ret)).toString());
}
private void testCmd07()
{
byte body[] = new byte[0];
writeCmd(7, body);
byte ret[] = readReply();
logger.log(Level.INFO, (new StringBuilder("<<<")).append(new String(ret)).toString());
}
private void testCmd09(byte area)
{
byte body[] = {
area
};
writeCmd(9, body);
readReply();
}
private void testCmd10()
{
byte body[] = new byte[0];
writeCmd(10, body);
readReply();
}
private void testCmd04(byte flag)
{
byte body[] = {
flag
};
writeCmd(4, body);
readReply();
}
private void testCmd05(byte cert[])
{
byte body[] = cert;
writeCmd(5, body);
readReply();
if(lastflags == 0)
testCmd07();
}
private void testCmd06(byte data[])
{
writeCmd(6, data);
readReply();
}
private void testCmd06_2(byte data[])
{
if(data != null && data.length < 65519)
{
writeCmd2(6, data);
readReply();
} else
{
byte body[] = new byte[65519];
System.arraycopy(data, 0, body, 0, body.length);
writeCmd2(6, body);
readReply();
body = new byte[data.length - 65519];
System.arraycopy(data, 65519, body, 0, body.length);
writeCmd2(6, body);
readReply();
}
}
private byte[] testCmd12(int id)
{
byte body[] = c.a(id, 4, false);
writeCmd(12, body);
byte ret[] = readReply();
if(ret != null)
{
if(ret.length != 0)
{
logger.log(Level.INFO, (new StringBuilder("<<<")).append(new String(ret)).toString());
logger.log(Level.INFO, (new StringBuilder("<<<")).append(hd.toHex(ret)).toString());
} else
{
logger.log(Level.INFO, "<<< null string");
}
} else
{
logger.log(Level.INFO, "<<< (null)");
}
return ret;
}
private void testCmd13(int t)
{
byte bodies[][] = new byte[4][];
byte body0[] = {
0, 0, 8, -77, 0, 0, 0, 4, -96, 0,
0, 0
};
byte body1[] = {
0, 0, 8, -3, 0, 0, 0, 16, 0, 0,
8, 0, 5, 0, 0, 0, 14, 0, 0, 0,
8, 0, 0, 0
};
byte body2[] = {
0, 0, 9, 97, 0, 0, 0, 4, -2, -1,
-1, -1
};
byte body3[] = {
0, 0, 8, -77, 0, 0, 0, 4, -86, 0,
0, 0
};
bodies[0] = body0;
bodies[1] = body1;
bodies[2] = body2;
bodies[3] = body3;
if(t < bodies.length)
{
writeCmd(13, bodies[t]);
readReply();
}
}
private void dumpProperties()
{
for(int i = 0; i < 3000; i++)
{
logger.log(Level.INFO, (new StringBuilder("%%% read property id=")).append(i).toString());
byte ret[] = testCmd12(i);
if(ret != null)
try
{
FileOutputStream out = new FileOutputStream((new StringBuilder("prop_")).append(i).append(".bin").toString());
out.write(ret);
out.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
private void uploadImage(String fname, int blksize)
{
try
{
FileInputStream in;
int len;
byte tmp1[];
tmp1 = new byte[6];
in = new FileInputStream((new StringBuilder(String.valueOf(fname))).append(".rofs").toString());
len = in.read(tmp1);
if(len != 6)
{
in.close();
return;
}
byte tmp2[];
tmp2 = new byte[4];
System.arraycopy(tmp1, 2, tmp2, 0, 4);
len = c.c(tmp2, false);
tmp2 = new byte[len - 6];
len = in.read(tmp2);
if(len != tmp2.length)
{
in.close();
return;
}
byte cert[] = new byte[len + 6];
System.arraycopy(tmp1, 0, cert, 0, 6);
System.arraycopy(tmp2, 0, cert, 6, cert.length - 6);
testCmd05(cert);
byte tmp[] = new byte[blksize];
do
{
len = in.read(tmp);
if(len != blksize)
break;
testCmd06_2(tmp);
} while(true);
in.close();
if(len != 0)
{
byte data[] = new byte[len];
System.arraycopy(tmp, 0, data, 0, len);
testCmd06(data);
}
}
catch(FileNotFoundException e)
{
logger.log(Level.INFO, (new StringBuilder("file ")).append(fname).append(".rofs not found. skip..").toString());
}
catch(IOException e)
{
e.printStackTrace();
}
return;
}
private void uploadLoader(String fname, int blksize)
{
try
{
FileInputStream inL;
int lenL;
byte tmp1L[];
tmp1L = new byte[6];
inL = new FileInputStream((new StringBuilder(String.valueOf(fname))).append(".bin").toString());
lenL = inL.read(tmp1L);
byte tmpL[] = new byte[blksize];
byte dataL[] = new byte[lenL];
System.arraycopy(tmpL, 0, dataL, 0, lenL);
testCmd06(dataL);
inL.close();
}
catch(FileNotFoundException e)
{
logger.log(Level.INFO, (new StringBuilder("file ")).append(fname).append(".rofs not found. skip..").toString());
}
catch(IOException e)
{
e.printStackTrace();
}
return;
}
private void run3()
{
//testCmd13(0);
uploadImage("1", 0x10000);
uploadImage("2", 0x10000);
uploadImage("3", 0x10000);
uploadImage("4", 0x10000);
//testCmd13(1);
//testCmd13(2);
testCmd07();
testCmd13(3);
testCmd07();
testCmd10();
testCmd04((byte)1);
}
private void run2()
{
uploadLoader("loader", 4096);
testPluged();
testCmd01();
testCmd09((byte)2);
run3();
}
private void run()
{
testPluged();
testCmd01();
testCmd09((byte)2);
testCmd10();
run2();
logger.log(Level.INFO, "###test end.");
}
public static void main(String args[])
{
System.loadLibrary("USBFlash");
my_a = com.sonyericsson.cs.usbflashnative.b.a.a();
if(logger == null)
{
logger = Logger.getLogger("mytest.logging");
try
{
FileHandler fh = new FileHandler("U5flash-log.txt");
fh.setFormatter(new SimpleFormatter());
logger.addHandler(fh);
logger.setLevel(Level.ALL);
}
catch(SecurityException securityexception) { }
catch(IOException ioexception) { }
}
logger.log(Level.INFO, "start");
try{
BufferedReader in=new BufferedReader(new FileReader("DeviceID.txt"));
str=in.readLine();
in.close();
}
catch(Exception e){}
try
{
my_ch = my_a.openChannel("USB\\VID_0FCE&PID_ADDE\\" + str, false);
}
catch(IOException e)
{
e.printStackTrace();
}
me = new U5flash();
me.run();
my_a.close(my_ch);
}
}
Mon erreur est:
Exception in thread "main" java.lang.NullPointerException
at java.lang.String.<init>(String.java:593)
at U5flash.testPluged(U5flash.java:103)
at U5flash.run2(U5flash.java:389)
at U5flash.run(U5flash.java:401)
at U5flash.main(U5flash.java:439)
Merci de bien vouloir m'aider.
Autres pages sur : probleme java
Lassé par la pub ? Créez un compte
Lassé par la pub ? Créez un compte
- Contenus similaires :
Tags :