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

Thread: Help!, newbie, interested in Java, Very simple code, completely stuck!

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Help!, newbie, interested in Java, Very simple code, completely stuck!

    //This code reports a non static method and I have not got a clue why, can anyone help?
     
    package google;
     
    import com.google.gdata.client.*;
    import com.google.gdata.client.sites.*;
    import com.google.gdata.data.*;
    import com.google.gdata.data.acl.*;
    import com.google.gdata.data.media.*;
    import com.google.gdata.data.sites.*;
    import com.google.gdata.data.spreadsheet.*;  // If working with listpages / listitems
    import com.google.gdata.util.*;
     
    import java.net.*;
    import java.io.*;
     
    public class Google {
        public static SitesService client = new SitesService("NCC-Google-App-v1");
     
     
    public String getSiteFeedUrl() {
      String domain = "nsix.org.uk";
      return "https://sites.google.com/feeds/site/" + domain + "/";
    }
     
    public SiteEntry createSite(String title, String summary, String theme, String tag)
        throws MalformedURLException, IOException, ServiceException {
      SiteEntry entry = new SiteEntry();
      entry.setTitle(new PlainTextConstruct(title));
      entry.setSummary(new PlainTextConstruct(summary));
     
      Theme tt = new Theme();
      tt.setValue(theme);
      entry.setTheme(tt);
     
      entry.getCategories().add(new Category(TagCategory.Scheme.TAG, tag, null));
     
      return client.insert(new URL(getSiteFeedUrl()), entry);
    }
     
    public static void main(String[] args) {
     
     
    // Non static method on the following line
     
       SiteEntry newSiteEntry = createSite("My Site Title", "summary for site", "slate", "tag");
     
    }   
     
    }


  2. #2
    Member OutputStream's Avatar
    Join Date
    Apr 2011
    Posts
    32
    My Mood
    Fine
    Thanks
    1
    Thanked 4 Times in 3 Posts

    Default Re: Help!, newbie, interested in Java, Very simple code, completely stuck!

    createSite is not a static method, so you can't call it without having an instance of that class.

    Also, that doesn't look like "very simple code" to me. "Hello world" is very simple code. If you're new to Java I suggest you read some basic tutorials first.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help!, newbie, interested in Java, Very simple code, completely stuck!

    When you get errors, please copy and paste here the full text of the error message.

  4. #4
    Junior Member
    Join Date
    Jun 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help!, newbie, interested in Java, Very simple code, completely stuck!

    Quote Originally Posted by Norm View Post
    When you get errors, please copy and paste here the full text of the error message.
    Here you go, compiler errors

    Compiling 1 source file to C:\Users\riskf\Documents\NetBeansProjects\Google\b uild\classes
    C:\Users\riskf\Documents\NetBeansProjects\Google\s rc\google\Google.java:41: non-static method createSite(java.lang.String,java.lang.String,java. lang.String,java.lang.String) cannot be referenced from a static context
    SiteEntry newSiteEntry = createSite("My Site Title", "summary for site", "slate", "tag");
    1 error
    C:\Users\riskf\Documents\NetBeansProjects\Google\n bproject\build-impl.xml:603: The following error occurred while executing this line:
    C:\Users\riskf\Documents\NetBeansProjects\Google\n bproject\build-impl.xml:245: Compile failed; see the compiler error output for details.
    BUILD FAILED (total time: 0 seconds)

    error.jpg

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help!, newbie, interested in Java, Very simple code, completely stuck!

    The error message says that at line 41 in your program you call a method: createSite.
    The code at Line 41 is in a static method. The method called is not a static method and can only be used when an object exists.
    Either make the method being called static, or create an instance of the object and use that instance to call the method.
    Also See OutputStream's response.

Similar Threads

  1. completely stuck on a simple code
    By disp in forum Loops & Control Statements
    Replies: 6
    Last Post: June 30th, 2011, 12:02 PM
  2. Newbie Question on a Code - I don't know if this is Java
    By fresca in forum Java Theory & Questions
    Replies: 4
    Last Post: April 7th, 2011, 08:39 PM
  3. School java project, completely stuck
    By John1818 in forum Java Theory & Questions
    Replies: 0
    Last Post: November 18th, 2010, 04:10 AM
  4. java newbie..simple mail server implementation
    By saurabh4dudes in forum Java Networking
    Replies: 0
    Last Post: March 12th, 2010, 08:53 AM
  5. [SOLVED] Java Newbie Code Problem
    By lee in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 16th, 2010, 03:05 PM

Tags for this Thread