Votre question

Problème en JAVA

Tags :
  • Io
  • Programmation
Dernière réponse : dans Programmation
24 Septembre 2010 01:34:58

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.

  1. import com.sonyericsson.cs.generic.c.c;
  2. import java.io.BufferedReader;
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.DataOutputStream;
  5. import java.io.FileInputStream;
  6. import java.io.FileNotFoundException;
  7. import java.io.FileOutputStream;
  8. import java.io.IOException;
  9. import java.io.*;
  10. import java.util.logging.FileHandler;
  11. import java.util.logging.Level;
  12. import java.util.logging.Logger;
  13. import java.util.logging.SimpleFormatter;
  14.  
  15. class U5flash
  16. {
  17. private static String str;
  18. private static U5flash me = null;
  19. private static int my_ch;
  20. private static final boolean isNeedDump = false;
  21. private int lastflags;
  22. private static Logger logger = null;
  23. private static com.sonyericsson.cs.usbflashnative.a.a my_a = null;
  24.  
  25. U5flash()
  26. {
  27. }
  28.  
  29. private byte[] readReply()
  30. {
  31. try
  32. {
  33. byte ret[] = my_a.readBytes(my_ch, 0x10000);
  34. int cmd = -1;
  35. int flags = -1;
  36. int length = -1;
  37. byte abyte0[] = ret;
  38. byte tmpB[] = new byte[4];
  39. System.arraycopy(abyte0, 0, tmpB, 0, 4);
  40. cmd = c.c(tmpB, false);
  41. if((cmd & 0xfffffff0) == 0)
  42. {
  43. System.arraycopy(abyte0, 4, tmpB, 0, 4);
  44. flags = c.c(tmpB, false);
  45. if((flags & -8) == 0)
  46. {
  47. System.arraycopy(abyte0, 8, tmpB, 0, 4);
  48. length = c.c(tmpB, false);
  49. if((length & 0xfffe0000) == 0)
  50. {
  51. byte sum1 = d.calcSum(abyte0);
  52. if(sum1 == abyte0[12])
  53. {
  54. lastflags = flags;
  55. logger.log(Level.INFO, (new StringBuilder("<<< cmd=")).append(cmd).append(",flags=").append(flags).append(",length=").append(length).toString());
  56. if(length != 0)
  57. {
  58. if(length >= 0x10000)
  59. {
  60. ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
  61. DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
  62. for(; length != 0; length -= ret.length)
  63. {
  64. byte out[] = my_a.readBytes(my_ch, 0x10000);
  65. try
  66. {
  67. dataoutputstream.write(out);
  68. continue;
  69. }
  70. catch(IOException ioexception) { }
  71. break;
  72. }
  73.  
  74. ret = bytearrayoutputstream.toByteArray();
  75. } else
  76. {
  77. ret = my_a.readBytes(my_ch, 0x10000);
  78. }
  79. } else
  80. {
  81. byte b[] = new byte[0];
  82. ret = b;
  83. }
  84. byte tmp[] = my_a.readBytes(my_ch, 4096);
  85. int sum = -1;
  86. int sum2 = -1;
  87. if(tmp.length == 4)
  88. sum = c.c(tmp, false);
  89. d testD = new d(cmd, false, false, false, ret);
  90. byte sumed[] = testD.getByteArray();
  91. byte sumed2[] = new byte[4];
  92. System.arraycopy(sumed, sumed.length - 4, sumed2, 0, 4);
  93. sum2 = c.c(sumed2, false);
  94. if(sum != sum2)
  95. logger.log(Level.INFO, (new StringBuilder("### read filed : checksum err! ")).append(hd.toHex(sum)).append("!=").append(hd.toHex(sum2)).toString());
  96. return ret;
  97. }
  98. }
  99. }
  100. }
  101. }
  102. catch(Exception exception) { }
  103. return null;
  104. }
  105.  
  106. private void testPluged()
  107. {
  108. byte ret[] = readReply();
  109. logger.log(Level.INFO, (new StringBuilder("<<<")).append(new String(ret)).toString());
  110. }
  111.  
  112. private void writeCmd(int cmd, byte body[])
  113. {
  114. d my_d = new d(cmd, false, true, false, body);
  115. logger.log(Level.INFO, (new StringBuilder("write(cmd=")).append(cmd).append(") (finish)").toString());
  116. try
  117. {
  118. my_a.writeBytes(my_ch, my_d.getByteArray());
  119. }
  120. catch(IOException e)
  121. {
  122. logger.log(Level.INFO, "### write failed");
  123. }
  124. }
  125.  
  126. private void writeCmd2(int cmd, byte body[])
  127. {
  128. d my_d = new d(cmd, false, true, true, body);
  129. logger.log(Level.INFO, (new StringBuilder("write(cmd=")).append(cmd).append(") (continue)").toString());
  130. try
  131. {
  132. my_a.writeBytes(my_ch, my_d.getByteArray());
  133. }
  134. catch(IOException e)
  135. {
  136. logger.log(Level.INFO, "### write failed");
  137. }
  138. }
  139.  
  140. private void testCmd01()
  141. {
  142. byte body[] = new byte[0];
  143. writeCmd(1, body);
  144. byte ret[] = readReply();
  145. logger.log(Level.INFO, (new StringBuilder("<<<")).append(new String(ret)).toString());
  146. }
  147.  
  148. private void testCmd07()
  149. {
  150. byte body[] = new byte[0];
  151. writeCmd(7, body);
  152. byte ret[] = readReply();
  153. logger.log(Level.INFO, (new StringBuilder("<<<")).append(new String(ret)).toString());
  154. }
  155.  
  156. private void testCmd09(byte area)
  157. {
  158. byte body[] = {
  159. area
  160. };
  161. writeCmd(9, body);
  162. readReply();
  163. }
  164.  
  165. private void testCmd10()
  166. {
  167. byte body[] = new byte[0];
  168. writeCmd(10, body);
  169. readReply();
  170. }
  171.  
  172. private void testCmd04(byte flag)
  173. {
  174. byte body[] = {
  175. flag
  176. };
  177. writeCmd(4, body);
  178. readReply();
  179. }
  180.  
  181. private void testCmd05(byte cert[])
  182. {
  183. byte body[] = cert;
  184. writeCmd(5, body);
  185. readReply();
  186. if(lastflags == 0)
  187. testCmd07();
  188. }
  189.  
  190. private void testCmd06(byte data[])
  191. {
  192. writeCmd(6, data);
  193. readReply();
  194. }
  195.  
  196. private void testCmd06_2(byte data[])
  197. {
  198. if(data != null && data.length < 65519)
  199. {
  200. writeCmd2(6, data);
  201. readReply();
  202. } else
  203. {
  204. byte body[] = new byte[65519];
  205. System.arraycopy(data, 0, body, 0, body.length);
  206. writeCmd2(6, body);
  207. readReply();
  208. body = new byte[data.length - 65519];
  209. System.arraycopy(data, 65519, body, 0, body.length);
  210. writeCmd2(6, body);
  211. readReply();
  212. }
  213. }
  214.  
  215. private byte[] testCmd12(int id)
  216. {
  217. byte body[] = c.a(id, 4, false);
  218. writeCmd(12, body);
  219. byte ret[] = readReply();
  220. if(ret != null)
  221. {
  222. if(ret.length != 0)
  223. {
  224. logger.log(Level.INFO, (new StringBuilder("<<<")).append(new String(ret)).toString());
  225. logger.log(Level.INFO, (new StringBuilder("<<<")).append(hd.toHex(ret)).toString());
  226. } else
  227. {
  228. logger.log(Level.INFO, "<<< null string");
  229. }
  230. } else
  231. {
  232. logger.log(Level.INFO, "<<< (null)");
  233. }
  234. return ret;
  235. }
  236.  
  237. private void testCmd13(int t)
  238. {
  239. byte bodies[][] = new byte[4][];
  240. byte body0[] = {
  241. 0, 0, 8, -77, 0, 0, 0, 4, -96, 0,
  242. 0, 0
  243. };
  244. byte body1[] = {
  245. 0, 0, 8, -3, 0, 0, 0, 16, 0, 0,
  246. 8, 0, 5, 0, 0, 0, 14, 0, 0, 0,
  247. 8, 0, 0, 0
  248. };
  249. byte body2[] = {
  250. 0, 0, 9, 97, 0, 0, 0, 4, -2, -1,
  251. -1, -1
  252. };
  253. byte body3[] = {
  254. 0, 0, 8, -77, 0, 0, 0, 4, -86, 0,
  255. 0, 0
  256. };
  257. bodies[0] = body0;
  258. bodies[1] = body1;
  259. bodies[2] = body2;
  260. bodies[3] = body3;
  261. if(t < bodies.length)
  262. {
  263. writeCmd(13, bodies[t]);
  264. readReply();
  265. }
  266. }
  267.  
  268. private void dumpProperties()
  269. {
  270. for(int i = 0; i < 3000; i++)
  271. {
  272. logger.log(Level.INFO, (new StringBuilder("%%% read property id=")).append(i).toString());
  273. byte ret[] = testCmd12(i);
  274. if(ret != null)
  275. try
  276. {
  277. FileOutputStream out = new FileOutputStream((new StringBuilder("prop_")).append(i).append(".bin").toString());
  278. out.write(ret);
  279. out.close();
  280. }
  281. catch(IOException e)
  282. {
  283. e.printStackTrace();
  284. }
  285. }
  286.  
  287. }
  288.  
  289. private void uploadImage(String fname, int blksize)
  290. {
  291. try
  292. {
  293. FileInputStream in;
  294. int len;
  295. byte tmp1[];
  296. tmp1 = new byte[6];
  297. in = new FileInputStream((new StringBuilder(String.valueOf(fname))).append(".rofs").toString());
  298. len = in.read(tmp1);
  299. if(len != 6)
  300. {
  301. in.close();
  302. return;
  303. }
  304. byte tmp2[];
  305. tmp2 = new byte[4];
  306. System.arraycopy(tmp1, 2, tmp2, 0, 4);
  307. len = c.c(tmp2, false);
  308. tmp2 = new byte[len - 6];
  309. len = in.read(tmp2);
  310. if(len != tmp2.length)
  311. {
  312. in.close();
  313. return;
  314. }
  315.  
  316. byte cert[] = new byte[len + 6];
  317. System.arraycopy(tmp1, 0, cert, 0, 6);
  318. System.arraycopy(tmp2, 0, cert, 6, cert.length - 6);
  319. testCmd05(cert);
  320. byte tmp[] = new byte[blksize];
  321. do
  322. {
  323. len = in.read(tmp);
  324. if(len != blksize)
  325. break;
  326. testCmd06_2(tmp);
  327. } while(true);
  328. in.close();
  329. if(len != 0)
  330. {
  331. byte data[] = new byte[len];
  332. System.arraycopy(tmp, 0, data, 0, len);
  333. testCmd06(data);
  334. }
  335. }
  336. catch(FileNotFoundException e)
  337. {
  338. logger.log(Level.INFO, (new StringBuilder("file ")).append(fname).append(".rofs not found. skip..").toString());
  339. }
  340. catch(IOException e)
  341. {
  342. e.printStackTrace();
  343. }
  344. return;
  345. }
  346.  
  347. private void uploadLoader(String fname, int blksize)
  348. {
  349. try
  350. {
  351. FileInputStream inL;
  352. int lenL;
  353. byte tmp1L[];
  354. tmp1L = new byte[6];
  355. inL = new FileInputStream((new StringBuilder(String.valueOf(fname))).append(".bin").toString());
  356. lenL = inL.read(tmp1L);
  357. byte tmpL[] = new byte[blksize];
  358. byte dataL[] = new byte[lenL];
  359. System.arraycopy(tmpL, 0, dataL, 0, lenL);
  360. testCmd06(dataL);
  361. inL.close();
  362. }
  363. catch(FileNotFoundException e)
  364. {
  365. logger.log(Level.INFO, (new StringBuilder("file ")).append(fname).append(".rofs not found. skip..").toString());
  366. }
  367. catch(IOException e)
  368. {
  369. e.printStackTrace();
  370. }
  371. return;
  372. }
  373.  
  374.  
  375.  
  376. private void run3()
  377. {
  378. //testCmd13(0);
  379. uploadImage("1", 0x10000);
  380. uploadImage("2", 0x10000);
  381. uploadImage("3", 0x10000);
  382. uploadImage("4", 0x10000);
  383. //testCmd13(1);
  384. //testCmd13(2);
  385. testCmd07();
  386. testCmd13(3);
  387. testCmd07();
  388. testCmd10();
  389. testCmd04((byte)1);
  390. }
  391.  
  392. private void run2()
  393. {
  394. uploadLoader("loader", 4096);
  395. testPluged();
  396. testCmd01();
  397. testCmd09((byte)2);
  398. run3();
  399. }
  400.  
  401. private void run()
  402. {
  403. testPluged();
  404. testCmd01();
  405. testCmd09((byte)2);
  406. testCmd10();
  407. run2();
  408. logger.log(Level.INFO, "###test end.");
  409. }
  410.  
  411. public static void main(String args[])
  412. {
  413. System.loadLibrary("USBFlash");
  414. my_a = com.sonyericsson.cs.usbflashnative.b.a.a();
  415. if(logger == null)
  416. {
  417. logger = Logger.getLogger("mytest.logging");
  418. try
  419. {
  420. FileHandler fh = new FileHandler("U5flash-log.txt");
  421. fh.setFormatter(new SimpleFormatter());
  422. logger.addHandler(fh);
  423. logger.setLevel(Level.ALL);
  424. }
  425. catch(SecurityException securityexception) { }
  426. catch(IOException ioexception) { }
  427. }
  428. logger.log(Level.INFO, "start");
  429. try{
  430. BufferedReader in=new BufferedReader(new FileReader("DeviceID.txt"));
  431. str=in.readLine();
  432. in.close();
  433. }
  434.  
  435. catch(Exception e){}
  436. try
  437. {
  438. my_ch = my_a.openChannel("USB\\VID_0FCE&PID_ADDE\\" + str, false);
  439. }
  440. catch(IOException e)
  441. {
  442. e.printStackTrace();
  443. }
  444. me = new U5flash();
  445. me.run();
  446. my_a.close(my_ch);
  447. }
  448.  
  449. }



Mon erreur est:

  1. Exception in thread "main" java.lang.NullPointerException
  2. at java.lang.String.<init>(String.java:593)
  3. at U5flash.testPluged(U5flash.java:103)
  4. at U5flash.run2(U5flash.java:389)
  5. at U5flash.run(U5flash.java:401)
  6. at U5flash.main(U5flash.java:439)


Merci de bien vouloir m'aider.

Autres pages sur : probleme java

a c 232 L Programmation
24 Septembre 2010 09:30:15

Salut,

Tu as une exception sur la ligne numérotée 109 (dans ton code), qui correspond à la ligne 4 là-dessous "logger.log(...)"
  1. private void testPluged()
  2. {
  3. byte ret[] = readReply();
  4. logger.log(Level.INFO, (new StringBuilder("<<<" )).append(new String(ret)).toString());
  5. }
m
0
l
Tom's guide dans le monde
  • Allemagne
  • Italie
  • Irlande
  • Royaume Uni
  • Etats Unis
Suivre Tom's Guide
Inscrivez-vous à la Newsletter
  • ajouter à twitter
  • ajouter à facebook
  • ajouter un flux RSS