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 1 of 1

Thread: Problem creating text file using the using class.getResource()

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem creating text file using the using class.getResource()

    Hi
    I'm having a problem with this code im creating a small application that just creates a txt file in my resource folder the problem is is I keep getting this exception
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    Now I dont get this exception if I change my code to this but I actually want to run this app as a standalone so this code wouldnt be effiencent help would be grateful

    public void directoryFile()
    	{
    		path = Paths.get( "C:/Users/Genesis/Desktop/cv/My Applications/" +
    		                 	"Running Jar File Image Directory/Load Folders With Jar File 4/src/resources/jenny.txt" );
     
    	}


    package loadFileWithJarFile;
     
    import java.io.IOException;
    import java.net.URISyntaxException;
    import java.nio.file.Files;
    import java.nio.file.Path;
    import java.nio.file.Paths;
     
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;
     
    public class LoadFileWithJar extends JFrame 
    {
     
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
     
    	private Path path;
     
    	public LoadFileWithJar() 
    	{
    		// TODO Auto-generated constructor stub
    		super();
    		setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
     
    		makeTextFile();
     
    		setSize( 500, 500 );
    		setVisible( true );
    	}
     
    	public void directoryFile()
    	{
     
    		try 
    		{
    			path = Paths.get( LoadFileWithJar.class.getResource( "/resources/jeny.txt" ).toURI()  );
    		} 
    		catch (URISyntaxException e)
    		{
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}			
    	}
     
    	public void makeTextFile() 
    	{
    		directoryFile();
     
    		try 
    		{
    			Files.createFile( path );
    		}
    		catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
     
    	}
     
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) 
    	{
    		// TODO Auto-generated method stub
    		SwingUtilities.invokeLater( new Runnable() 
    		{
     
    			@Override
    			public void run() 
    			{
    				// TODO Auto-generated method stub
    				new LoadFileWithJar();				
    			}
     
    		});
     
    	}
     
    }
    Attached Images Attached Images


Similar Threads

  1. Replies: 1
    Last Post: November 19th, 2012, 05:44 AM
  2. Replies: 5
    Last Post: October 18th, 2012, 01:43 PM
  3. Problem in Creating Jar file
    By sikriyogesh in forum Member Introductions
    Replies: 0
    Last Post: November 20th, 2009, 02:12 AM
  4. Creating a class file
    By ipatch in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 8th, 2009, 07:19 PM
  5. Creating variables from a text file
    By Larz0rz in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: October 4th, 2009, 11:57 PM