I have just started to learn NetApp SDK and trying to run the very first example created by NetApp. I am getting the following error and I don't have any idea why there is something related to com/google/common/io/NullOutputStream
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/io/NullOutputStream
at com.netapp.nmsdk.client.ApiTarget$Encoding$1.createApiInvocation(ApiTarget.java:202)
at com.netapp.nmsdk.client.ApiRunner.createApiInvocation(ApiRunner.java:153)
at com.netapp.nmsdk.client.ApiRunner.run(ApiRunner.java:131)
at com.netapp.nmsdk.client.ApiRunner.run(ApiRunner.java:105)
at getSystemMode.getSystemMode.main(getSystemMode.java:30)
Caused by: java.lang.ClassNotFoundException: com.google.common.io.NullOutputStream
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 more
package getSystemMode;
import com.netapp.nmsdk.client.ApiRunner;
import com.netapp.nmsdk.client.ApiTarget;
import com.netapp.nmsdk.client.ApiTarget.TargetType;
import com.netapp.nmsdk.ontap.api.system.SystemGetVersionRequest;
import com.netapp.nmsdk.ontap.api.system.SystemGetVersionResponse;
public class getSystemMode {
public static void main(String[] args) {
if (args.length < 3) {
System.err.println("Usage: SystemMode <storage-system> <user> <passwd>");;
System.exit(1);
}
try {
ApiRunner runner = new ApiRunner(ApiTarget.builder()
.withHost(args[0])
.withUserName(args[1])
.withPassword(args[2])
.withTargetType(TargetType.FILER)
.useHttp()
.build());
SystemGetVersionRequest req = new SystemGetVersionRequest();
SystemGetVersionResponse resp = runner.run(req);
if (resp.isClustered() != null && resp.isClustered()) {
System.out.println("The storage system " + args[0] + " is in \"Cluster-Mode\"");
} else {
System.out.println("The storage system " + args[0] + " is in \"7-Mode\"");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
NullOutputStream removed from Guava 15.
Use ByteStreams.nullOutputStream() instead. This class is scheduled to be removed in Guava release 15.0.
You have to look your guava version.
More info;
Guava Version Problem About NullOutputStream
Related
I want to work telegram API, I create Bot in telegram and set username and get a token but I can not connect with my java code please help me
I use this code
ApiContextInitializer.init();
TelegramBotsApi telegramBotsApi = new TelegramBotsApi();
try {
telegramBotsApi.registerBot(new TradeBot());
} catch (TelegramApiException e) {
e.printStackTrace();
}
and my proxy is set and test connection is right
public class TradeBot extends TelegramLongPollingBot {
public void onUpdateReceived(Update update) {
}
public String getBotUsername() {
return "xxx";
}
public String getBotToken() {
return "xxx";
}
}
and after run code give this error :
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/cache/RemovalListener
at com.google.inject.internal.InheritingState.<init>(InheritingState.java:63)
at com.google.inject.internal.InjectorShell$Builder.getState(InjectorShell.java:208)
at com.google.inject.internal.InjectorShell$Builder.lock(InjectorShell.java:114)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:102)
at com.google.inject.Guice.createInjector(Guice.java:87)
at com.google.inject.Guice.createInjector(Guice.java:69)
at com.google.inject.Guice.createInjector(Guice.java:59)
at org.telegram.telegrambots.meta.ApiContext.getInjector(ApiContext.java:48)
at org.telegram.telegrambots.meta.ApiContext.getInstance(ApiContext.java:27)
at org.telegram.telegrambots.bots.TelegramLongPollingBot.<init>(TelegramLongPollingBot.java:16)
at TradeBot.<init>(TradeBot.java:6)
at MainClass.main(MainClass.java:10)
Caused by: java.lang.ClassNotFoundException: com.google.common.cache.RemovalListener
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 12 more
Was answered here:
Google Guice can't find class
You need the correct version of the com.google.guava/guava dependency related to the com.google.inject/guice library that you are already using.
I am trying to implement a simple code to read the data from the ultrasonic and send it to a server by using Californium. The problem is that when I use debug, it doesn't have any error. However when I export the code to a runable jar file and run it on my raspberry pi, it throws the following errors:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.NoClassDefFoundError: org/eclipse/californium/elements/util/NamedThreadFactory
at org.eclipse.californium.core.CoapServer.<init>(CoapServer.java:163)
at org.eclipse.californium.core.CoapServer.<init>(CoapServer.java:120)
at iot.main.device.DeviceClient.main(DeviceClient.java:34)
... 5 more
Caused by: java.lang.ClassNotFoundException: org.eclipse.californium.elements.util.NamedThreadFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 8 more
I am not sure what caused this and how to solve it, any suggestion would be much helpful. Below is the code:
package iot.main.device;
import static org.eclipse.californium.core.coap.CoAP.ResponseCode.BAD_REQUEST;
import static org.eclipse.californium.core.coap.CoAP.ResponseCode.CHANGED;
import org.eclipse.californium.core.CoapClient;
import org.eclipse.californium.core.CoapResource;
import org.eclipse.californium.core.CoapResponse;
import org.eclipse.californium.core.CoapServer;
import org.eclipse.californium.core.coap.MediaTypeRegistry;
import org.eclipse.californium.core.server.resources.CoapExchange;
import com.pi4j.io.gpio.*;
public class DeviceClient {
private static GpioPinDigitalOutput sensorTriggerPin ;
private static GpioPinDigitalInput sensorEchoPin ;
final static GpioController gpio = GpioFactory.getInstance();
public static void main(String[] args) {
double ultraVal;
sensorTriggerPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04); // Trigger pin as OUTPUT
sensorEchoPin = gpio.provisionDigitalInputPin(RaspiPin.GPIO_05,PinPullResistance.PULL_DOWN); // Echo pin as INPUT
CoapClient client = new CoapClient("coap://localhost/Ultrasonic");
CoapServer server = new CoapServer();
server.add(new UltraResource());
server.start();
while(true){
try {
Thread.sleep(2000);
sensorTriggerPin.high(); // Make trigger pin HIGH
Thread.sleep((long) 0.00001);// Delay for 10 microseconds
sensorTriggerPin.low(); //Make trigger pin LOW
while(sensorEchoPin.isLow()){ //Wait until the ECHO pin gets HIGH
}
long startTime= System.nanoTime(); // Store the surrent time to calculate ECHO pin HIGH time.
while(sensorEchoPin.isHigh()){ //Wait until the ECHO pin gets LOW
}
long endTime= System.nanoTime(); // Store the echo pin HIGH end time to calculate ECHO pin HIGH time.
ultraVal = ((((endTime - startTime)/1e3)/2) / 29.1);
System.out.println("Distance : " + ultraVal + " cm"); //Printing out the distance in cm
Thread.sleep(1000);
CoapResponse response = client.put(Double.toString(ultraVal), MediaTypeRegistry.TEXT_PLAIN);
if (response!=null) {
System.out.println( response.getCode() );
System.out.println( response.getOptions() );
System.out.println( response.getResponseText() );
} else {
System.out.println("Request failed");
}
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static class UltraResource extends CoapResource {
public String value = "Resource has not changed yet !!!";
public UltraResource() {
super("Ultrasonic");
setObservable(true);
}
#Override
public void handleGET(CoapExchange exchange) {
exchange.respond(value);
}
#Override
public void handlePUT(CoapExchange exchange) {
String payload = exchange.getRequestText();
System.out.println(payload + " cm");
try {
exchange.respond(CHANGED, payload);
value = new String(payload);
changed();
} catch (Exception e) {
e.printStackTrace();
exchange.respond(BAD_REQUEST, "Invalid String");
}
}
}
}
The error states that
Caused by: java.lang.ClassNotFoundException: org.eclipse.californium.elements.util.NamedThreadFactory
This means you are writing code that uses a dependency from Californium. That dependency is within your dev. environment but it is not within the runtime environment of your Raspberry Pi.
Have a look at this other post which may help you. Also this SO site may be better.
I am trying to call "getOrderList" from the ST312_TestMain class. I am getting the java.lang.ExceptionInInitializerError for the below mentioned class.
package com.Main;
import org.w3c.dom.Document;
import com.yantra.ycp.core.YCPContext;
import com.Main.XMLUtil;
import com.Main.SterlingUtil;
public class ST312_TestMain {
public static void main(String[] args) throws Exception {
String ServiceName = "getOrderList";
String sServiceFlag = "N";
Document dTemplate = null;
//ServiceName = "SendDN";
//sServiceFlag = "Y";
Document inputXML=null;
inputXML = XMLUtil.getDocument("<Order OrderHeaderKey='201407181105267340509' />");
//inputXML = XMLUtil.getXmlFromFile("src/Test.xml");
dTemplate = XMLUtil.getDocument("<Order OrderHeaderKey='' OrderNo=''/>");
if (args.length == 3) {
ServiceName = args[0];
sServiceFlag = args[1].equals("Y") ? "Y" : "N";
inputXML = XMLUtil.getXmlFromFile(args[2]);
} else {
System.out
.println("Usage: TestMain <API/Service Name> <API/Service(N/Y)> <Input XML File>");
System.out
.println("No Input received using preset XML to call preset Service");
System.out.println("Service Name=" + ServiceName);
}
***YCPContext env = new YCPContext("admin", "admin");***
System.out.println("Input XML \n" + XMLUtil.getXmlString(inputXML));
try {
Document outputXML = null;
if ("Y".equals(sServiceFlag)) {
outputXML = SterlingUtil.callService(env, inputXML, ServiceName, null);
} else {
outputXML = SterlingUtil.callAPI(env, inputXML, ServiceName, dTemplate);
}
env.commit();
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Service Invocation Failed");
}
}
}
The exception is as follows:
Usage: TestMain <API/Service Name> <API/Service(N/Y)> <Input XML File>
No Input received using preset XML to call preset Service
Service Name=getOrderList
log4j:WARN No appenders could be found for logger (com.yantra.ycp.core.YCPContext).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.sterlingcommerce.woodstock.util.frame.Manager.getProperty(Manager.java:1365)
at com.yantra.yfc.util.YFCConfigurator.setStandalone(YFCConfigurator.java:37)
at com.yantra.yfs.core.YFSSystem.init(YFSSystem.java:62)
at com.yantra.yfs.core.YFSSystem.<clinit>(YFSSystem.java:47)
at com.yantra.ycp.core.YCPContext.<init>(YCPContext.java:288)
at com.yantra.ycp.core.YCPContext.<init>(YCPContext.java:276)
at com.Main.ST312_TestMain.main(ST312_TestMain.java:31)
Caused by: java.lang.NullPointerException
at com.sterlingcommerce.woodstock.util.frame.log.base.SCILogBaseConfig.doConfigure(SCILogBaseConfig.java:35)
at com.sterlingcommerce.woodstock.util.frame.log.LogService.<clinit>(LogService.java:110)
... 7 more
Please help me on this problem, since I am not sure how to handle the YCPContext object. ("YCPContext env = new YCPContext("admin", "admin");"). Thanks in advance.
Request support from IBM about this.
No matter what mistakes you may have made configuring it (if any), the Sterling code should not be throwing an NPE at you.
If you are testing in local using main() method, then you should comment all the lines where you are using environment varilable. For your code its env variable.
Probably you wouldn't have added the database driver jars to your project build path... For e.g.
For DB2 database, db2jcc.jar has to be added
For Oracle database, ojdbc.jar has to be added
I am new to FreeTTS and this is my first program.The following program simply reads out a string passed.
I am using Linux Mint 32-bit if that matters.But I extracted jsapi.jar on my windows machine a day back.I believe it doesn't matter.
import javax.speech.*;
import java.util.*;
import javax.speech.synthesis.*;
public class Speak
{
String speaktext;
public void dospeak(String speak,String voicename)
{
speaktext=speak;
String voiceName =voicename;
try
{
SynthesizerModeDesc desc = new SynthesizerModeDesc(null,"general", Locale.US,null,null);
Synthesizer synthesizer = Central.createSynthesizer(desc);
synthesizer.allocate();
synthesizer.resume();
desc = (SynthesizerModeDesc) synthesizer.getEngineModeDesc();
Voice[] voices = desc.getVoices();
Voice voice = null;
for (int i = 0; i < voices.length; i++)
{
if (voices[i].getName().equals(voiceName))
{
voice = voices[i];
break;
}
}
synthesizer.getSynthesizerProperties().setVoice(voice);
System.out.print("Speaking : "+speaktext);
synthesizer.speakPlainText(speaktext, null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
synthesizer.deallocate();
}
catch (Exception e)
{
String message = " missing speech.properties in " + System.getProperty("user.home") + "\n";
System.out.println(""+e);
System.out.println(message);
}
}
public static void main(String[] args)
{
Speak obj=new Speak();
obj.dospeak("Finally It speaks and speaks and speaks","kevin16");
}
}
I am getting this as a gift.
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/speech/freetts/ValidationException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at javax.speech.Central.registerEngineCentral(Central.java:703)
at javax.speech.Central.loadProps(Central.java:775)
at javax.speech.Central.availableSynthesizers(Central.java:651)
at javax.speech.Central.createSynthesizer(Central.java:553)
at Speak.dospeak(Speak.java:16)
at Speak.main(Speak.java:47)
Caused by: java.lang.ClassNotFoundException: com.sun.speech.freetts.ValidationException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 8 more
What can I do not to accept this gift.
PS
I have added all the 4 archives viz en_us.jar,freetts-jsapi10.jar, jsapi.jar,mbrola.jar
1) Find in which jar this class is usually defined:
com.sun.speech.freetts.ValidationException
2) See if you have the jar
3) See if you have the right version of this jar
(open it, see if the class file is there)
4) See if the jar is in the classpath at runtime
I think I need some help with finding an enumeration class within another class using reflection in Java. I have been battling with this for far too long now. I have read this as well as a number of other posts and they all make me believe it should work as below.
public class ModelActivity {
public enum AttributeEnumeration { MODELID, MODELURGENCY, MODELDUEDATEANDTIME }
public static void main(String[] args) {
// Find the class with the given name
String className = "ModelActivity";
Class modelClass = null;
try {
// Retrieve the Class with the given className...
modelClass = Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Class by name '" + className + "' not found.", e);
}
// Find the AttributeEnumeration within the class
String attributeEnumerationClassName = className + ".AttributeEnumeration";
Class attributeEnumerationClass = null;
try {
attributeEnumerationClass = Class.forName(attributeEnumerationClassName);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Class by name '" + attributeEnumerationClassName + "' not found.", e);
}
}
}
However, what actually happens is that the modelClass is found correctly, but the attributeEnumerationClass is not, that is, I get the second ClassNotFoundException as follows:
Exception in thread "main" java.lang.RuntimeException: Class by name 'ModelActivity.AttributeEnumeration' not found.
at ModelActivity.main(ModelActivity.java:27)
Caused by: java.lang.ClassNotFoundException: ModelActivity.AttributeEnumeration
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at ModelActivity.main(ModelActivity.java:25)
Could anyone please point the--probably obvious--mistake out to me. Thank you.
See for yourself:
package foo.bar;
public class Outer{
public enum Inner{}
public static void main(final String[] args){
System.out.println(Inner.class.getName());
}
}
Output:
foo.bar.Outer$Inner
Inner class names are delimited with $, not with a period, so you want ModelActivity$AttributeEnumeration.
BTW:
The $ syntax is valid for class loading only. Use periods to access instances of the class in source as follows:
import foo.bar.Outer.Inner;
// ...
private Inner myEnumValue;
or like this:
private foo.bar.Outer.Inner myEnumValue;
Or, to put it this way:
assertEquals( // two ways to reference the same class
foo.bar.Outer.Inner.class,
Class.forName("foo.bar.Outer$Inner")
);