Exception in thread "main" java.lang.RuntimeException: java.lang.NoSuchFieldException: versionID

z
log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.RuntimeException: java.lang.NoSuchFieldException: versionID
    at org.apache.hadoop.ipc.RPC.getProtocolVersion(RPC.java:174)
    at org.apache.hadoop.ipc.WritableRpcEngine$Invocation.<init>(WritableRpcEngine.java:114)
    at org.apache.hadoop.ipc.WritableRpcEngine$Invoker.invoke(WritableRpcEngine.java:242)
    at com.sun.proxy.$Proxy4.login(Unknown Source)
    at cn.hadoop.rpc.LoginController.main(LoginController.java:13)
Caused by: java.lang.NoSuchFieldException: versionID
    at java.lang.Class.getField(Unknown Source)
    at org.apache.hadoop.ipc.RPC.getProtocolVersion(RPC.java:170)

    ... 4 more



1:这是提示需要指定版本号versionIDLoginServiceInterface

package cn.hadoop.rpc;

import java.io.IOException;
import java.net.InetSocketAddress;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.RPC;


public class LoginController {
    public static void main(String[] args) throws IOException {
        LoginServiceInterface proxy = RPC.getProxy(LoginServiceInterface.class, 1L, new InetSocketAddress("master",10000), new Configuration());
        String result = proxy.login("qiqi", "123456");
        
        System.out.println(result);
    }
}



2:在接口LoginServiceInterface中定义一个静态变量的版本号,这要和main方法的LoginServiceInterface proxy = RPC.getProxy(LoginServiceInterface.class, 1L, new InetSocketAddress("master",10000), new Configuration());里面的版本号一致:

package cn.hadoop.rpc;

public interface LoginServiceInterface {
    public static final long versionID=1L;
    public String login(String username,String passwd);
}


3:同样在虚拟机中eclipse的LoginServiceInterface中也加入public static final long versionID=1L;问题就解决了!


你可能感兴趣的:(Exception in thread "main" java.lang.RuntimeException: java.lang.NoSuchFieldException: versionID)