当我在此页面中声明方法时,为啥此代码会出现“找不到符号”错误?

Posted

技术标签:

【中文标题】当我在此页面中声明方法时,为啥此代码会出现“找不到符号”错误?【英文标题】:Why does this code get me a "Cannot find symbol" error when I declare the method in this page?当我在此页面中声明方法时,为什么此代码会出现“找不到符号”错误? 【发布时间】:2015-09-27 03:02:07 【问题描述】:

您好,我想知道为什么当我在页面底部声明它时找不到符号 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

【问题讨论】:

【参考方案1】:

它没有为 RecyclerView.ViewHolder 定义。您需要先将 holder 转换为 HourViewHolder。

【讨论】:

【参考方案2】:

标准是:

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

那么你的方法签名变成:

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

无需强制转换。

【讨论】:

以上是关于当我在此页面中声明方法时,为啥此代码会出现“找不到符号”错误?的主要内容,如果未能解决你的问题,请参考以下文章

为啥当我将查询字符串添加到我的 url 时,它会被 xampp 拒绝(“在此服务器上找不到请求的 URL”)

为啥在此代码中调用虚拟方法时会出现分段错误?

为啥我在此代码的循环中出现错误?

Django:为啥当我在 django 中通过 popen 使用 Ghostscript 时会出现“找不到文件”错误

在 amCharts Angular 的 createChild 中找不到 html 容器

为啥 FireFox 会冻结我在此登录表单中的输入?