package com.example.dennis.sunshine.app;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* A placeholder fragment containing a simple view.
*/
public class MainActivityFragment extends Fragment {
public MainActivityFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_main, container, false);
String[] forecastArray = {
"Today - Sunny - 88 / 63",
"Tomorrow - Foggy - 70 / 46",
"Weds - Cloudy - 72 / 63",
"Thurs - Rainy - 64 / 51",
"Fri - Foggy - 70 / 46",
"Sat - Sunny - 76 / 68"
};
List<String> weekForecast = new ArrayList<String>(Arrays.asList(forecastArray));
}
}
我正在尝试按照 IDE 上创建ArrayList
的教程,但我偶然发现了一个错误显示在String [] forecastArray = .....};说'无法到达的声明'。
答案 0 :(得分:5)
您的方法将在此行结束(请注意Array [ ]
语句):
return
该行之后的任何内容都无法访问,换句话说,永远无法执行。
答案 1 :(得分:1)
返回return语句后,返回语句后没有执行其他代码。
尝试在返回之前移动逻辑。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String[] forecastArray = {
"Today - Sunny - 88 / 63",
"Tomorrow - Foggy - 70 / 46",
"Weds - Cloudy - 72 / 63",
"Thurs - Rainy - 64 / 51",
"Fri - Foggy - 70 / 46",
"Sat - Sunny - 76 / 68"
};
List<String> weekForecast = new ArrayList<String>(Arrays.asList(forecastArray));
return inflater.inflate(R.layout.fragment_main, container, false);
}