2017-11-15 5 views
-2

私は学部生です。私は私の授業のために書いているコードのトラブルシューティングの助けを求めています。Javaの教訓の質問

import weather.WeatherData; 
import Weather.data.classes.WeatherReading; 
import Weather.data.classes.WeatherStation; 

/** 
* QUESTION 01 
* 
* If you decide to answer question 01 then the main method below should be used as the entry point for your application 
* You may use as many other classes as you feel necessary as long as all code is supplied 
* 
* Remember to add -Xmx1024m to the VM arguments using menu run --> run configurations in eclipse 
*/ 
public class Answer01 { 
    public static void main(String[] args) { 
     System.out.println("Question 01"); 
     /* 
     * Add your code below 
     */ 
     WeatherStation x = new WeatherStation("site", "a", 1.1, 1.0); 
     WeatherReading y = new WeatherReading(1,2,3,4,5,6); 
     String line[] = WeatherData.getData(); 
     ArrayList<WeatherStation>weatherSize = new ArrayList<>(); 
     for(int i = 1; i < line.length; i++){ 
     String [] split = line[i].split(","); 
     WeatherStation z = new WeatherStation(line[0], line[1], Double.parseDouble(line[2]), Double.parseDouble(line[3])); 
     weatherSize.add(z); 
     } 

     System.out.println(weatherSize.size() + " test"); 

    } 
} 

私がここに持ってる問題はweatherSize.size()はなく136で正解の0をプリントアウトしていることです。コードは、JARファイルからデータを描画

weather.WeatherDataと呼ばれ、私はゲッターとセッターとtoString()メソッドを持つ2つのクラスを作成し、WeatherStationWeatherReadingと呼ばれます。

jarファイルはWeatherData.jarというライブラリ項目で、ukの異なる場所に記録された気象データを記録します。

String [] weatherData = WeatherData.getData();

文字列の配列を返します。インデックス0の最初の要素にはヘッダー情報が含まれています。

要素0:サイトID、サイト名、緯度、経度、年、月、日、時、風速、温度 要素1: 3002、Baltasoundの(3002)、60.7490、-0.8540,2015,01,01,0私はAnswer01のための私のコードを実行すると、21,8.70

は、それは単に言う:0テスト

package Weather.data.classes; 

    public class WeatherStation { 
    public String siteId; 
    public String siteName; 
    public double latitude; 
    public double longitude; 

    public WeatherStation(String siteId, String siteName, double latitude, double longitute){ 
     super(); 
     this.siteId = siteId; 
     this.siteName = siteName; 
     this.latitude = latitude; 
     this.longitude = longitude; 
     } 
    }   

そしてWeatherReading

package Weather.data.classes; 

public class WeatherReading { 
    public int year; 
    public int month; 
    public int date; 
    public int hour; 
    public int windSpeed; 
    public int temperature; 

    public WeatherReading(int year, int month, int date, int hour, int windSpeed, int temperature){ 
     this.year = year; 
     this.month = month; 
     this.date = date; 
     this.hour = hour; 
     this.windSpeed = windSpeed; 
     this.temperature = temperature; 
    }  
} 
+0

サンプルをa * little *ビットで区切り、試してみるためのサンプルデータを提供できますか? – Makoto

+1

なぜこれをやっているのですか? 'String [] split = line [i] .split("、 ")'?あなたはどこで '分割 'を使っていますか? –

+0

@JacobBarnesええ、配列の最初の行は、サイトID、サイト名、緯度、経度などのヘッダー情報を持っています – Ash

答えて

0

マイ提案は、ファイル

String line[] = WeatherData.getData(); 
System.out.println("Number of lines : " + line.length); 

からファイルが正しく読み込まれているかどうかを知るでしょう。この道を読まれるラインアレイの長さをチェックすることです。 あなたも

WeatherStation z = new WeatherStation(split[0], split[1], Double.parseDouble(split[2]), Double.parseDouble(split[3])); 
0
String line[] = WeatherData.getData(); 

はあなたにWeatherData.getData();何かを返すよろしいです

WeatherStation z = new WeatherStation(line[0], line[1], Double.parseDouble(line[2]), Double.parseDouble(line[3])); 

が、私はそれがあるべきだと思う。この行を確認することはできますか?戻り値の文字列には","が存在します。問題が解決しない場合は、正しいことができるように、あなたがインポートするjarファイルについて教えてください。 あなたはあなたが何をしているのかがはっきりしないと思います。