B4J Question JavaObject Error

victormedranop

Well-Known Member
Licensed User
Longtime User
Hi, i am trying to run some javaObject, but got and error
java.lang.RuntimeException: Method: sendudp not found in: net.nowyouseeme.nvr.client

that's the method is not found.

the class work great on eclipse. I really don't understand what's happened.

some advice,

Victor

I am using this to run the function.

B4X:
Dim J As JavaObject = Me
 J.RunMethod("sendudp", Array As String ("172.31.3.150",data))

this is the code ->

B4X:
#If JAVA
import java.util.logging.*;
import com.cloudbees.syslog.*;
import com.cloudbees.syslog.sender.TcpSyslogMessageSender;
import com.cloudbees.syslog.sender.UdpSyslogMessageSender;
public class SyslogC {
 
 private  final SyslogMessage SyslogMessage = null;
 public SyslogMessage msg = SyslogMessage;
 public  final Logger LOGGER = Logger.getLogger( Class.class.getName() );
 
public  void send_udp(String host, String sms)  {
  try {
      SyslogMessage msg = new SyslogMessage()
        .withAppName("monitor")
              .withFacility(Facility.SYSLOG)
              .withHostname("my-hostname")
              .withMsg(sms + Timestamp(System.currentTimeMillis()))
              .withSeverity(Severity.CRITICAL)
              .withTimestamp(System.currentTimeMillis());
      
      UdpSyslogMessageSender messageSender = new UdpSyslogMessageSender();
      messageSender.setSyslogServerHostname(host);
      messageSender.setSyslogServerPort(514);
      messageSender.setMessageFormat(MessageFormat.RFC_3164);
     System.out.println(msg.toSyslogMessage(messageSender.getMessageFormat()));
     messageSender.sendMessage(msg);
  } catch (Exception e) {
   
  }
  
  
 } 
 
 public  void send_tcp(String host, String sms) throws Exception {
 try {
     SyslogMessage msg = new SyslogMessage()
      .withAppName("monitor")
             .withFacility(Facility.SYSLOG)
             .withHostname("my-hostname")
             .withMsg(sms + Timestamp(System.currentTimeMillis()))
             .withSeverity(Severity.CRITICAL)
             .withTimestamp(System.currentTimeMillis());
     TcpSyslogMessageSender messageSender = new TcpSyslogMessageSender();
     messageSender.setSyslogServerHostname(host);
     messageSender.setSyslogServerPort(514);
     messageSender.setMessageFormat(MessageFormat.RFC_3164);
     messageSender.setSsl(true);
     messageSender.sendMessage(msg);
 } catch (Exception e) {
  
 }
 }
 private  long Timestamp(long currentTimeMillis) {
  return System.currentTimeMillis();
 }
}
#End If
 

stevel05

Expert
Licensed User
Longtime User
I can't test it without recreating your project but it looks to me like it might be as simple as the call should be
B4X:
J.RunMethod("send_udp", Array As String ("172.31.3.150",data))
with an underscore.

You may also need to change the Method declaration to static.
 
Upvote 0

victormedranop

Well-Known Member
Licensed User
Longtime User
If I change to static does not allow me to send variables. Also try change name in java code. Sorry for that.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
It's probably where you have made the inline java code into a class.

If I add a class via inline java I usually have a method outside of the class that simply returns a new copy of it to the caller.

B4X:
Dim jo As JavaObject = Me
Dim myClass As JavaObject
…
myClass = jo.RunMethod("getNew",Null))
…
myClass.RunMethod("whatever",array(123))
…
#If Java
public static myJavaClass getNew(){
   return new myJavaClass();
}

public class myJavaClass{
…
}
#End If
 
Last edited:
Upvote 0

victormedranop

Well-Known Member
Licensed User
Longtime User
the real solution was convert that code to a library.
now is working.

but thats was true, was in a class module.
i post the library in the b4j forum.

Victor
 
Upvote 0
Top