2017-06-15 129 views
0
public static void sendScenarioToEdc(String connectionType, String ipOrBaudrate, String portOrCom, String timeout, String profile) { 
    loadEcrLib();  
    File file = new File (ApplicationConstans.PROFILE_FOLDER +profile+ ".csv"); 
    // create parameter for the dll 
    String param = createParameter(connectionType, ipOrBaudrate, portOrCom, timeout); 
    List<Transaction> transactions = new ArrayList<Transaction>(); 
    String[] messages = CsvUtil.readRequestMessage(file); 
     for (String message : messages) { 

      Transaction t = new Transaction(); 
      t.setRequestMsg(message); 
      EcrInterface ecrLib = EcrInterface.INSTANCE; 
      Pointer stringMem = new Memory(3000); 
      stringMem.setString(0, " "); 
      Pointer response = stringMem.getPointer(0); 

      // notify the user before hand 
      System.out.println("Request: "+ t.getRequestMsg()); 
      long time = System.currentTimeMillis(); 
      Integer status = ecrLib.procEdcTrans(message, response, param); //send message here 
      t.setResponseStatus(status.toString()); 
      t.setResponseTime(System.currentTimeMillis() - time); 
      t.setResponseMsg(response.getString(0).replace("ÿ", "")); // trim 0x255 characters 

      System.out.println("Response: "+ t.getResponseMsg()); 
      System.out.println("Time: "+ (t.getResponseTime()/1000) + "." + (t.getResponseTime() % 1000) + " s"); 
      System.out.println("Status: "+ t.getResponseStatus()); 

返回错误java.lang.OutOfMemoryError:无法分配3000字节无法分配内存小“java.lang.OutOfMemoryError:无法分配3000个字节”

程序为何不能分配这么小的内存? 我也用这个参数“java -Xmx2048m -Xms512m”来配置内存堆,但是这并没有解决问题。

这里是跟踪:

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Cannot allocate 3000 bytes 
at com.sun.jna.Memory.<init>(Memory.java:70) 
at com.kartuku.utils.SenderUtil.sendScenarioToEdc(SenderUtil.java:98) 
at com.kartuku.ui.Main1.btnRunMouseClicked(Main1.java:581) 
at com.kartuku.ui.Main1.access$000(Main1.java:31) 
at com.kartuku.ui.Main1$1.mouseClicked(Main1.java:123) 
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270) 
at java.awt.Component.processMouseEvent(Component.java:6536) 
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324) 
at java.awt.Component.processEvent(Component.java:6298) 
at java.awt.Container.processEvent(Container.java:2236) 
at java.awt.Component.dispatchEventImpl(Component.java:4889) 
at java.awt.Container.dispatchEventImpl(Container.java:2294) 
at java.awt.Component.dispatchEvent(Component.java:4711) 
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888) 
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4534) 
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466) 
at java.awt.Container.dispatchEventImpl(Container.java:2280) 
at java.awt.Window.dispatchEventImpl(Window.java:2746) 
at java.awt.Component.dispatchEvent(Component.java:4711) 
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) 
at java.awt.EventQueue.access$500(EventQueue.java:97) 
at java.awt.EventQueue$3.run(EventQueue.java:709) 
at java.awt.EventQueue$3.run(EventQueue.java:703) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) 
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90) 
at java.awt.EventQueue$4.run(EventQueue.java:731) 
at java.awt.EventQueue$4.run(EventQueue.java:729) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) 
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) 
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) 
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) 
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) 
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) 
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) 
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) 

程序无法分配为指针stringmem

+0

你能粘贴堆栈跟踪细节吗? – haifzhan

+0

无法为指针分配内存“指针stringMem =新内存(3000);” –

+0

@naufal将整个错误消息放在问题中。 –

回答

0

这么小的内存此错误通常意味着您的计算机内存不足。尝试让任务管理器同时打开,看看你的内存使用情况如何,如果它在3mb以内,那就是问题所在。如果没有,那么Java很可能没有足够的空间来运行。

+0

我的电脑有4GB内存,并有1GB可用 –

+0

我试过在另一台电脑上运行,但同样的问题发生了 –

+0

@naufal等待,1GB是程序启动时,或者当它崩溃时?另一台电脑有多少ram? –

相关问题