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



嗨,我想知道为什么我得到这个错误说它找不到符号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,当我试图运行它。它似乎有一个问题与bindHour在OnBindViewHolder方法?

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:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-hdpirefresh.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-mdpiwind.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-hdpipartly_cloudy.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xhdpifog.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-mdpiclear_day.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xxhdpisnow.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xhdpipartly_cloudy.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xhdpidegree.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xhdpirain.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-hdpisleet.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-hdpisnow.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-mdpicloudy_night.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xxhdpiclear_day.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xhdpiclear_day.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xxhdpisleet.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xhdpiclear_night.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xhdpisnow.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-mdpisunny.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-hdpicloudy.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-mdpifog.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-mdpibg_temperature.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xxhdpipartly_cloudy.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xhdpiwind.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-mdpiclear_night.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-mdpirefresh.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xxhdpicloudy.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-mdpidegree.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-mdpisnow.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xhdpiic_launcher.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xxhdpifog.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xhdpicloudy_night.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xhdpirefresh.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xxhdpirain.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xhdpisunny.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xxhdpidegree.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xxhdpiclear_night.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-hdpiic_launcher.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-hdpiwind.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-hdpiclear_night.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-hdpibg_temperature.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-hdpiclear_day.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xxhdpiic_launcher.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xxhdpicloudy_night.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xhdpibg_temperature.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-mdpisleet.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xxhdpiwind.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-hdpifog.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-hdpidegree.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xhdpicloudy.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-mdpirain.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-hdpirain.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-hdpisunny.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xhdpisleet.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-hdpicloudy_night.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xxhdpisunny.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-mdpicloudy.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xxhdpibg_temperature.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-mdpiic_launcher.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-mdpipartly_cloudy.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainresdrawable-xxhdpirefresh.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:compileDebugJava
C:UsersAndreasDocumentsdreday creativetreehouseStormyappsrcmainjavacomdredaydesignsstormyadaptersHourAdapter.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)

它不是为RecyclerView.ViewHolder定义的。你需要先将holder转换为一个HourViewHolder

相关内容