【问题标题】:I don't understand why this code don't work the for int error [duplicate]我不明白为什么这段代码不起作用 for int 错误 [重复]
【发布时间】:2020-02-23 07:46:00
【问题描述】:

我不明白为什么这段代码不能工作 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();
    }


}

遇到的错误:

error: no suitable constructor found for
Location(String,String,String,String,String,int) constructor
Location.Location(String) is not applicable (actual and formal
argument lists differ in length) constructor
Location.Location(Location) is not applicable (actual and formal argument lists differ in length)

【问题讨论】:

    标签: java error-handling


    【解决方案1】:

    您似乎不小心导入了Location from the Android API,它只接受一个String 或Location 作为构造函数参数,而不是您自己的Location。 在这种情况下,只需修改 import android.location.Location; 行来导入您的自定义类。

    【讨论】:

      猜你喜欢
      • 2012-05-25
      • 2010-12-14
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2012-05-23
      • 2014-06-12
      • 1970-01-01
      • 2014-04-19
      相关资源
      最近更新 更多