java.lang.NullPointerException when assigning new file

Hi,
I'm trying to assign path to a file..
I'm getting the path from text Filed, then set it using set method..
finally, putting the path in a File..

here is the code till now,,

setting the pcImagePath
	
	public String getPcImagePath() {
		return pcImagePath;
	}
	public void setPcImagePath(String pcImagePath) {
		this.pcImagePath = pcImagePath;
		System.out.println(this.pcImagePath);
	}

Open in new window

the path which is from text Filed printed correctly here ..

then taking the path string from the text field and set it  
path.setPcImagePath(txtPathToStore.getText());

Open in new window


then trying to assign a file to that path

pcImageFile = new File(path.getPcImagePath());

Open in new window

but here it gives me an exception  java.lang.NullPointerException

is there any assignment of objects problem ??

sorry if it is not clear, I'm not that good in java :)
omarkkkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gurpsbassiCommented:
I guess your call to txtPathToStore.getText() is returning null.

Put a print statement before your assignment e.g.

System.out.println("text value = " + txtPathToStore.getText()); // this could be returning null.
path.setPcImagePath(txtPathToStore.getText());
omarkkkAuthor Commented:
Hi gurpsbassi,
I made a fast printing statement before set, and it works and prints the path..
ext: /Volumes/development/ScreenShots

do I have to put the path in a stream or such thing before the setting it ?
gurpsbassiCommented:
please show the stack trace of the exception
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

omarkkkAuthor Commented:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
      at java.io.File.<init>(File.java:277)
      at com.omar.aap.ScreenShotPanel.<init>(ScreenShotPanel.java:31)
      at com.omar.aap.MainWindow$4.actionPerformed(MainWindow.java:153)
      at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
      at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
      at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
      at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
      at java.awt.Component.processMouseEvent(Component.java:6527)
      at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
      at java.awt.Component.processEvent(Component.java:6292)
      at java.awt.Container.processEvent(Container.java:2234)
      at java.awt.Component.dispatchEventImpl(Component.java:4883)
      at java.awt.Container.dispatchEventImpl(Container.java:2292)
      at java.awt.Component.dispatchEvent(Component.java:4705)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
      at java.awt.Container.dispatchEventImpl(Container.java:2278)
      at java.awt.Window.dispatchEventImpl(Window.java:2739)
      at java.awt.Component.dispatchEvent(Component.java:4705)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
      at java.awt.EventQueue.access$400(EventQueue.java:97)
      at java.awt.EventQueue$3.run(EventQueue.java:697)
      at java.awt.EventQueue$3.run(EventQueue.java:691)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
      at java.awt.EventQueue$4.run(EventQueue.java:719)
      at java.awt.EventQueue$4.run(EventQueue.java:717)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
gurpsbassiCommented:
Also which line in your program comes first

path.setPcImagePath(txtPathToStore.getText());

or

pcImageFile = new File(path.getPcImagePath());
omarkkkAuthor Commented:
path.setPcImagePath(txtPathToStore.getText()); comes first

the steps are as follows:
getting the pcImagePath
set it
and creating the file which is
pcImageFile = new File(path.getPcImagePath());

I defined a the pcImageFile as a filed
private File pcImageFile;
gurpsbassiCommented:
post your com.omar.aap.ScreenShotPanel class
CEHJCommented:
The problem is in the ctor of ScreenShotPanel. This is most probably causing a null path to be given to the File ctor (which throws the exception)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
:)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.