android - 当我在此页面中声明方法时,为什么这段代码会给我一个 "Cannot find symbol"错误?

标签 android symbols

您好,我想知道为什么我在页面底部声明了符号 bindHour 时收到此错误消息,提示它找不到符号 bindHour?任何帮助将不胜感激,非常感谢您!

package com.dredaydesigns.stormy.adapters;


import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.dredaydesigns.stormy.R;
import com.dredaydesigns.stormy.weather.Hour;

/**
 * Created by Andreas on 7/2/2015.
 */
public class HourAdapter extends RecyclerView.Adapter {
    private Hour [] mHours;
    public HourAdapter(Hour [] hours) {
        mHours = hours;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.hourly_list_item, parent, false);
        HourViewHolder viewHolder = new HourViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        holder.bindHour(mHours[position]);
    }

    @Override
    public int getItemCount() {
        return mHours.length;
    }


    public class HourViewHolder extends RecyclerView.ViewHolder {

        public TextView mTimeLabel;
        public TextView mSummaryLabel;
        public TextView mTemperatureLabel;
        public ImageView mIconImageView;

        public HourViewHolder(View itemView) {
            super(itemView);

            mTimeLabel = (TextView) itemView.findViewById(R.id.timeLabel);
            mSummaryLabel = (TextView) itemView.findViewById(R.id.summaryLabel);
            mTemperatureLabel = (TextView) itemView.findViewById(R.id.temperatureLabel);
            mIconImageView = (ImageView) itemView.findViewById(R.id.iconImageView);
        }
    public void bindHour(Hour hour) {

    mTimeLabel.setText(hour.getHour());
    mSummaryLabel.setText(hour.getSummary());
    mTemperatureLabel.setText(hour.getTemperature() + "");
    mIconImageView.setImageResource(hour.getIconId());


}
}
}

这是我尝试运行时得到的 logcat。 OnBindViewHolder方法中的bindHour好像有问题?

Information:Gradle tasks [clean, :app:compileDebugSources, :app:compileDebugAndroidTestSources]
:app:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72211Library
:app:prepareComAndroidSupportRecyclerviewV72211Library
:app:prepareComAndroidSupportSupportV42211Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources
:app:mergeDebugResources
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-hdpi\refresh.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-mdpi\wind.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-hdpi\partly_cloudy.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xhdpi\fog.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-mdpi\clear_day.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xxhdpi\snow.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xhdpi\partly_cloudy.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xhdpi\degree.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xhdpi\rain.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-hdpi\sleet.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-hdpi\snow.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-mdpi\cloudy_night.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xxhdpi\clear_day.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xhdpi\clear_day.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xxhdpi\sleet.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xhdpi\clear_night.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xhdpi\snow.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-mdpi\sunny.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-hdpi\cloudy.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-mdpi\fog.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-mdpi\bg_temperature.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xxhdpi\partly_cloudy.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xhdpi\wind.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-mdpi\clear_night.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-mdpi\refresh.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xxhdpi\cloudy.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-mdpi\degree.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-mdpi\snow.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xhdpi\ic_launcher.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xxhdpi\fog.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xhdpi\cloudy_night.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xhdpi\refresh.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xxhdpi\rain.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xhdpi\sunny.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xxhdpi\degree.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xxhdpi\clear_night.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-hdpi\ic_launcher.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-hdpi\wind.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-hdpi\clear_night.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-hdpi\bg_temperature.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-hdpi\clear_day.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xxhdpi\ic_launcher.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xxhdpi\cloudy_night.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xhdpi\bg_temperature.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-mdpi\sleet.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xxhdpi\wind.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-hdpi\fog.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-hdpi\degree.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xhdpi\cloudy.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-mdpi\rain.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-hdpi\rain.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-hdpi\sunny.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xhdpi\sleet.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-hdpi\cloudy_night.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xxhdpi\sunny.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-mdpi\cloudy.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xxhdpi\bg_temperature.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-mdpi\ic_launcher.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-mdpi\partly_cloudy.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\res\drawable-xxhdpi\refresh.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:compileDebugJava
C:\Users\Andreas\Documents\dreday creative\treehouse\Stormy\app\src\main\java\com\dredaydesigns\stormy\adapters\HourAdapter.java
Error:(32, 15) error: cannot find symbol method bindHour(Hour)
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
Information:Total time: 1 mins 56.274 secs
Information:2 errors
Information:0 warnings
Information:See complete output in console

最佳答案

标准是:

public class HourAdapter extends RecyclerView.Adapter<HourAdapter.HourViewHolder>

然后你的方法签名变成:

public HourViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
public void onBindViewHolder(HourViewHolder holder, int position)

无需类型转换。

关于android - 当我在此页面中声明方法时,为什么这段代码会给我一个 "Cannot find symbol"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31305592/

相关文章:

android - 为什么setEnabled(false)不会触发主题Theme.AppCompat.Light的ColorStateList?

perl - 为什么符号的封装限定会导致使用更少的内存,即使符号是本地导入的?

lisp - 普通口齿不清 : Hunchentoot: Strange behavior with ASSOC

html - HTML 中的 OK 或 ACCEPTED 符号?

Android:如何为应用程序设置文化值

android - Android View 的 CSS 类选择器的等价物?

android - NativeScript 安装错误 - npm Fiber

c++ - 使用 C++ 标准库避免共享库中的符号冲突

ruby - 为什么 double splat 仅适用于符号键?

android - 在 android 的谷歌地图中查找两个位置之间的距离的方法哪种更准确? distanceTo 还是距离?