【问题标题】:Calling a non-static method from within static Map Class in Hadoop从 Hadoop 中的静态 Map 类中调用非静态方法
【发布时间】:2012-07-20 03:59:44
【问题描述】:

Using DistributedCache in Hadoop by Yavcular

在上面的链接中,以一种易于理解的方式描述了如何在 Hadoop 中使用 DistributedCache。但问题是,当我编译代码时,我得到以下错误:

non-static method loadIdUrlMapping(org.apache.hadoop.mapreduce.Mapper.Context) cannot be referenced from a static context
        loadIdUrlMapping(context);

解决方法是什么?我无法将 Mapper 类更改为非静态,当我将 loadIdUrlMapping 方法签名更改为静态时,我无法访问 idmap HashSet

【问题讨论】:

  • 您能否发布您的代码版本 - 链接文章中没有cacheItemset 方法
  • 抱歉,我刚刚将 loadIdUrlMapping(Context context) 更改为 cacheItemset(Context context)。同样的事情。

标签: hadoop distributed-caching static-classes non-static


【解决方案1】:

您需要发布您的代码版本以确定,但我想您有一个名为 cacheItemset 的方法,它被定义为静态范围:

public static void cacheItemset(Context) {
    loadIdUrlMapping(context);
}

loadUrlMapping 未定义为静态方法,因此会出现编译错误。

如果您的 ReplacementMapper 类的版本在它自己的类文件中,那么您不需要在类声明中使用 static 关键字(仅当 ReplacementMapper 类是另一个类的内部类时才需要)。

【讨论】:

  • 抱歉,我刚刚将 loadIdUrlMapping(Context context) 更改为 cacheItemset(Context context)。同样的事情。
  • 我自己解决了这个问题。问题是,我没有将方法放在静态地图类中,而是错误地放置在主公共类中。换了方法,问题解决了。感谢您的帮助
猜你喜欢
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-24
  • 1970-01-01
相关资源
最近更新 更多