"main" java.lang.NoSuchMethodError: - java

Below is my code to integrate with bugzilla and i am getting exception
import java.util.Map;
import com.j2bugzilla.base.Bug;
import com.j2bugzilla.base.BugFactory;
import com.j2bugzilla.base.BugzillaConnector;
import com.j2bugzilla.base.BugzillaMethod;
import com.j2bugzilla.rpc.LogIn;
import com.j2bugzilla.rpc.ReportBug;
public class bugzillaTest {
public static void main(String args[]) throws Exception {
//try to connect to bugzilla
BugzillaConnector conn;
conn=new BugzillaConnector();
conn.connectTo("http://bugzilllaurl");
LogIn login=new LogIn("pramod.kg","123#er");
conn.executeMethod(login);
int id=login.getUserID();
System.out.println("current user id"+id);
BugFactory factory=new BugFactory();
String component="Usability";
String description="this is a test desc";
String os="All";
String platform="PC";
String priority="High";
String product="MMNR7";
String summary="test summary";
String version="1.0";
Bug bugs= factory.newBug()
.setComponent(component)
.setDescription(description)
.setOperatingSystem(os)
.setPlatform(platform)
.setPriority(priority)
.setProduct(product)
.setSummary(summary)
.setVersion(version)
.createBug();
ReportBug report=new ReportBug(bugs);
try {
conn.executeMethod(report);
System.out.println("Bug is logged!");
} catch (Exception e) {
// TODO: handle exception
System.out.println("eror"+e.getMessage());
}
}
}
Exception is :
I have scucessfully logged in but when i run conn.executeMethod(report); i get below error.
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.xmlrpc.parser.XmlRpcResponseParser.getErrorCause()Ljava/lang/Throwable;
at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:195)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:137)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:126)
at com.j2bugzilla.base.BugzillaConnector.executeMethod(BugzillaConnector.java:164)
at bugzillaTest.main(bugzillaTest.java:92)

Add all the below jars and check
xmlrpc-client-3.1.3
xmlrpc-common-3.1.3
xmlrpc-server-3.1.3

l got fix this issue as below
public class bugzillaTest {
private static final String COMP = "Usability";
private static final String DES = "this is a test desc";
private static final String OS = "All";
private static final String PLAT = "PC";
private static final String PRIO = "High";
private static final String PRO = "MMNR7";
private static final String SUM = "test summary";
private static final String VER = "1.0";
public static void main(String args[]) throws Exception {
// try to connect to bugzilla
BugzillaConnector conn;
BugFactory factory;
Bug bugs;
ReportBug report;
conn = new BugzillaConnector();
conn.connectTo("http://192.168.0.31/");
LogIn login = new LogIn("username", "password");
// create a bug
factory = new BugFactory();
bugs = factory
.newBug().
setOperatingSystem(OS)
.setPlatform(PLAT)
.setPriority(PRIO)
.setProduct(PRO)
.setComponent(COMP)
.setSummary(SUM)
.setVersion(VER)
.setDescription(DES)
.createBug();
report=new ReportBug(bugs);
try{conn.executeMethod(login);
conn.executeMethod(report);
}
catch(Exception e){System.out.println(e.getMessage());}
}
}

Related

How can i connect a Java mqtt client with username and password to an emqttd(EMQ) broker?

I am able to subscribe to the mosquitto broker with this Java code, without username and password. Now, i would like to subscribe to an emqttd broker which requires some dummy username and password. How can i do this?. Thanks.
http://tgrall.github.io/blog/2017/01/02/getting-started-with-mqtt/#disqus_thread
https://github.com/emqtt/emqttd
package com.mapr.demo.mqtt.simple;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttException;
public class Subscriber {
public static void main(String[] args) throws MqttException {
System.out.println("== START SUBSCRIBER ==");
MqttClient client=new MqttClient("tcp://localhost:1883", MqttClient.generateClientId());
client.setCallback( new SimpleMqttCallBack() );
client.connect();
client.subscribe("iot_data");
}
}
You could use the MqttConnectOptions:
public class Subscriber {
private static final String CONNECTION_URL = "tcp://localhost:1883";
private static final String SUBSCRIPTION = "iot_data";
private static final String USERNAME = "username";
private static final String PASSWORD = "top-secret";
public static void main(String[] args) throws MqttException {
System.out.println("== START SUBSCRIBER ==");
MqttClient client = new MqttClient(CONNECTION_URL,
MqttClient.generateClientId());
MqttConnectOptions connOpts = setUpConnectionOptions(USERNAME, PASSWORD);
client.connect(connOpts);
client.subscribe(SUBSCRIPTION);
}
private static MqttConnectOptions setUpConnectionOptions(String username, String password) {
MqttConnectOptions connOpts = new MqttConnectOptions();
connOpts.setCleanSession(true);
connOpts.setUserName(username);
connOpts.setPassword(password.toCharArray());
return connOpts;
}
}
This is my final working code:
Without this line,
client.setCallback(new SimpleMqttCallBack());
i can't print the message. Not sure why?.
package com.mapr.demo.mqtt.simple;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
public class Subscriber {
// private static final String CONNECTION_URL = "tcp://localhost:1883";
private static final String CONNECTION_URL = "tcp://192.168.1.102:1883";
private static final String SUBSCRIPTION = "Area1/#";
private static final String USERNAME = "username";
private static final String PASSWORD = "top-secret";
public static void main(String[] args) throws MqttException {
System.out.println("== START SUBSCRIBER ==");
MqttClient client = new MqttClient(CONNECTION_URL, MqttClient.generateClientId());
MqttConnectOptions connOpts = setUpConnectionOptions(USERNAME, PASSWORD);
// This callback is required to receive the message
client.setCallback(new SimpleMqttCallBack());
client.connect(connOpts);
client.subscribe(SUBSCRIPTION);
}
public void messageArrived(String topic, MqttMessage message) throws MqttException {
System.out.println(String.format("[%s] %s", topic, new String(message.getPayload())));
System.out.println("\tMessage published on topic 'Area1'");
}
private static MqttConnectOptions setUpConnectionOptions(String username, String password) {
MqttConnectOptions connOpts = new MqttConnectOptions();
connOpts.setCleanSession(true);
connOpts.setUserName(username);
connOpts.setPassword(password.toCharArray());
return connOpts;
}
}

java.lang.NoClassDefFoundError: net/sourceforge/tess4j/TesseractException

I try to do an ocr application for Mirth with Java and Tesseract.I export the project in jar file and call in Mirth with Javascript that did a hello world application.I believe that I add the jar files right way.However I have a problem in Java OCR,so I get this error,
ERROR (com.mirth.connect.connectors.js.JavaScriptDispatcher:193): Error evaluating JavaScript Writer (JavaScript Writer "RTF>DCM" on channel b469e5af-a78d-41ca-86a0-a7b507799a4d).
java.lang.NoClassDefFoundError: net/sourceforge/tess4j/TesseractException
Project Screenshot
package com.imagerad.ocr;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
public class JavaOCRTest {
static String Tc;
static String phone;
static String date;
public static void main(String[] args) throws IOException{
}
public String returnText(String fileName) throws IOException{
Files.walk(Paths.get(fileName)).forEach(filePath -> {
if (Files.isRegularFile(filePath)) {
File imageFile = filePath.toFile();
ITesseract instance = new Tesseract();
try {
String result = instance.doOCR(imageFile);
int i=result.indexOf("Numarasn: ");
int j=result.indexOf("Tel No:");
int k=result.indexOf("Bilgllendirme Tarihl:");
Tc = result.substring(i+10, i+22);
phone = result.substring(j+8,j+23);
date = result.substring(k+22,k+32);
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
}
});
return Tc+""+phone+""+date;
}
public String returnTC() throws IOException{
return Tc;
}
public String returnPhone() throws IOException{
return phone;
}
public String returnDate() throws IOException{
return date;
}
}
Thank you so much for your helps.
You have to download the Tess4J.jar and add it to the classpath. This jar contains the missing class net/sourceforge/tess4j/TesseractException

Getting Null Pointer Exception for function isElementPresent in Selenium ...

I am getting null pointer exception when I call headerVerification method from main function of TestDriver class, though the element is present.
Start Server Class:
package WebTesting;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
public class StartServer {
private String host;
private String nameOfBrowser;
private int port;
private String url;
public StartServer(String host, int port, String nameOfBrowser, String url){
this.host=host;
this.port=port;
this.nameOfBrowser=nameOfBrowser;
this.url=url;
}
public static Selenium browser;
public void startServer(){
browser = new DefaultSelenium(host, port, nameOfBrowser, url);
browser.start();
browser.open("/");
System.out.println("Browser Started !!!");
}
}
Header Verification Class
package WebTesting;
import com.thoughtworks.selenium.Selenium;
public class HeaderVerification {
private String elementPath;
private String linkPath;
private String testLink;
public HeaderVerification(String elementPath, String linkPath, String testLink){
this.elementPath=elementPath;
this.linkPath=linkPath;
this.testLink=testLink;
}
public static Selenium browser;
public void headerVerification() throws InterruptedException{
System.out.println(elementPath);
if(browser.isElementPresent(elementPath)){
Thread.sleep(5000);
System.out.println("Header is Present");
browser.click(linkPath);
Thread.sleep(5000);
if(browser.getLocation().equals(testLink)){
System.out.println("Correct Location!!!");
}
else
System.out.println("Incorrect Location!!!");
browser.close();
System.out.println("Browser Closed!!!");
}
}
}
TestDriver Class
package WebTesting;
public class TestDriver {
/**
* #param args
*/
static StartServer ss = new StartServer("localhost", 4444, "*firefox", "http://docs.seleniumhq.org/");
static HeaderVerification hv = new HeaderVerification ("//div[#id='header']", "//a[#title='Overview of Selenium']", "http://docs.seleniumhq.org/about/");
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
ss.startServer();
hv.headerVerification();
}
}
The brower static variable is null in the HeaderVerification class. You should add
HeaderVerification.browser = browser;
in StarstServer.startServer() method.

Trying to use jdbc driver for postgresql but it's not working

I have added the jdbc driver to my classpath as far as I know i.e. I added the following to my .profile
export CLASSPATH=$CLASSPATH:location/to/the/jarfile.jar
When I compile my java program I always get this error
javac v9.java
v9.java:8: <identifier> expected
Class.forName("org.postgresql.Driver");//load the driver
^
v9.java:8: illegal start of type
Class.forName("org.postgresql.Driver");//load the driver
^
2 errors
This is driving me insane, any help would be awesome. I'm using Mac OS X Snow Leopard
The java program is here
import java.sql.*;
public class v9
{
String dbURL = "jdbc:postgresql:mydb";
String user = "UserName";
String password = "pswd";
C try
{
Class.forName("org.postgresql.Driver");//load the driver
// Connect to the database
Connection DBconn = DriverManager.getConnection( dbURL, user, password );
}
catch (Exception e)
{
e.printStackTrace();
}
}
Try this - you need a method somewhere:
import java.sql.Connection;
import java.sql.DriverManager;
public class V9
{
public static final String driver = "org.postgresql.Driver";
public static final String url = "jdbc:postgresql://localhost:5432/party";
public static final String username = "pgsuper";
public static final String password = "pgsuper";
public static void main(String [] args)
{
try
{
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
System.out.println(conn.getMetaData().getDatabaseProductName());
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

Java compilation with 2 classes

This is some very simple java OOP but I haven't done this in a while...I'm getting a "symbol not found" error when referencing one java class from another
Class #1:
package toaV2;
import java.sql.Connection;
public class vehicle_model
{
public db_model DB;
public Connection conn;
public static void main(String[] args) {
vehicle_model v = new vehicle_model("system");
}
public vehicle_model(String sys) {
DB = new db_model(sys);
conn = DB.connect();
if(conn != null) {
System.err.println("Got a connection.");
}
else {
System.err.println("Couldn't get a connection...");
}
}
}
Class #2:
package toaV2;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class db_model
{
private static String driver = "com.mysql.jdbc.Driver";
private static String dbUser = "user";
private static String dbPass = "pass";
private static String dbUrl = "jdbc:mysql://url";
private static String system;
public static Connection conn;
public db_model(String sys)
{
system = sys;
}
public static Connection connect()
{
conn = null;
try
{
String dbName = system.toUpperCase();
String dbHost = dbUrl + dbName;
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(dbUrl, dbUser, dbPass);
}
catch(Exception e)
{
System.err.println("Exception: " + e.getMessage());
}
return conn;
}
}
And the errors I get on compilation:
$ javac vehicle_model.java
vehicle_model.java:10: cannot find symbol
symbol : class db_model
location: class toaV2.vehicle_model
public db_model DB;
^
vehicle_model.java:24: cannot find symbol
symbol : class db_model
location: class toaV2.vehicle_model
DB = new db_model(system);
^
2 errors
you need to provide the classpath to the other java files when you're compiling.
i.e. javac -classpath path/to/class2 vehicle_model.java
You must compile your two files in the same command, like
javac vehicle_model.java db_model.java

Categories