Showing posts with label NetBeans. Show all posts
Showing posts with label NetBeans. Show all posts

Monday, July 6, 2020

git in NetBeans: Contains files that are in conflict - Solved


After you switch to a different branch, you notice that there is a red cylinder mark next to the project icon. When you hover over it, a message shows up and it says "Contains files that are in conflict".



To fix it, right-click on the project, choose Git, then Resolve Conflict.


In the pop-up window, choose either Remove File From Index or Keep Current File Content.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Thursday, December 12, 2019

NetBeans: java.nio.file.AccessDeniedException thrown when copying jars to your library

After you have your coding done, you do a Clean and Build, and you see the following error message in your Output pane.

Copy libraries to C:\MyProjects\lib.
Attempt to copy C:\dynamicreports-3.2.0\lib\xalan-2.7.1.jar to C:\MyProjects\lib\xalan-2.7.1.jar using NIO Channels failed due to 'C:\MyProjects\lib\xalan-2.7.1.jar'.  Falling back to streams.
C:\MyProjects\nbproject\build-impl.xml:1212: The following error occurred while executing this line:
C:\MyProjects\nbproject\build-impl.xml:1035:
java.nio.file.AccessDeniedException: C:\MyProjects\lib\xalan-2.7.1.jar
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:83)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:230)
at java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:434)
at java.nio.file.Files.newOutputStream(Files.java:216)
at org.apache.tools.ant.util.FileUtils.newOutputStream(FileUtils.java:1721)
at org.apache.tools.ant.types.resources.FileResource.getOutputStream(FileResource.java:267)
at org.apache.tools.ant.types.resources.FileResource.getOutputStream(FileResource.java:241)
at org.apache.tools.ant.util.ResourceUtils.getOutputStream(ResourceUtils.java:791)
at org.apache.tools.ant.util.ResourceUtils.copyUsingStreams(ResourceUtils.java:765)
at org.apache.tools.ant.util.ResourceUtils.copyResource(ResourceUtils.java:435)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:565)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:525)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:486)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:449)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:415)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:390)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:328)
at org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs.execute(CopyLibs.java:218)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor172.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at java.util.Vector.forEach(Vector.java:1275)
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:67)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor172.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:391)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor172.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388)
at org.apache.tools.ant.Project.executeTarget(Project.java:1361)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:261)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:574)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:128)

To fix this problem, do one of the following.

1. Change the accessibility of your library folder.
     Right-click on the folder and select Properties. In the pop-up window, select the Security tab.               Select each group of users, click the Edit button to change their permission to access this folder.
2. Run your NetBeans as Administrator.
    Righ-click on your NetBeans icon and select Run as administrator.
3. Remove all the unused jar files from the lib directory.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Friday, August 9, 2019

NetBeans: Migrate from an early JDK to Java 8 or a later version

After you have updated the Java platform from an earlier version to Java 8 or a later version, you want to convert the old java code to one with the new features of the newly added Java version.

Of course, you can check your code line by line to convert it manually. However, you can use the NetBeans built-in feature to perform this, which will save you a lot of time and effort.

1. Click the Refactor in the top menu of the NetBeans IDE, and choose Inspect and Transform/



2. In the Inspect and Transform window, select a project you want to refactor from the drop-down list next to the Inspect label.



3. While the Configuration is checked, select the target JDK you will convert to from the drop-down list next to the Configuration label. Then, click the Inspect button.



4. If the below window pops up, click the Inspect button again to continue.



5. In the Refactoring window, click the upward arrow with the notation "Previous Occurrence" on the left column of the window to view the suggestions of code changes.



6. Use the upward and downward arrows on the left column to view all the changes. If all look OK, click the Do Refactoring button.


-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Monday, May 6, 2019

Install Tomcat 9 as the web server in NetBeans 11.0

Download the Tomcat core zip file from https://tomcat.apache.org/download-90.cgi. The file downloaded is apache-tomcat-9.9.19.

Extract files from the zip file to the C:\Program Files directory.

Open the NetBeans 11.0, click on Tools in the top menu and select Servers.


In the popup window, click the Add Server button.


In the new popup window, select Apache Tomcat or TomEE from the server list. Then, click the Next button.



In the popup window, enter the Tomcat location as the Server location, fill in the username and password fields, and click the Finish button.


It will take you back to the Server screen, which now looks like the one below. Click the Close button to close the window.


To start the Tomcat server, right click the Apache Tomcat or TomEE under Servers in the Services tab, and select Start.



In a few seconds, the server is available to view at http://localhost:8080


Right click on your web service project and select run to start your website.

 -----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Reference:

1. Installing Tomcat 7 and Configuring as Server in NetBeans

Wednesday, December 19, 2018

NetBeans: Cannot locate java installation in specified jdkhome

When I was trying to launch the NetBeans, I got the following message.



It happened after I updated java from jdk1.8.0_25 to jdk1.8.0_191.

I did the following to get rid of this message.

1. Open the C:\Program Files\NetBeans 7.4\etc\netbeans.conf

2. Search the file for "jdkhome" to locate the line
      netbeans_jdkhome="C:\Program Files\Java\jdk1.8.0_25"

3. Change it to  netbeans_jdkhome="C:\Program Files\Java\jdk1.8.0_191"

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live


           

If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Friday, September 14, 2018

NetBeans: Checkout a project with a certain tag from git

Before starting, make a copy of your current project, and store it somewhere.

Method A

1. In NetBeans, right click on the project, select Git, then Checkout, and then Checkout Files.


2. In the popped up Checkout Selected Paths window, check the Update Index with Entries from the Selected Revision: checkbox.


3. Click on the Select button. In the popped up Select Revision window, expand the Tags folder, select the tags you want to checkout, and click the Select button at the bottom.



Method B

1. In NetBeans, right click on the project, select Git, then Repository Browser.


2. In the Git Repository Browser pane, expand the Tags folder under your project, right click on the tag you would like to checkout, and select Checkout Revision.



After you have done with the tag, right click on the project again, select Git, then Checkout, and then Checkout Files. In the popped up window, click the Checkout button to checkout the HEAD of the project. And then replace your project folder with the copy you made at the beginning.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live

               

If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Thursday, April 5, 2018

NetBeans: one or more project resources could not be found

When you open an existing java project from NetBeans, you get the following message.


[Thumbnail for referenceRUSAK.jpg]



To fix this, click the Close button to close the message. Right-click on the project and select Properties.


In the popped-up Project Properties window, select the Libraries under the Categories, and you will see a list of broken references on the Compile tab.



Select these broken references and click the Remove button to remove them.

Click the Add JAR/Folder button to add the jars needed or refer to this article to create and add the libraries you need for your project.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.


Tuesday, April 3, 2018

NetBeans: View, add, remove, replace jar(s) in an existing library

1. Right-click on your project in the Projects pane of NetBeans and select Properties.

2. In the Project Properties window, select Libraries under the Categories.

3. Choose the library you want to work on and click on the Edit button.

4. Select the jars you want to remove and click the Remove button.

5. Click the Add JAR/Folder... button to add a jar to the library.

-----------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

NetBeans: Use / reference classes from external jars

If your code needs to use classes from other jars, get these jars and put them in folders at your discretion.

1. Click  on Tools in the top menu and select Liberaries


2. In the new pop-up Ant Library Manager window, click the New Library button at the bottom-left corner.


3. Enter the library name you want to use and click OK.


4. Click the Add JAR/Folder button to choose the jars you would like to add to the new library. Click the OK button.

5. In NetBeans, right-click on your project and select Properties.

6. In the Project Properties window, select Libraries under the Categories.



7. Click the Add Library button and select the library you want to add. Finally, click the OK button.

Of course, if your project only needs a few external jars, you can directly add them to your libraries by clicking the Add JAR/Folder button in the Project Properties window.

-----------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.







NetBeans: How to find all the @TODO items in your code

While developing the project for the initial main functions, you put reminders of the add-on things needed to put in later using comments like this.

//@TODO the changes to be made later

After you have finished the initial round of coding, you need to find all the TODO things to work on them. In NetBeans, you can find all of them by clicking the Window item in the top menu and select the Action Items.





You can right-click on an item in the Action Items pane and choose the Scope and Filter you want to apply to the list. If you select Show All from the Filter menu, it will display lines of code with compiling errors, quick fixes and style warnings in addition to the TODO things. You can also sort the entries in the Action Items by picking a method from the Sort By menu.

Double click on an item in the Action Items pane will take you to its location in your code.

Reference:





-----------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.




Thursday, March 9, 2017

[Solved] NetBeans: How to get back / recover / restore the Output window, Editor window, Projects window, or the Navigator window?

A. Window closed by accident

If you closed any of the NetBean windows by accident, you can always click on the Window menu in the top menu, and select the window you want to recover or display. If you don't see the window you want to display, check the submenus under the Window menu.


B. Window minimized by clicking the minimize button of the window

Look at the side and bottom edge of the NetBean screen to locate the minimized window, click on it to restore it.

If you feel the windows are really messed up, you can click on the word Window in the top menu and select Reset Windows before you perform the A or B listed above. This will reset the windows to their default layout.

---------------------------------------------------------------------------------------------------

                        


If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

Tuesday, July 14, 2015

Java: Overridable method call in constructor

In NetBeans, the following code will give a warning: Overridable method call in constructor.

public class Reward {
      protected int baseReward = 1000;

      public Reward() {
            int reward = calculateReward(); //this line generates the warning
            System.out.println("The reward is " + reward);
      }

      protected int calculateReward() {return baseReward;}
}

This is because the calculateReward method can be override in subclasses and calling such a method in superclass constructor before the proper initiation of properties in subclasses may result in errors. Here is an example.

public class CreativeReward extends Reward {
      private int rewardAdjust = 100;

     public CreativeReward() {
           super();
     }

      public CreativeReward(int rewardAdjust) {
            this.rewardAdjust = rewardAdjust;
      }

      protected int calculateReward() {
          return baseReward + rewardAdjust;
      }

      public static void main(String[] args) {
            new CreativeReward(); //Prints 1000 instead of 1100
            new CreativeReward(50); //Prints 1000 instead of 1050
      }
}

This is because the constructor in superclass is called first, after which the constructor in subclass is called and the instance variables are initiated. Therefore, an overriden method called in superclass constructor will ignore the values assigned to the used instance variables in subclasses. Thus, in the above example the rewardAdjust used in the superclass constructor is 0 instead of 100 or 50.

-----------------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.


Monday, October 20, 2014

NetBeans: Use an old/previous version/revision of code/file/project, Revert vs Checkout

If for some reason, one of your code users could not accommodate the recent modifications of the code at the moment and would like to go back to an old version of the code, you could either revert your current code to the old version or checkout the old version, and then do a build and send the jar to your code user.

A. Revert

  1. Open the window explorer, find the file or project that you are interested in, make a copy of it and save it some where.
  2. In NetBeans, right-click on the file/project, select "Subversion", then "Revert Modifications"
  3. In the pop-up window, select "Revert Modifications from Single Commit", then click the "Search" button.
  4. In the new pop-up window, click the "List" button, click on the revision that you would like to revert to, then click the "OK" button at the bottom.
  5. Click the "Revert" button.
Revert may generate conflicts in file.

After you have sent the jar to the particular user, you can follow the procedure to revert your code back to the current revision. Or simply update the code to the HEAD.

B. Checkout

  1. In NetBeans, close the project.
  2. In Window Explorer, rename the project to something else.
  3. In NetBeans, click "Team" on the top menu, select "Checkout"
  4. Enter the correct information related to your repository n the pop-up window, and click the "Next" button.
  5. Click the "Browse" button at the line of "Repository Folder(s) to choose the project that you would like to checkout
  6. Click the "Search" button at line Repository Revision.
  7. In the new pop-up window, click the "List" button, click on the revision that you would like to revert to, then click the "OK" button at the bottom.
  8. Click the "Finish" button.

After you have finished with the old code, you can update the code to your current working version and close the project in NetBeans. In window explorer, rename the old project and rename the current revision of the project back to the project name and open the project in NetBeans.

-------------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

Wednesday, September 3, 2014

NetBeans contains files with errors - resolved

If you have a class X in project B extends a class Y in project A, error badges may occur in project B after you modified class Y and rebuilt project A. When you point the cursor at the error badge, it says "Contains files with errors". When you open the java file of class X and point the cursor at the error line, it says "Class X cannot convert to class Y".

To fix this problem


  1. Right-click on project B and select "Porperties".
  2. Click "Libraries" on the left under Categories.
  3. Select the library or the jar of project A in the right pane and click the "Remove" button to remove it.
  4. Click "OK" to close the window.
  5. Restart NetBeans.
  6. Repeat steps 1 and 2.
  7. Click the "Add Library" or "Add JAR/Folder" button to add the library or the jar of project A back to project B.         
-----------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

Friday, July 25, 2014

NetBeans split the editor window /open file in new window /open one file in two tabs

A. To open one file in two tabs


  1.  Double click the file or right-click the file and select Open to open the file in the editor window. 
  2.  Right-click the tab title and select Clone or click Window in the top menu, select "Configure Window", then select "Clone Document".


B. To Open one file in two windows, do one of the followings


  1. Right-click the title of the tab that has the file open, select Split, and then choose how you would like to split the file, vertically or horizontally.
  2. Click Window in the top menu, select "Configure Window", then select "Split Document" and finally choose how your would like to split the file.

      To close one of the windows, repeat one of the above two procedures and at the last step select Clear.

C. To open a file in a new editor window


  1. Drag the title of the tab that has the file open to the bottom of the editor window until you see a rectangle and drop it. To close the window, right-click on the tab title and select "Collapse Document Tab Group".
  2. Right-click the title of the tab that has this document open, select "New Document Tab Group". To close the window, right-click on the tab title and select "Collapse Document Tab Group".
  3. Click Window in the top menu, select "Configure Window", then select "New Document Tab Group". To close the new window, select "Collapse Document Tab Group"            
-------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

Thursday, July 24, 2014

NetBeans low memory/not enough memory to compile

The NetBeans gives a "low memory" or "not enough memory to compile" warning when it needs more memory to compile your project.

A. Delete NetBeans cache to release memory.
      Close NetBeans and delete the cache folder.    

      Location of NetBeans caches:
      Windows: C:\Users\<user>\AppData\Local\NetBeans\Cache\<cache folder should be deleted>
      MAC OS X: /Users//Library/Caches/NetBeans/<cache folder>
      UNIX: /home//.cache/netbeans/<cache folder>

B. Allocate more memory for NetBeans.

1. Go to your NetBeans home directory.
2. Open the netbeans.conf file in the etc directory.
3. Find the netbeans_default_options parameter in the file.
4. Set the -J-Xms and -J-XX to larger values.

C. Allocate more memory for your project, follow the steps below.

1. Perform a clean and build of your project. You can get it done by performing one of the followings.
      a. Right click your project and select "Clean and Build".
      b. Select your project in the Project Pane, then type Shift+F11.
      c. Select your project in the Project Pane, then click the Run button in the top menu of the frame and select "Clean and Build Project".

2. Watch the Output pane carefully to make sure that your project compiles successfully.

3. Right click your project and select "Properties". In the pop up window select "Run" in the left Categories. Then, set the VM Options on the right side of the window. For example, setting the VM Option to -Xms64m -Xmx1024m tells your JVM to allocate minimum 64 megabytes of memory to your project up to maximum of 1024 megabytes of memory. However, the memory set here cannot exceed the RAM your machine has.

-----------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

Friday, June 6, 2014

NetBeans The type of [method call] is erroneous

While you are working with your code, the NetBeans IDE sometimes unexpectedly shows an error sign. When hovering the cursor over the place underlined with a curly red line, the message says that the type of <mehtod> is erroneous.

This type of error sign occurs in the following situations
1. When a final method in the super class is called from a subclass.
         public class SuperPowerful {
                   public final String getTheString() {
                             return "Super class final method is called";
                   }
         }

         public class SubPowerful  extends SuperPowerful {
                   public void printString() {
                             //The error sign shows on this line of code
                             String str = getTheString(); 
                             System.out.printlin(str);
                   }
          }

2. When creating a class instance using a return type of an interface that is not directly implemented by this class, but is implemented by its super class.
          public interface SunRisingInterface {
                    public void sunIsRising();
          }

          public class GeneralSunRise implements SunRisingInterface {
                   public void sunIsRising() {
                             System.out.println("get ready to watch sun rising!!!");
                   }
          }

          public class SummerSunRise extends GeneralSunRise {
                     public static void main(String [] args) {
                               //The error sign shows on this line of code
                               SunRisingInterface sri = new SummerSunRise();
                               sri.sunIsRising();
                     }
          }

However the code compiles and runs just fine. You can either ignore the error sign, but if your feel uncomfortable to work while there is an error sign you may fix the problem as stated below.

To fix this problem

A. Remove and add back the jar containing the super class to the project library/path if the super class and sub class are contained in two different projects. Let's say that the super class is in project A and the sub class is in project B.
  1. Right-click on project B and select "Porperties".
  2. Click "Libraries" on the left under Categories.
  3. Select the library or the jar of project A in the right pane and click the "Remove" button to remove it.
  4. Click "OK" to close the window.
  5. Restart NetBeans.
  6. Repeat steps 1 and 2.
  7. Click the "Add Library" or "Add JAR/Folder" button to add the library or the jar of project A back to project B.
B. Remove the final  keyword from the method in the super class.

C. Change public class SummerSunRise extends GeneralSunRise to public class SummerSunRise extends GeneralSunRise implements SunRisingInterface.
       
---------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

Wednesday, May 21, 2014

How to debug java code to fix runtime exceptions

If your java code throws any exceptions during its execution, follow the steps below to find out the cause and fix them.
  1. Look at the stack trace printed in your log file or in the console. Scroll down to see if there is a line starting with "Caused by". Following that line to look for the first line that is about your code. If you could not find a line starting with "Caused by", look from the beginning of the stack trace to find the first line that indicates a place in your code
  2. Look at the place of your code found above to see if there is anything inappropriate, then fix it. You may need to look at the stack trace the second or third lines that are directly related to your code to understand what is going on. If you could not tell what is wrong, you need to debug this section of code.
  3. Debugging java code in NetBeans
    • Setting breakpoint: A breakpoint is a place in the source code that makes the debugger to hang when the execution reaches it. To set a breakpoint, select a line, click the left grey margin area of the line or right click on the left grey margin area of the line, select Breakpoint, then select Toggle Line Breakpoint, the line is highlighted in red with a square red mark on the left margin.
    • Setting a watch: If you would like to monitor the value of a variable, click the Debug button on the top menu and choose New Watch. Enter the variable name that you want to monitor. Or you can right click on the variable name directly and choose New Watch. Click OK. You can monitor the changes of the variable value in the Watches window during debugging.
    • Starting the debugger: Right click on your executable application and choose Debug File. Alternatively, you can select the executable application in the Projects pane, click the Debug button on the top menu and select Debug File. The debugger will execute the program until it reaches a breakpoint, it then hangs. 
    • Using the following keys or corresponding buttons on the top menu to watch the execution of the program.
      • F8 (Step Over): Executes the current line of code. If the current line is a method call, execute the method without stepping into the code of the method.
      • F7 (Step Into): Executes the current line of code. If the current line is a method call, step into the code of the method and stops at the first line of the method .
      • Ctrl+F7 (Step Out): Finishes the execution of the current method and returns to the caller of the method.
      • F5 (Continue): Continue the execution until it reaches the next breakpoint.
      • F4 (Run to Cursor): Continue the execution to the line where the cursor is located
    • While debugging, click the Window button on the top menu, select Debugging, then select Variables, Watches, and any other you would like to monitor. You can monitor the values of the variables in the Variables and Watches windows. Or you can hover the cursor on the variable during line by line execution. You can also highlight an expression by dragging the cursor through it while the left mouse button is pressed, and the hover the cursor over it to see the value of the expression.
  4. Debugging java code in eclipse
    • Setting breakpoint: Select the line of code that you decide to start debugging, go to the left end of the line, double click the small margin area to the left of the line or right click to select Toggle Breakpoint, and the line is marked as a debugging point
    • Starting the debugger: Right-click on the executable application, select Debug as and then select Java Application. If a Confirm Perspective Switch window pops up asking if you want to open the debug perspective, click Yes. If the debugger has already been started, you can click the bug icon on the top menu to start debugging after you having set the debug breakpoint. The execution of the program will hang at the breakpoint.
    • Using the keys described below or corresponding buttons on the top menu to watch the execution of the code
      • F5 (Step into): Executes the current line and goes to the next line. If the current line is a method call, the debugger will step into the code of  the method
      • F6 (Step over): Executes the current line and goes to the next line regardless if the current line is a method call or not. If the current line is a method call, the program executes the method call without the debugger stepping into the code of the method.
      • F7 (Step out): The program finishes the execution of the current method and returns to the caller of this method
      • F8 (Go to next breakpoint): The program will execute until it reaches the next breakpoint.
    • Using the Variables View to analyse the execution. The Variables View displays the names and values of fields and local variables in the current executing stack. To change the display of the view, click the drop down icon at the top-right corner and select the display
  5. Manually debugging
    • If the editor that you use for coding does not have the debugging function. You may select points in your code where you would like to see how the execution progresses, and print to the console a message to indicate that the previous section of code executed successfully and it is entering the next section of code, and if possible attach the values of any pertinent variables using System.out.println("<message>"). If at a place the message stops printing and the program terminates, you know that the problem is located between that place and the place the last message is printed
    • You may also use the Java Debugger (jdb) to debug your code.
         
--------------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.
--------------------------------------------------------------------------------------------------------------------------------

References

1. Java debugging tutorial - 10 tips on debugging in java with example
2. Java Debugging with Eclipse - Tutorial
3. NetBeans Debugger- Short Tutorial

Friday, May 16, 2014

NetBeans - Throwable.printStackTrace() should be removed

If you use NetBeans for your Java development, whenever you use printStackTrace() in a catch block, you get a warning sign that the Throwable.printStackTrace() should be removed.

To get rid of this warning sign, do one of the followings

         1. Log the exception. For example to log to a file.
                  Logger logger = Logger. getAnonymousLogger();
                  logger.addHandler(new FileHandler("<directory>/<file name>");
                  logger.log(Level.SEVERE, <exception>.getMessage(), <exception>);
     
         2. Print the stack trace to a file
                  PrintStream ps = new PrintStream(
                                            new FileOutputStream("<directory>/<file name>", true));
                  <exception>.printStackTrace(ps);

         3. If your really want to print to the console, use <exception>.printStackTrace(System.out) instead of <exception>.printStackTrace()
           
--------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.