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

Posted on 2004-05-02
Last Modified: 2007-12-19
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 ({
            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 Method)
        at javax.swing.AbstractButton.fireActionPerformed(
        at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
        at javax.swing.DefaultButtonModel.setPressed(
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
        at java.awt.Component.processMouseEvent(
        at java.awt.Component.processEvent(
        at java.awt.Container.processEvent(
        at java.awt.Component.dispatchEventImpl(
        at java.awt.Container.dispatchEventImpl(
        at java.awt.Component.dispatchEvent(
        at java.awt.LightweightDispatcher.retargetMouseEvent(
        at java.awt.LightweightDispatcher.processMouseEvent(

        at java.awt.LightweightDispatcher.dispatchEvent(
        at java.awt.Container.dispatchEventImpl(
        at java.awt.Window.dispatchEventImpl(
        at java.awt.Component.dispatchEvent(
        at java.awt.EventQueue.dispatchEvent(
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
        at java.awt.EventDispatchThread.pumpEvents(

        at java.awt.EventDispatchThread.pumpEvents(


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.

Question by:vassim
  • 3
LVL 22

Expert Comment

ID: 10974001
For what it's worth, 0xc0000005 is an access denied.

I presume it happened on the first getline()?

Author Comment

ID: 10974019
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????
LVL 22

Accepted Solution

cookre earned 500 total points
ID: 10974201
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.

LVL 22

Expert Comment

ID: 10974206
You should either

char javaMcName[someappropriateamount];

or, with its current declaration as a char *

javaMcName=(char *)malloc(someappropriateamount);


Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question