Nodeclipse / nodeclipse

Nodeclipse-1 : Eclipse plugin for Node.js, PhantomJS development (Nodeclipse core plugin); Maven and Gradle (with Android) plugins
https://nodeclipse.github.io/
158 stars 76 forks source link

PhantomJS Project in Eclipse (with Nodeclipse): NullPointerException when trying to run js file that is present in a folder #188

Closed Manali-J closed 9 years ago

Manali-J commented 9 years ago

Nodeclipse plugin version: Nodeclipse PhantomJS 0.17 (see screenshot nodeclipse 0.17) Eclipse Version: Luna Service Release 1 (4.4.1) Stackoverflow question: http://stackoverflow.com/questions/29457542/phantomjs-project-in-eclipse-with-nodeclipse-nullpointerexception-when-trying

Reproducible: Yes - consistently

Description: After creating a PhantomJS Project, if we create a javascript file and place it in any folder created under the project and try to run the .js file, a NullPointerException is being thrown in Eclipse. Note that if we don't create any folder structure under the project and try to run the .js files, the scripts run fine. Basically, any attempt to run a script placed inside a folder gives an error. (see screenshot "Folder structure.png").

Steps:

  1. Install Nodeclipse PhantomJS plugin 0.17 from the Eclipse marketplace
  2. Launch Eclipse and click on File->New->PhantomJS Project
  3. Give a name the project, enter other details and click on Finish
  4. Under your PhantomJS project, create any folder
  5. Right click on the folder created and select New->JavaScript file
  6. Enter any piece of code in the .js file (Ex. console.log("Hello World");) and run the .js file.

Expected result: Script should run without any errors

Actual result: User is getting a NullPointerException. (see screenshots Error1.png and Error2.png)

Exception details:

An internal error occurred during: "Launching PhantomJSTest-Test1.js". java.lang.NullPointerException

Additional details:

java.lang.NullPointerException at org.nodeclipse.phantomjs.launch.LaunchConfigurationDelegate.launch(LaunchConfigurationDelegate.java:81) at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:885) at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:739) at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1039) at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1256) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

nodeclipse 0 17 error2 nullpointerexception error1 folder structure

paulvi commented 9 years ago

First, thank for the first feedback on PhantomJS plugin.

I have tried using Phantom 1.9.2 on Windows 7, Nodeclipse:0.17.0.201409260953 Eclipse:4.4.0.v20140606-1215 Java:1.8.0_05 OS:win32,x86_64

And it worked well when launching from Project Explorer or from Editor

pha

What is your path to phantom.exe ? Does it have spaces or other suspicious characters?

Mine is "D:\Progs\phantomjs-1.9.2-windows\phantomjs.exe"

P.S. I even tried "D:\Progs\phantomjs-1.9.2-windows - 副本\phantomjs.exe" and it worked. No idea for now, why it may fails.

Can you get https://github.com/Nodeclipse/nodeclipse-1/tree/master/org.nodeclipse.phantomjs project and run/debug it?

Manali-J commented 9 years ago

The path for me is D:\phantomjs.exe. Is there any important point I am missing? My phantomjs version 1.9.2.

paulvi commented 9 years ago

Well, "D:\phantomjs.exe" is not nice (root of drive D:), but it should work (like any)

I have looked at source org.nodeclipse.phantomjs.launch.LaunchConfigurationDelegate.launch(LaunchConfigurationDelegate.java:81)

it is

String filePath = ResourcesPlugin.getWorkspace().getRoot().findMember(file).getLocation().toOSString();

What is special about your js file?

Try debug https://github.com/Nodeclipse/nodeclipse-1/tree/master/org.nodeclipse.phantomjs

Manali-J commented 9 years ago

Actually I've tried two paths - "D:\MANALI\phantomjs-1.9.2-windows\phantomjs-1.9.2-windows\phantomjs.exe" and "D:\phantomjs.exe". Issue happens after I create a folder in the project and then try to run the js file.

The js file had this script which works fine when I don't create a folder -

var page = require('webpage').create();
page.open('http://example.com', function(status) {
  console.log("Status: " + status);
  if(status === "success") {
    page.render('example.png');
  }
  phantom.exit();
});

Should I consider doing a fresh install of Eclipse & Nodeclipse?

paulvi commented 9 years ago

The Phantom path is path to Phantom executable, so it should have .exe in the end.

Fresh install of Eclipse & Nodeclipse would make no difference.

Try debug yourself https://github.com/Nodeclipse/nodeclipse-1/tree/master/org.nodeclipse.phantomjs

or guess what is wrong with String filePath = ResourcesPlugin.getWorkspace().getRoot().findMember(file).getLocation().toOSString(); line. I ran out of ideas.

paulvi commented 9 years ago

What is .js file path? What is Project path?

Manali-J commented 9 years ago

.js path - "D:\MANALI\WORKSPACE\PhantomJSTest\test\Test1.js" Project path - D:\MANALI\WORKSPACE\PhantomJSTest

paulvi commented 9 years ago

Tried again with Eclipse 4.4.2 all works fine.

Manali-J commented 9 years ago

I have followed all the instructions from this link.

This is what is causing the issue (below screenshot). I have tried copying the node_modules to the project but that did not help and I'm not sure which environment variable has to be set. I'm still looking.

image

paulvi commented 9 years ago

Well, from "Eclipse Installation Detail" it seems that you have not installed Nodeclipse Nodejs Feature Set. I have never yet had Eclipse with PhantomJS, but without Nodejs...

Also you have also a lot of stuff like C++, Python... Maybe it may cause. So yes please try one more clean Eclipse instance or Enide Studio.

Manali-J commented 9 years ago

I don't know what the problem was with installing the Nodeclipse plugin. So, I downloaded the Enide Studio and I am not facing any issues with folder structures now.

For a PhantomJS Project, I needed only the following two things:

  1. Enide Studio 2014
  2. PhantomJS

Thank you for being so patient.