# Invoke Java method

**URL:** <https://forum.uipath.com/t/invoke-java-method/149494>\
**Category:** Help\
**Tags:** java, activities\
**Created:** [September 10, 2019, 9:59am UTC](https://forum.uipath.com/t/invoke-java-method/149494 "2019-09-10T09:59:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![subramaniancts](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@subramaniancts](https://forum.uipath.com/u/subramaniancts)\
**Post date:** [September 10, 2019, 9:59am UTC](https://forum.uipath.com/t/invoke-java-method/149494/1 "2019-09-10T09:59:40Z")

</div>

I have searched to understand how to invoke java code from UiPath but unfortunately unable to find any documents or examples. Can someone please explain and share the sample files how to Invoke java method using java scope step by step?

---

<div class="post-metadata">

**Author:** ![Palaniyappan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/palaniyappan/32/524095_2.png) [@Palaniyappan](https://forum.uipath.com/u/Palaniyappan)\
**Post date:** [September 10, 2019, 10:00am UTC](https://forum.uipath.com/t/invoke-java-method/149494/2 "2019-09-10T10:00:42Z")

</div>

hope this would help you

> **[About the Java Activities Package](https://docs.uipath.com/activities/docs/about-the-java-activities-pack)**
>
> The Java Activities Pack contains several new activities that help you harness the power of Java code. With the Java Scope activity you can initialize a Java library, thus providing a scope for all subsequent activities. All activities in this pack...

> **[Invoke Java Method](https://docs.uipath.com/activities/docs/invoke-java-method)**
>
> UiPath.Java.Activities.InvokeJavaMethod Invokes a specified Java method from a .jar loaded in the Java Scope. The result is stored in a JavaObject variable. Properties Common DisplayName - The display name of the activity. This field supports only...

Cheers @subramaniancts

---

<div class="post-metadata">

**Author:** ![subramaniancts](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@subramaniancts](https://forum.uipath.com/u/subramaniancts)\
**Post date:** [September 10, 2019, 10:04am UTC](https://forum.uipath.com/t/invoke-java-method/149494/3 "2019-09-10T10:04:06Z")

</div>

No. I have followed the document but unable to invoke. Any examples will help

---

<div class="post-metadata">

**Author:** ![Palaniyappan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/palaniyappan/32/524095_2.png) [@Palaniyappan](https://forum.uipath.com/u/Palaniyappan)\
**Post date:** [September 10, 2019, 10:10am UTC](https://forum.uipath.com/t/invoke-java-method/149494/4 "2019-09-10T10:10:27Z")

</div>

here you go with an example

> **[Running Static and Object Methods](https://docs.uipath.com/activities/docs/running-static-and-object-methods)**
>
> To exemplify how to use this activity pack, we have built an automation process which showcases its capabilities of running both static and object methods, split into two parts: For the first part, a Java library is initialized by using the Java...

Cheers @subramaniancts

---

<div class="post-metadata">

**Author:** ![subramaniancts](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@subramaniancts](https://forum.uipath.com/u/subramaniancts)\
**Post date:** [September 10, 2019, 11:27am UTC](https://forum.uipath.com/t/invoke-java-method/149494/5 "2019-09-10T11:27:15Z")

</div>

Thanks. I am invoking as per the document but getting exception in Invoke java method activity. i have created a simply method in a class where it will take arguments and print it. I have passed the string parameters as input

RemoteException wrapping System.AggregateException: One or more errors occurred. —\> RemoteException wrapping System.InvalidOperationException: The method could not be invoked. —\> RemoteException wrapping System.InvalidOperationException: An unexpected exception has occurred during the invocation.  
Java Invoker program exception:  
java.lang.NullPointerException  
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)  
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)  
at java.lang.reflect.Method.invoke(Unknown Source)  
at com.uipath.instance.ObjectInstance.InvokeMethod(ObjectInstance.java:141)  
at com.uipath.invoker.InvokerContext.invokeStaticMethod(InvokerContext.java:165)  
at com.uipath.invoker.InvokerContext.invokeStaticMethod(InvokerContext.java:40)  
at com.uipath.server.DotNetProcessRequest.processRequest(DotNetProcessRequest.java:52)  
at com.uipath.Main.main(Main.java:46)

at UiPath.Java.Service.JavaResponse.ThrowExceptionIfNeeded()  
at UiPath.Java.JavaInvoker.d\_\_17.MoveNext()  
— End of stack trace from previous location where exception was thrown —  
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)  
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)  
at UiPath.Java.JavaInvoker.d\_\_14.MoveNext()  
— End of stack trace from previous location where exception was thrown —  
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)  
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)  
at UiPath.Java.Activities.InvokeJavaMethod.d\_\_16.MoveNext()  
— End of inner exception stack trace —  
at UiPath.Java.Activities.InvokeJavaMethod.d\_\_16.MoveNext()  
— End of inner exception stack trace —  
at UiPath.Shared.Activities.AsyncTaskCodeActivity.EndExecute(AsyncCodeActivityContext context,  
IAsyncResult result)  
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context,  
IAsyncResult result)  
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor,  
BookmarkManager bookmarkManager)

---

<div class="post-metadata">

**Author:** ![subramaniancts](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@subramaniancts](https://forum.uipath.com/u/subramaniancts)\
**Post date:** [September 11, 2019, 6:30am UTC](https://forum.uipath.com/t/invoke-java-method/149494/6 "2019-09-11T06:30:26Z")

</div>

Can someone please check this and let me know your suggestion?

---

<div class="post-metadata">

**Author:** ![anurag\_sharma](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anurag_sharma/32/98446_2.png) [@anurag\_sharma](https://forum.uipath.com/u/anurag_sharma)\
**Post date:** [May 1, 2020, 2:31pm UTC](https://forum.uipath.com/t/invoke-java-method/149494/7 "2020-05-01T14:31:12Z")

</div>

Hello Palaniyappan,

I have to reuse the java code into my project that have parameter by using Invoke Java Method can i do that or if you have any other solution please suggest.

Need example flow or video that also help.  
Thanks in advance …
