我有一个属性文件,其中包含一个属性,指定包含温度数据集的NOAA网站的URL.该属性包含一个[DATE_REPLACE]令牌,因为当NOAA生成新预测时,URL会每天更改.
在我的属性文件中,我指定:
WEATHER_DATA_URL="http://weather.noaa.gov/pub/SL.us008001/DF.anf/DC.mos/DS.mex/RD.[DATE_REPLACE]/cy.00.txt"
Run Code Online (Sandbox Code Playgroud)
我已经声明了一个带有PropertyHelper类(java.util.Properties的包装器)的方法,使用WEATHER_DATA_URL名称" yyyyMMdd "作为日期格式生成当天的URL字符串,即今天的日期.
public String getPropertyWithDateReplaceToken(String name, String dateFormat, Date dateToFormat)
{
String value = this.properties.getProperty(name);
if (StringHelper.isNullOrWhitespace(value) || !value.contains("[DATE_REPLACE]"))
{
throw new UnsupportedOperationException("The property value should specify the [DATE_REPLACE] token");
}
StringBuilder sb = new StringBuilder(value);
int index = sb.indexOf("[DATE_REPLACE]");
while (index != -1)
{
String replacement = StringHelper.getTodayAsDateString(dateFormat, dateToFormat);
sb.replace(index, index + "[DATE_REPLACE]".length(), replacement);
index += replacement.length();
index = sb.indexOf(value, index);
}
return sb.toString();
}
Run Code Online (Sandbox Code Playgroud)
然后,我使用以下方法调用另一个帮助器类来从网页中读取文本:
public static List<String> readLinesFromWebPage(String urlText) …Run Code Online (Sandbox Code Playgroud) 在 android 中使用 Android-Volley 时出现以下错误。同样的问题在这里也仍未解决......
\n\n08-27 14:46:18.779 26990-26990/com.rev.volleydemo D/VOLLEY\xef\xb9\x95 http://api.androidhive.info/volley/person_object.json\n08-27 14:46:18.879 26990-27004/com.rev.volleydemo E/Volley\xef\xb9\x95 [619] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Bad URL null\n java.lang.RuntimeException: Bad URL null\n at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:151)\n at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114)\n Caused by: java.net.MalformedURLException\n at java.net.URL.<init>(URL.java:154)\n at java.net.URL.<init>(URL.java:127)\n at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:102)\n at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:97)\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114)\nRun Code Online (Sandbox Code Playgroud)\n\npublic class AppController extends Application {\n\n public static final String TAG = AppController.class\n .getSimpleName();\n\n private RequestQueue mRequestQueue;\n private ImageLoader mImageLoader;\n\n private static AppController mInstance;\n\n @Override\n public void onCreate() {\n super.onCreate();\n mInstance = this;\n }\n\n …Run Code Online (Sandbox Code Playgroud)