Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default Error While Opening A PDF file

    I am getting this error . . .

    test.java:5: unreported exception java.io.IOException; must be caught or declared to be thrown
    Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler Tic Tac Toe itemStrategy.pdf");
    ^
    1 error

    java.lang.NoClassDefFoundError: test
    Caused by: java.lang.ClassNotFoundException: test
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
    Could not find the main class: test. Program will exit.
    Exception in thread "main"

    Code is
    Java Code:
    public class test 
    {
    	public static void main (String[] args) {
    	
    		Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler " + "Guide.pdf");
    	}
    }
    or Is there any alternative way to open a file from directory other than images etc ???
    Last edited by Cluster Storm; 06-07-2010 at 03:53 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default

    It's not erroring trying to open the file, it's not even compiling.
    This:
    unreported exception java.io.IOException; must be caught or declared to be thrown
    is a compilation error.
    You need to either catch or throw the exception.

  3. #3
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default

    As you said you need to either catch or throw the exception . .
    I use try and catch block . . .
    Now i am getting this compile time error . . .

    test.java:14: reached end of file while parsing
    }


    Modified code is :

    Java Code:
    public class test 
    {
    	public static void main ( String[] args ) {
    			
    	try
    	{
      		Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler " + "Tic Tac Toe itemStrategy.pdf" );
    	}
    	catch ( Exception  e )
    	{
      		System.err.print( e.getMessage() );
    	}
    
    }
    This problem is appearing now, before that when i run first time it work properly . . . but now it is giving me an error . . .

    Is there any alternative way to do such type of task ???

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default

    Again...compilation error.
    Count your brackets.

  5. #5
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default

    Ok i recover this error . . . but the file is not opening ??? What i do ?? You don't have any alternate way to open a file ??

    Please

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default

    No idea what it is you're trying to do, frankly, but that exec looks flaky.

    You could have a look at the runtime traps article.

    It's generally best to split an exec call up into a String[], so (from the article):
    Java Code:
    String[] cmd = new String[3];
    cmd[0] = "cmd.exe" ;
    cmd[1] = "/C" ;
    cmd[2] = "some command";

  7. #7
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

Similar Threads

  1. Jre upgrade Issue :java.util.zip.ZipException: error in opening zip file
    By selvakumar.velmurugesan in forum New To Java
    Replies: 0
    Last Post: 10-27-2009, 05:20 AM
  2. Replies: 1
    Last Post: 10-26-2009, 04:38 PM
  3. Opening a custom proyect file
    By janpol1 in forum Eclipse
    Replies: 0
    Last Post: 02-04-2009, 02:29 PM
  4. Replies: 3
    Last Post: 01-26-2009, 05:30 PM
  5. Problem in opening a file
    By Raghav kv in forum New To Java
    Replies: 1
    Last Post: 08-11-2007, 01:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •