Results 1 to 5 of 5
  1. #1
    switch's Avatar
    switch is offline Member
    Join Date
    Jan 2012
    Location
    U.S.A.
    Posts
    19
    Rep Power
    0

    Default Netbeans API Tutorials...

    After agreeing with Fubarable that using a database was better than what I questioned, I have started to dig deeper into the depths of the Netbeans IDE. I have upgraded from Netbeans 7.0.1 to Netbeans 7.1. I was directed to a tutorial page that teaches us about Netbeans APIs before learning about CRUD. I want to build a database on the Netbeans platform. I did the first tutorial, but I am having a problem with the second. Part 2: Lookup API. In the tutorial the instructor added the import (import org.demo.service.ServiceInterface;) to the second application. When I try to add the import Netbeans informs me that org.demo.service does not exist. The editor will only allow me to add the import (import org.demo.ServiceInterface;). Then when I do the editor gives a warning with two options. When I select either option the editor deletes the import. So, in a nutshell the program compiles and runs, but it does not return anything. Heres the link to the tutorial page. The tutorial is as stated before: Part 2: Lookup API. NetBeans Top 10 NetBeans APIs
    If someone would, could you watch the demo and see if you can make it work. I can only think that the installation of Netbeans or Java 1.6 on my computer is missing something. I don't really know. I thought that one of you experts on this site could help me out.

    Thanks in Advance,

    switch
    Last edited by switch; 02-01-2012 at 12:07 AM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default Re: Netbeans API Tutorials...

    Show us the code and tell us what the error Netbeans is giving you.
    I doubt many people will want to watch the vid.

  3. #3
    switch's Avatar
    switch is offline Member
    Join Date
    Jan 2012
    Location
    U.S.A.
    Posts
    19
    Rep Power
    0

    Default Re: Netbeans API Tutorials...

    Netbeans API Tutorials...-screen-shot-2012-02-01-12.26.21-pm.png

    First Application:

    Java Code:
    package org.demo;
    
    /**
     *
     * @author switch
     */
    public interface ServiceInterface {
        public String getName();
    }
    Second Application:

    Java Code:
    package org.demo;
    
    //import org.demo.service.ServiceInterface; (the instructor used this import here)
    //(netbeans won't allow me to use this import or import org.demo.ServiceInterface; without an error or warning)
    /**
     *
     * @author switch
     */
    public class ServiceProvider1 implements ServiceInterface {
        @Override
        public String getName() {
            return "switch";
        }
    }
    Third Application:

    Java Code:
    package thirdappserviceproviderdisplayer;
    
    import java.util.ServiceLoader;
    import org.demo.ServiceInterface;
     
    //(Netbeans accepts this but when I use .service, net beans says that org.demo.service doe's not exists.
    //(Why was the instructor able to do this and I can't?)
    
    //import org.demo.service.ServiceInterface; (The instructor used this import here)
    
    /**
     *
     * @author switch
     */
    public class ThirdAppServiceProviderDisplayer {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            for (ServiceInterface sInterface : ServiceLoader.load(ServiceInterface.class)) {
                System.out.println("Hello " + sInterface);
            }
        }
    }
    Empty file (org.demo.ServiceInterface):

    Java Code:
    org.demo.ServiceProvider1
    The return value should be "Hello switch." I don't get any return value. I can't use the import that the instructor used.

    Thanks Tolls...
    Last edited by switch; 02-01-2012 at 09:00 PM.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default Re: Netbeans API Tutorials...

    Either you've put the ServiceInterface in the wrong package in the first app, or the tutorial is wrong (which happens quite a lot, even with well-reviewed stuff).
    Essentially if FirstApp is correct, based on the earlier steps, then the later bits of the tutorial are mistaken with respect to the location of that interface.
    So I wouldn't worry about the import statement.

    As for why it isn't prinitn switch, you haven't called the getName method.
    You are just relying on the base toString() method for printing out ServiceProvider1, that is the toString() that is in Object.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default Re: Netbeans API Tutorials...

    Oh, and thanks for the question anyway as I don't think I've ever actually looked at the ServiceLoader.

Similar Threads

  1. What tutorials to use?
    By Eleeist in forum New To Java
    Replies: 6
    Last Post: 08-02-2011, 04:21 PM
  2. Anyone Looking tutorials or help with java?
    By TheITRanger in forum Java Software
    Replies: 0
    Last Post: 02-24-2011, 09:25 PM
  3. looking for tutorials
    By bap2 in forum New To Java
    Replies: 0
    Last Post: 12-02-2010, 09:40 PM
  4. MDB tutorials
    By asliyanage in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 03-06-2010, 02:23 PM
  5. My tutorials
    By gibsonrocker800 in forum Forum Lobby
    Replies: 2
    Last Post: 01-06-2008, 08:48 AM

Posting Permissions

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