sending sms from pc to mobile - java

i am using smsj api to send sms from pc to mobile through gsm modem. as given on the page, i have tried the following code.
package org.marre;
import java.io.IOException;
import org.marre.sms.SmsException;
public class SendMessage {
public void send() {
try{
// Send SMS with clickatell
SmsSender smsSender = SmsSender.getGsmSender("COM7");
String msg ="sample message";
// International number to reciever without leading "+"
String reciever = "9561356345";
// Number of sender (not supported on all transports)
String sender ="9561356345";
// Connect
smsSender.connect();
// Send message
smsSender.sendTextSms(msg, reciever, sender);
// Disconnect
smsSender.disconnect();
} catch(IOException i){
i.printStackTrace();
System.out.println("i");
} catch(SmsException s){
s.printStackTrace();
System.out.println("s");
}
}
public static void main(String args[]){
SendMessage app = new SendMessage();
app.send();
}
}
but i am getting this error message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.marre.sms.transport.gsm.SerialComm.<clinit>(SerialComm.java:58)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.marre.sms.transport.gsm.GsmTransport.class$(GsmTransport.java:83)
at org.marre.sms.transport.gsm.GsmTransport.<clinit>(GsmTransport.java:83)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.marre.sms.transport.SmsTransportManager.getTransport(SmsTransportManager.java:75)
at org.marre.SmsSender.<init>(SmsSender.java:112)
at org.marre.SmsSender.getGsmSender(SmsSender.java:180)
at org.marre.SendMessage.send(SendMessage.java:12)
at org.marre.SendMessage.main(SendMessage.java:30)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 12 more
i am a beginner in java. please help me with the code.
note: i have used smslib api earlier for sending a simple text message. but this does not support ems messages. if you have any other library in mind which supports ems messages, please let me know. smsj was one i could easily download.

The real cause of the problem lies here:
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
The compiler couldn't find org.slf4j.LoggerFactory from the classpath.
Download SLF4J and add the library in your classpath and compile your code.
Note: As smsj references a very old version of Slf4J you need to use this old version as well: http://mvnrepository.com/artifact/org.slf4j/slf4j-simple/1.0-beta9

Related

Having trouble connecting to MongoDB with Java

I'm trying to write a Java program that will connect to a MongoDB database. I already have the IP address, port, userDB, username, and password of the database I'm trying to access.
I have the mongodb-driver-3.0.0.jar file set as a referenced library in Eclipse. I created a MongoDBDriver.java file in the src folder (shown below):
import com.mongodb.MongoClient;
public class MongoDBDriver {
public static void main(String[] args) {
MongoClient client = new MongoClient("10.66.80.152", 27017);
String connectPoint = client.getConnectPoint();
System.out.println(connectPoint);
client.close();
}
}
When I run the script, I get the following error message:
Exception in thread "main" java.lang.NoClassDefFoundError:
com/mongodb/connection/BufferProvider
at MongoDBDriver.main(MongoDBDriver.java:7)
Caused by: java.lang.ClassNotFoundException:
com.mongodb.connection.BufferProvider
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
So, what am I doing wrong and how can I fix it?
Exception means that you have the class path mismatch.
I create small app that connect java and mongodb and do some CURD operations.
eMongoDB-Java-app
I think it will be better solution to connect database.
MongoClient does not have method getConnectPoint(), class Mongo does.
You can read the official website, it will help you out.mongodb official website java tutorial

Protege-OWL: java.lang.NoClassDefFoundError

Im trying to run code use protege-owl. So I added the protege.jar and protege-owl.jar to library to import edu.stanford.smi.protegex.owl.* and edu.stanford.smi.protege.*.
I also added jena jar files to use in next steps.
First i wrote simple code to see how it works :
import java.lang.Object;
import edu.stanford.smi.protege.*;
import edu.stanford.smi.protegex.owl.*;
import edu.stanford.smi.protegex.owl.jena.JenaOWLModel;
import edu.stanford.smi.protegex.owl.model.OWLNamedClass;
public class Main {
public static void main(String[] args) {
// TODO code application logic here
JenaOWLModel model=ProtegeOWL.createJenaOWLModel();
OWLNamedClass c= model.createOWLNamedClass("A");
System.out.print(c.getName());
}
}
But it gives me this error :
CONFIG: Protege 3.0 Build 141, JVM 1.6.0_20-b02, memory=259M, Windows 7, encoding=UTF-8, language=fa, country=IR
WARNING: Look and feel not found: com.jgoodies.plaf.plastic.PlasticLookAndFeel -- SystemUtilities.loadLookAndFeel()
WARNING: Plugins directory not found: C:\Users\mona\Documents\NetBeansProjects\JavaApplication3\plugins -- PluginUtilities.getPluginsDir()
WARNING: Exception Caught -- java.lang.NoClassDefFoundError: com/toedter/calendar/JDateChooser
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at edu.stanford.smi.protege.plugin.PluginUtilities.isLoadableClass(Unknown Source)
at edu.stanford.smi.protege.plugin.PluginUtilities.checkPlugin(Unknown Source)
at edu.stanford.smi.protege.plugin.PluginUtilities.checkPlugins(Unknown Source)
at edu.stanford.smi.protege.plugin.PluginUtilities.processManifest(Unknown Source)
at edu.stanford.smi.protege.plugin.PluginUtilities.loadPluginsWithClassLoader(Unknown Source)
at edu.stanford.smi.protege.plugin.PluginUtilities.createClassLoaderAndLoadPlugins(Unknown Source)
at edu.stanford.smi.protege.plugin.PluginUtilities.loadPlugins(Unknown Source)
at edu.stanford.smi.protege.plugin.PluginUtilities.loadSystemPlugins(Unknown Source)
at edu.stanford.smi.protege.plugin.PluginUtilities.loadPlugins(Unknown Source)
at edu.stanford.smi.protege.plugin.PluginUtilities.init(Unknown Source)
at edu.stanford.smi.protege.plugin.PluginUtilities.<clinit>(Unknown Source)
at edu.stanford.smi.protege.util.SystemUtilities.init(Unknown Source)
at edu.stanford.smi.protege.util.SystemUtilities.<clinit>(Unknown Source)
at edu.stanford.smi.protege.model.Project.<clinit>(Unknown Source)
at edu.stanford.smi.protegex.owl.ProtegeOWL.createJenaOWLModel(ProtegeOWL.java:32)
at javaapplication3.Main.main(Main.java:25)
Caused by: java.lang.ClassNotFoundException: com.toedter.calendar.JDateChooser
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method) . . . .
What can I do ?
Update:
I replace protege.jar with protege-3.5.jar and now it gives :
Exception in thread "main" java.lang.NoSuchMethodError: edu.stanford.smi.protege.model.SystemFrames.replaceFrame(Ledu/stanford/smi/protege/model/Frame;)V
at edu.stanford.smi.protegex.owl.model.impl.AbstractOWLModel.createSystemFrames(AbstractOWLModel.java:544)
at edu.stanford.smi.protege.model.DefaultKnowledgeBase.<init>(DefaultKnowledgeBase.java:79)
at edu.stanford.smi.protegex.owl.model.impl.AbstractOWLModel.<init>(AbstractOWLModel.java:318)
at edu.stanford.smi.protegex.owl.jena.JenaOWLModel.<init>(JenaOWLModel.java:62)
at edu.stanford.smi.protegex.owl.jena.JenaKnowledgeBaseFactory.createKnowledgeBase(JenaKnowledgeBaseFactory.java:55)
at edu.stanford.smi.protege.model.Project.createDomainKB(Project.java:429)
at edu.stanford.smi.protege.model.Project.createDomainKnowledgeBase(Project.java:447)
at edu.stanford.smi.protege.model.Project.<init>(Project.java:359)
at edu.stanford.smi.protege.model.Project.<init>(Project.java:341)
at edu.stanford.smi.protege.model.Project.createNewProject(Project.java:545)
at edu.stanford.smi.protegex.owl.ProtegeOWL.createJenaOWLModel(ProtegeOWL.java:32)
at javaapplication3.Main.main(Main.java:24)
Java Result: 1
Where is the problem?
I downloaded protege-owl.jar which is 3.24MB from different link and now it works.

How to open pdf file without save,save as,print using java?

I have used opening pdf using following code.
try
{
File file = new File("Sample.pdf");
java.awt.Desktop.getDeskTop().open(file);
System.out.println("File opened successfully");
}catch(Exception ex)
{
System.out.println("Error occurred: "+ex);
}
Now i want disable save,save as,print option in the pdf file before opening.I have tried this link.but it wont work.
It throws following error occur.
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/cms/Recipient
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.cms.Recipient
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
How to disable save,save as,print option for given pdf file?
You missd the most importnat part of the link you attached, you need to use the PdfWriter static fileds, i am not sure it support all your needs but at least some of them like ALLOW_PRINTING.

java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Base64 when trying to create CommonsHttpOAuthConsumer

EDIT:
public static void main(String[] args)throws Exception {
// TODO Auto-generated method stub
System.out.println("debug1");
CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer("key","secret");
System.out.println("debug2");
...}
hi when i try to run this script i get this response:
debug1
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/binary/Base64
at oauth.signpost.signature.OAuthMessageSigner.<init>(OAuthMessageSigner.java:37)
at oauth.signpost.signature.HmacSha1MessageSigner.<init>(HmacSha1MessageSigner.java:30)
at oauth.signpost.AbstractOAuthConsumer.<init>(AbstractOAuthConsumer.java:65)
at oauth.signpost.commonshttp.CommonsHttpOAuthConsumer.<init>(CommonsHttpOAuthConsumer.java:30)
at mein.tester.main(tester.java:21)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Base64
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 5 more
Line 21 is the line before
System.out.println("debug2");
Well i can easily compile the code in eclipse and i added 2 Signpost librabrys and also common-codec.jar as external library as i read in another post.. however, how do i make it available on runtime?(i did like in the post "add it to WEB-INF/lib " -> i created that folder and added the jar
-i also tryed the defaultoauthconsumer -> same error
Right click on the jar and choose "add to build path"? I don't think the ide will automatically add it to your classpath unless you tell it to.

Getting error while sending Push Notification to iPhone using Java-PNS?

I am using javaPNS_2.2.jar file to send push notification message to iPhone device.
My Code is:
PushNotificationPayload payload = PushNotificationPayload.complex();
/* Customize the payload */
payload.addAlert("Hello World!");
payload.addCustomDictionary("mykey1", "My Value 1");
payload.addCustomDictionary("mykey2", 2);
/* Push your custom payload */
String keystore = "C:/1.0Eywa_Baba/PushNotificationKey.p12";
String password = "Eywa#12";
boolean production = false;
String devices = "C81DD339-F5C1-529F-BEC4-6C8622BA0BFD";
List<PushedNotification> notifications = Push.payload(payload,
keystore,
password,
production,
devices);
However, I am getting the error:
log4j:WARN No appenders could be found for logger (javapns.notification.Payload).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/jce/provider/BouncyCastleProvider
at javapns.notification.PushNotificationManager.initializeConnection(PushNotificationManager.java:105)
at javapns.Push.sendPayload(Push.java:171)
at javapns.Push.payload(Push.java:149)
at com.example.SendMSG.send(SendMSG.java:35)
at com.example.APNDemo1.main(APNDemo1.java:20)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.BouncyCastleProvider
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
What is causing this exception?
Include the bcprov-jdk15-140 jar in classpath of your project.
Include the bouncycastle library in your project.

Categories