• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1363
  • Last Modified:

ifstream::getline exception???? help please!!!

My application is running the difficult part, but what should be the easy part is blowing up in my face
I have a java GUI using JNI to call a cpp .dll file. I tried to pass an object to the native method, this gave me all sorts of problems so I decided to csrap that, now the app just calls the native method and stores the object in a text file, then the cpp method opens the text file and is supposed to read just 6 pieces of string and work on from there. However when I run the program it throws an exception claiming there is a problem with the getline function in the dll.

the java code looks like so:

public void Login(){
                MachineDetails dClass = new MachineDetails();//object storing the details
      dClass.BSTRMachineName = jTextField1.getText();     //
      dClass.UserName          = jTextField2.getText();         //  These are strings
      dClass.PassWd          = jPasswordField1.getText(); //

      dClass.AvailMemory     = jCheckBox1.isSelected();      //
      dClass.LoadPercentage  = jCheckBox2.isSelected();    //   These are boolean
      dClass.DiskSpaceFree   = jCheckBox3.isSelected();     //

      FileOutputStream out;
      PrintStream p;
            out = new FileOutputStream("machineDetails.dat");
            p = new PrintStream( out );

            p.println (dClass.BSTRMachineName);
            p.println (dClass.UserName);
            p.println (dClass.PassWd);
            p.println (dClass.AvailMemory);
            p.println (dClass.DiskSpaceFree);
            p.println (dClass.LoadPercentage);

      }catch(Exception e)
            System.err.println ("Error writing to file");

      driver(); //call the native method.
This compiles fine and the .dat file displays what it is supposed to so I dont think there is any problem with the java
Here is the native method source code which starts up fine but crashes when it tries to access the data in the .dat file.

JNIEXPORT void JNICALL Java_guineyd_java_ProgramStartup_driver
  (JNIEnv * env, jobject obj)
      printf("We have lift off");      //just to show that JNI is working ok.
      char* javaMcName = NULL;
      char* javaUserName = NULL;
      char* javaPassWd = NULL;
      char* javaAvailMemory = NULL;
      char* javaDiskSpaceFree = NULL;
      char* javaLoadPercentage = NULL;

      ifstream input("machineDetails.dat");
      if (input.fail()){
            printf("Cannot open machinDetails.dat");
                printf("data file opened ok\n");  //This proves that the data file opened

      input.getline(javaMcName, 100, '\n');//, 1024, '\n');
      input.getline(javaUserName, 100, '\n');
      input.getline(javaPassWd, 100, '\n');
      input.getline(javaAvailMemory, 6, '\n');
      input.getline(javaDiskSpaceFree, 6, '\n');
      input.getline(javaLoadPercentage, 6, '\n');

                .....................//work on with the data ..........
I have two printf statements to show how far the program actually goes.
This is what I get when I run the app.


We have lift off         //Here you can see the two printf statements working properly.
data file opened ok   //

An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x208
Function=std::basic_istream<char,std::char_traits<char> >::getline+0x1B0   //function is getline?????

Current Java thread:
        at guineyd.java.ProgramStartup.driver(Native Method)
        at guineyd.java.ProgramStartup.Login(ProgramStartup.java:237)
        at guineyd.java.ProgramStartup$Window_actionAdapter.actionPerformed(Prog
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:17
        at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
        at java.awt.Component.processMouseEvent(Component.java:5100)
        at java.awt.Component.processEvent(Component.java:4897)
        at java.awt.Container.processEvent(Container.java:1569)
        at java.awt.Component.dispatchEventImpl(Component.java:3615)
        at java.awt.Container.dispatchEventImpl(Container.java:1627)
        at java.awt.Component.dispatchEvent(Component.java:3477)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
        at java.awt.Container.dispatchEventImpl(Container.java:1613)
        at java.awt.Window.dispatchEventImpl(Window.java:1606)
        at java.awt.Component.dispatchEvent(Component.java:3477)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

Dynamic libraries:
0x00400000 - 0x00406000         C:\JBuilderX\jdk1.4\bin\java.exe
0x77F80000 - 0x77FFD000         C:\WINNT\system32\ntdll.dll
0x7C2D0000 - 0x7C332000         C:\WINNT\system32\ADVAPI32.dll
0x7C570000 - 0x7C628000         C:\WINNT\system32\KERNEL32.DLL
0x77D30000 - 0x77DA1000         C:\WINNT\system32\RPCRT4.DLL
0x78000000 - 0x78045000         C:\WINNT\system32\MSVCRT.dll
0x08000000 - 0x08136000         C:\JBuilderX\jdk1.4\jre\bin\client\jvm.dll
0x77E10000 - 0x77E75000         C:\WINNT\system32\USER32.dll
0x77F40000 - 0x77F7E000         C:\WINNT\system32\GDI32.DLL
0x77570000 - 0x775A0000         C:\WINNT\system32\WINMM.dll
0x10000000 - 0x10007000         C:\JBuilderX\jdk1.4\jre\bin\hpi.dll
0x007C0000 - 0x007CE000         C:\JBuilderX\jdk1.4\jre\bin\verify.dll
0x007D0000 - 0x007E8000         C:\JBuilderX\jdk1.4\jre\bin\java.dll
0x007F0000 - 0x007FD000         C:\JBuilderX\jdk1.4\jre\bin\zip.dll
0x18270000 - 0x1837F000         C:\JBuilderX\jdk1.4\jre\bin\awt.dll
0x77800000 - 0x7781E000         C:\WINNT\system32\WINSPOOL.DRV
0x76620000 - 0x76630000         C:\WINNT\system32\MPR.DLL
0x75E60000 - 0x75E7A000         C:\WINNT\system32\IMM32.dll
0x77A50000 - 0x77B3F000         C:\WINNT\system32\ole32.dll
0x18380000 - 0x183D0000         C:\JBuilderX\jdk1.4\jre\bin\fontmanager.dll
0x51000000 - 0x5104B000         C:\WINNT\system32\ddraw.dll
0x728A0000 - 0x728A6000         C:\WINNT\system32\DCIMAN32.dll
0x5C000000 - 0x5C0C7000         C:\WINNT\system32\D3DIM700.DLL
0x20860000 - 0x20890000         C:\COLLEGE\attempt\cpp\guineyd\guineyd.dll
0x779B0000 - 0x77A4B000         C:\WINNT\system32\OLEAUT32.dll
0x20890000 - 0x2094C000         C:\WINNT\system32\MSVCP71D.dll
0x20950000 - 0x209D7000         C:\WINNT\system32\MSVCR71D.dll
0x77920000 - 0x77943000         C:\WINNT\system32\imagehlp.dll
0x72A00000 - 0x72A2D000         C:\WINNT\system32\DBGHELP.dll
0x690A0000 - 0x690AB000         C:\WINNT\system32\PSAPI.DLL

Heap at VM Abort:
 def new generation   total 576K, used 81K [0x10010000, 0x100b0000, 0x104f0000)
  eden space 512K,   3% used [0x10010000, 0x10014420, 0x10090000)
  from space 64K, 100% used [0x10090000, 0x100a0000, 0x100a0000)
  to   space 64K,   0% used [0x100a0000, 0x100a0000, 0x100b0000)
 tenured generation   total 1408K, used 277K [0x104f0000, 0x10650000, 0x14010000
   the space 1408K,  19% used [0x104f0000, 0x105355f8, 0x10535600, 0x10650000)
 compacting perm gen  total 4352K, used 4226K [0x14010000, 0x14450000, 0x1801000
   the space 4352K,  97% used [0x14010000, 0x14430890, 0x14430a00, 0x14450000)

Local Time = Mon May 03 00:35:37 2004
Elapsed Time = 5
# The exception above was detected in native code outside the VM
# Java VM: Java HotSpot(TM) Client VM (1.4.2_01-b06 mixed mode)
# An error report file has been saved as hs_err_pid2248.log.
# Please refer to the file for further information.
Press any key to continue . . .


I know its a long load of code to go through but Im realy desperate, I have to have thios thing working very soon, please.

  • 3
1 Solution
For what it's worth, 0xc0000005 is an access denied.

I presume it happened on the first getline()?
vassimAuthor Commented:
Im not sure, I presume so, I tried making all the attributes in the MachineDetails class in the java as public but it didnt work.

Why would it deny me access when its just reading a text file????
javaMcName is typed as a pointer to a string and initialized to NULL.

The getline() then tries to store its input string to location NULL.

You should either

char javaMcName[someappropriateamount];

or, with its current declaration as a char *

javaMcName=(char *)malloc(someappropriateamount);

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now