2012-06-10 73 views
1

我已經在netbeans tomcat目錄中設置了帶有工作示例的PHP/Java Bridge。 什麼犯規是使用自定義的JAR 這裏工作是我的代碼:PHP/Java Bridge java.lang.NoSuchMethodException

package com.micha; 

public class Hello1Bean { 
    public Hello1Bean() 
    {} 
    String hi() {return "This is my hello message";} 
    String hello(String name) {return "Hello" + name;} 
} 

而且PHP代碼

<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title></title> 
    </head> 
    <body> 
     <?php 
     require_once ("java/Java.inc"); 
     $world = new Java("com.micha.Hello1Bean"); 
     echo java_values($world->hi()); 
     echo "Hello Working Thingy\n\n"; 

     ?> 
    </body> 
</html> 

當我檢查http://localhost:8084/JavaBridge/mytest.php

javax.servlet.ServletException: java.lang.RuntimeException: PHP Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: Invoke failed: [[o:Hello1Bean]]->hi. Cause: java.lang.NoSuchMethodException: hi(). Candidates: [] VM: [email protected]://java.sun.com/" at: 
#-6 php.java.bridge.JavaBridge.checkM(JavaBridge.java:1085) 
#-5 php.java.bridge.JavaBridge.Invoke(JavaBridge.java:1024) 
#-4 php.java.bridge.Request.handleRequest(Request.java:417) 
#-3 php.java.bridge.Request.handleRequests(Request.java:500) 
#-2 php.java.bridge.http.ContextRunner.run(ContextRunner.java:145) 
#-1 php.java.bridge.ThreadPool$Delegate.run(ThreadPool.java:60) 
#0 C:\Users\Micha\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\webapps\JavaBridge\java\Java.inc(232): java_ThrowExceptionProxyFactory->getProxy(2, 'com.micha.Hello...', 'T', true) 
#1 C:\Users\Micha\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\webapps\JavaBridge\java\Java.inc(360): java_Arg->getResult(true) 
#2 C:\Users\Micha\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\webapps\JavaBridge\java\Java.inc(366): java_Client->getWrappedResult(true) 
#3 C:\Users\Micha\.netbean in C:\Users\Micha\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\webapps\JavaBridge\java\Java.inc on line 195 

    php.java.servlet.fastcgi.FastCGIServlet.handle(FastCGIServlet.java:499) 
    php.java.servlet.fastcgi.FastCGIServlet.doGet(FastCGIServlet.java:521) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393) 
    php.java.servlet.PhpCGIFilter.doFilter(PhpCGIFilter.java:126) 

之前,我有一個ClassNotFoundException所以它知道有一個類,但由於某種奇怪的原因,我不能調用該函數。

回答

2

你的方法是不公開的(如果我有一些類 ,這並不存在,那麼我得到異常替換爲「com.micha.Hello1Bean」),嘗試:

public String hi() { 
     return "This is my hello message"; 
} 
+0

我前面想通了這一點,但我有連接問題,所以我無法發佈,無論如何,你會得到綠色檢查:) – m1sk

相關問題