Results 1 to 8 of 8
  1. #1
    exopforce is offline Member
    Join Date
    Apr 2013
    Posts
    6
    Rep Power
    0

    Default Help with weatherapp

    this code isnt compiling any ideas? thanks

    Java Code:
    import java.io.*;
    import java.util.*;
    import java.awt.*;
    
    
    
    public class WeatherMapApp {
    static List<String> testlist = new ArrayList<String> ();
    static String time = null;
    public static void main(String [] args) {
    	String base = "http://iwin.nws.noaa.gov/iwin/nj/hourly.html";
    	URL u = null;
    	URLConnection conn = null;
    	Scanner in = null;
    	u = new URL (base);
    	conn = u.openConnection();
    	in = new Scanner (conn.getInputStream());
    	parsePage(in);
    	in.close();
    	System.out.println("Student Name: ");
    	System.out.println(time); //testing reading time
    	//print out testing code here
    	
    	for (String s:testlist)
    		System.out.println(s);
    	fileOutput();
    	
    }//end main
    static void getTime (Scanner in)
    { //get weather report of cities
    	while (time == null && in.hasNext())
    	
    	{
    		String line = in.nextLine();
    		if (line.startsWith("NATIONAL WEATHER SERVICE"))
    			time = in.nextLine();
    	}
    }
    	static void parsePage(Scanner in) {}
    }
    Last edited by pbrockway2; 05-02-2013 at 03:50 AM. Reason: code tags added

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Help with weatherapp

    this code isnt compiling
    What are the compiler messages? And to which lines of the code do they refer? It's best to copy and post the compiler messages exactly as you see them.

    (I've added "code" tags to your post. The idea is that you put [code] at the start of a section of code and [/code] at the end so that the forum software will render the code properly in a web page.)

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,759
    Rep Power
    7

    Default Re: Help with weatherapp

    As mentioned above to maximise your chances of getting help you should copy and paste error messages.

    On line 26 you are calling a method that does not exist. Also in the loop before this line how many times do you expect it to iterate considering that you never insert anything into the List?

  4. #4
    exopforce is offline Member
    Join Date
    Apr 2013
    Posts
    6
    Rep Power
    0

    Default Re: Help with weatherapp

    Line 8
    It says
    WeatherMapApp.java:10: error: reference to List is ambiguous, both class java.awt.List in java.awt and interface java.util.List in java.util match
    static List <String> testlist = new ArrayList<String> ();

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,759
    Rep Power
    7

    Default Re: Help with weatherapp

    Ahh!

    That's the problem with importing blah.*, if two classes exist with the same name in different packages you will get this error. Personally I only import classes I need.

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Help with weatherapp

    Further to Junky's response - and just to spell things out - which sort of List is the proper super type of ArrayList? Because that's the one you should make sure is imported. The API docs help. (keep them open as you code)

    ---

    Having got that sorted out it would make a good exercise to remove all the import blah.* lines and add each class that should be imported. The compiler is your friend and will complain when it sees a class that it doesn't know about. And the API docs will help run down the correct class (or interface) including its package. This is a PITA to begin with, but it helps to develop a familiarity with the commonly used parts of the Java API.

    Having a whole list of imports like "import some.specific.package.SomeType;" is the preferred way to go because it makes your code more self documenting: you can see at a glance what parts of the Java API your class is using.

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,759
    Rep Power
    7

    Default Re: Help with weatherapp

    Quote Originally Posted by pbrockway2 View Post
    you can see at a glance what parts of the Java API your class is using.
    Even more important if you are using third party libs.

  8. #8
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Help with weatherapp

    Agreed. I should have said "you can see at a glance which parts of which API you are using..."

Posting Permissions

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