我不明白为什么这段代码不起作用for int错误。 我尝试使用以下代码:
package com.example.android.touregiude;
import android.content.res.TypedArray;
import android.location.Location;
import com.example.android.cairotourguide.R;
public class hotelsFragment extends CategoryAbstractFragment {
/**
* Constructor
*/
public hotelsFragment() {
// Required empty public constructor
}
/**
* Overridden methods
*/
@Override
void populateLocationsList() {
String[] LocationsNames = getResources().getStringArray(R.array.Hotels_names);
String[] LocationsAddresses = getResources().getStringArray(R.array.Hotels_addresses);
String[] LocationsPhoneNumbers = getResources().getStringArray(R.array.Hotels_phone_numbers);
TypedArray LocationsImagesResIds = getResources().obtainTypedArray(R.array.Hotels_images);
for (int i = 0; i < LocationsNames.length; ++i) {
locationsList.add(new Location (LocationsNames[i],
LocationsAddresses[i],
getString(R.string.Location_open_24_hours),
LocationsPhoneNumbers[i],
getString(R.string.Location_wiki_url_not_provided_text),
LocationsImagesResIds.getResourceId(i,0)));
}
LocationsImagesResIds.recycle();
}
}
遇到的错误:
错误:找不到适合的构造函数 Location(String,String,String,String,String,int)构造函数 Location.Location(String)不适用(实际和正式 参数列表的长度不同)构造函数 Location.Location(Location)不适用(实际和正式 参数列表的长度不同)
答案 0 :(得分:0)
似乎您不小心导入了Location from the Android API,它仅接受一个String
或Location
作为构造函数参数,而不是您自己的Location
。
在这种情况下,只需修改行import android.location.Location;
即可导入您的自定义类。