Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: JVM failed to initialize

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JVM failed to initialize

    What's up with this. Just trying to test my hands on java packages, and had this error(by java) after successful compilation:

    Error occurred during initialization of VM
    java.lang.Error: Properties init: Could not determine current working directory.
    at java.lang.System.initProperties(Native Method)
    at java.lang.System.initializeSystemClass(System.java :1119)

    Main.java
    package com.aceix.simplecalc;
     
    import com.aceix.simplecalc.inputhandler.InputHandler;
    import com.aceix.simplecalc.mathoperation.MathOperation;
     
    public class Main {
     
    	public static void main(String[] args) {
    		try {
    			System.out.println("Welcome to Aceix's simplecalc v1.0");
     
    			double num1=Double.parseDouble((InputHandler.getInput("Enter a number: ")));
    			double num2=Double.parseDouble(InputHandler.getInput("\nEnter another number: "));
    			int op=Integer.parseInt(InputHandler.getInput("1. Add\n2. Subtract\n3. Multiply\n4. Divide\nSelection: "));
    			double ans=0.0d;
     
    			switch (op) {
    			case 1:
    				ans=MathOperation.add(num1, num2);
    				break;
    			case 2:
    				ans=MathOperation.subtract(num1, num2);
    				break;
    			case 3:
    				ans=MathOperation.multiply(num1, num2);
    				break;
    			case 4:
    				ans=MathOperation.divide(num1, num2);
    				break;
     
    			default:
    				System.out.println("Invalid selection!!!");
    				break;
    			}
     
    			System.out.println("\n\n\nYou result is: "+ans);
     
    			return;
    		} catch (Exception e) {
    			e.getMessage();
    		}
    	}
     
    }

    MathOperation.java
    package com.aceix.simplecalc.mathoperation;
     
    public class MathOperation {
    	public static double add(double lhs, double rhs) {
    		return lhs+rhs;
    	}
    	public static double subtract(double lhs, double rhs) {
    		return lhs-rhs;
    	}
    	public static double multiply(double lhs, double rhs) {
    		return lhs*rhs;
    	}
    	public static double divide(double lhs, double rhs) {
    		return lhs/rhs;
    	}
    }

    InputHandler.java
    package com.aceix.simplecalc.inputhandler;
     
    public class InputHandler {
    	public static String getInput(String prompt) {
    		System.out.println(prompt);
     
    		return System.console().readLine().trim();
    	}
    }

    And please show me a suitable way to accept input from console.

    Thanks,
    Aceix.


  2. #2
    Member
    Join Date
    Sep 2013
    Posts
    68
    My Mood
    Confused
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: JVM failed to initialize

    In your InputHandler class you are using
    System.console().readLine().trim();
    to get the input but if you are using any IDE like eclipse then this code is not going to work.

    It's better if you take Scanner class to accept input from console.

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JVM failed to initialize

    Yeah thanks. I used BufferredReader with the InputBufferReader class, enveloping the System.in standard input stream, since I was having some trouble with the Scanner.next(); funtcion.

    Aceix.

Similar Threads

  1. Var Might have been initialize
    By Evilreaper in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 15th, 2012, 10:27 AM
  2. [SOLVED] using the return of a method to initialize an ArrayList
    By mia_tech in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 25th, 2012, 05:05 PM
  3. Initialize Map size
    By mano123 in forum Collections and Generics
    Replies: 2
    Last Post: May 29th, 2012, 12:05 AM
  4. Re-Initialize array without loosing contents..
    By Mr.777 in forum Java Theory & Questions
    Replies: 7
    Last Post: June 17th, 2011, 05:47 AM
  5. I'm not sure how to initialize GraphicsDevice and Window
    By DotChris in forum AWT / Java Swing
    Replies: 3
    Last Post: July 15th, 2009, 09:00 AM