Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » RCP Testing Tool » Method not found with invoke-static call(Call using invoke-static and arguments is returning a "Method not found" error)
Method not found with invoke-static call [message #1778995] Thu, 28 December 2017 01:22 Go to next message
Bruce Edgerton is currently offline Bruce EdgertonFriend
Messages: 25
Registered: May 2017
Junior Member
I am trying to call an external static method using the invoke-static call. If I use it like this:

  	get-now | let [val now -input] {
	   	$now  | equals $testDate | verify-true
   	}

      ......
      proc "get-now" {
	invoke-static -pluginId "mypluginid"
				  -className "mypluginid.date.JDateUtils" 
				  -methodName getNow
     }


In my plugin, the method is defined like this:

    public static String getNow() {
        return formatDateTime(DateTime.now());
    }


This works, the date string is returned. If I try another method from the same plugin that uses arguments I get a "Method not found" error. Here's an example:

   	get-now-plus-days "-7" | let [val date -input] {
	   	$date  | equals $testDate | verify-true
   	}

      ......
      proc "get-now-plus-days" [val days] {
          invoke-static -pluginId "mypluginid"
				  -className "mypluginid.date.JDateUtils" 
				  -methodName getNowPlusDays
				  -args $days

This static method is defined as:

    public static String getNowPlusDays(String days) {
        DateTime date = DateTime.now().plusDays(Integer.valueOf(days));
        
        return formatDateTime(date);
    }


Any help would be appreciated.

Re: Method not found with invoke-static call [message #1780270 is a reply to message #1778995] Fri, 19 January 2018 13:16 Go to previous messageGo to next message
Viktoria Dlugopolskaya is currently offline Viktoria DlugopolskayaFriend
Messages: 109
Registered: March 2017
Senior Member
Hi Bruce,

Could you show how 'days' variable is declared?
Maybe the problem is that 'days' variable has 'int' type. In this case you can try to declare it like this:
global [val days [str "20"]]


Or use integer input argument in your method.
Re: Method not found with invoke-static call [message #1780577 is a reply to message #1780270] Wed, 24 January 2018 04:24 Go to previous messageGo to next message
Bruce Edgerton is currently offline Bruce EdgertonFriend
Messages: 25
Registered: May 2017
Junior Member
Viktoria, thanks for your reply. I changed the API to use an integer parameter instead of a string and it works.
Re: Method not found with invoke-static call [message #1780627 is a reply to message #1780577] Thu, 25 January 2018 01:37 Go to previous messageGo to next message
Bruce Edgerton is currently offline Bruce EdgertonFriend
Messages: 25
Registered: May 2017
Junior Member
Further to this issue, I've added a new procedure which uses a string and int parameter. It should add a number of days to a given reference date:
proc "get-add-days" [val referenceDate] [val days] {
	invoke-static -pluginId "my.plugin"
				  -className "my.plugin.date.JDateUtils" 
				  -methodName "addDays"
				  -args $referenceDate -args $days

Here is the plugin method:
    public static String addDays(String referenceDate, int days) {
        DateTime date = getDateTime(referenceDate).plusDays(days);
        
        return formatDateTime(date);
    }

Calling this method from a script like this :
global [val refDate "10-Jan-2004"]

let [val date [get-add-days $refDate 5]] {
	log -message $date
}

Results in the error:
java.lang.reflect.InvocationTargetException: null
at invoke-static (/Test Common/CTX_DateProcs.ctx:6)
Re: Method not found with invoke-static call [message #1780730 is a reply to message #1780627] Fri, 26 January 2018 11:46 Go to previous messageGo to next message
Viktoria Dlugopolskaya is currently offline Viktoria DlugopolskayaFriend
Messages: 109
Registered: March 2017
Senior Member
Try to remove the second '-args' attribute name, like this:
proc "get-add-days" [val referenceDate] [val days] {
	invoke-static -pluginId "my.plugin"
				  -className "my.plugin.date.JDateUtils" 
				  -methodName "addDays"
				  -args $referenceDate $days
Re: Method not found with invoke-static call [message #1780826 is a reply to message #1780730] Sun, 28 January 2018 23:08 Go to previous messageGo to next message
Bruce Edgerton is currently offline Bruce EdgertonFriend
Messages: 25
Registered: May 2017
Junior Member
Tried that, get the following:

Syntax error on line 9, col 27
at Syntax error (/Test Common/CTX_DateProcs.ctx:9)

Line 9 is the -args line.
Re: Method not found with invoke-static call [message #1781976 is a reply to message #1780826] Thu, 15 February 2018 12:13 Go to previous messageGo to next message
Viktoria Dlugopolskaya is currently offline Viktoria DlugopolskayaFriend
Messages: 109
Registered: March 2017
Senior Member
Could you readd second '-args' attribute name and paste full exception you get?
Re: Method not found with invoke-static call [message #1782016 is a reply to message #1781976] Fri, 16 February 2018 02:41 Go to previous messageGo to next message
Bruce Edgerton is currently offline Bruce EdgertonFriend
Messages: 25
Registered: May 2017
Junior Member
Here is the message:

java.lang.reflect.InvocationTargetException: null
	at invoke-static (/Test Common/CTX_DateProcs.ctx:6)
	at get-add-days (/Test Common/Library Tests/Date Tests.test:27)


And here is the code making the calls:

let [val date [get-add-days $refDate 5]] {
	log -message $date
}


proc "get-add-days" [val referenceDate] [val days] {
	invoke-static -pluginId "au.com.morgans.rcp.core"
				  -className "au.com.morgans.rcp.core.date.JDateUtils" 
				  -methodName "addDays"
				  -args $referenceDate -args $days
}


and finally, the java code:

    public static String addDays(String referenceDate, int days) {
        DateTime date = getDateTime(referenceDate).plusDays(days);
        
        return formatDateTime(date);
    }

Re: Method not found with invoke-static call [message #1782604 is a reply to message #1782016] Tue, 27 February 2018 05:26 Go to previous messageGo to next message
Viktoria Dlugopolskaya is currently offline Viktoria DlugopolskayaFriend
Messages: 109
Registered: March 2017
Senior Member
Seems a NullPointerException occurs in your code. Try to debug your method step-by-step.
Maybe getDateTime() method can return null or an NPE occurs in other methods.

[Updated on: Tue, 27 February 2018 05:27]

Report message to a moderator

Re: Method not found with invoke-static call [message #1782696 is a reply to message #1782604] Wed, 28 February 2018 01:40 Go to previous message
Bruce Edgerton is currently offline Bruce EdgertonFriend
Messages: 25
Registered: May 2017
Junior Member
You were right Viktoria, the string I was passing was in the wrong format, causing an exception. Hadn't thought of that. Thanks very much for your help.
Previous Topic:Additional configuration for "Eclipse Application under Test"
Next Topic:What is the RCPTT workflow?
Goto Forum:
  


Current Time: Sun May 27 05:20:56 GMT 2018

Powered by FUDForum. Page generated in 0.02553 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top