I am using asmack for creating a chat app.
For creating a MultiUserChat i am using following code.
muc= new MultiUserChat(HomeActivity.connection, "chatRoom#conference.live-images.com");
try
{
muc.create(HomeActivity.connection.getUser());
muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
muc.join("kam");
}
catch (XMPPException e)
{
e.printStackTrace();
}
But i an getting the error.
Class CastException. & if i remove the Confrence from new MUC() then I get
Server Not Responsing Error.
Where i am wrong? Do i have to use some Patch.
it would be better to send more details like the stack trace.
Make sure you follow the code example here:
Multi User Chat
Related
I need send all exception in my app to server or email, not crash. How can i do that?
try{
}catch(Exception e){
// here send e.getMessage() to server or email
}
Someone can help me?
Crashlytisc is the answer to you question. Your fatal exceptions will be logged to Crashlytics server implicitly while to log non-fatal exceptions you have to do it explicitly, like following;
try{
} catch(Exception e){
// Crashlytics.log(PRIORITY, TAG, MESSAGE);
Crashlytics.log(android.util.Log.ERROR, "TAG","Message");
}
That's what Exception Handling(your try catch is there for),Your App crashes when there is some Exception.Catch it in your try block and handle it in catch....You can write the java code of sending an email in the catch block.The exception generated will be passed as a an argument to the catch....
I am considering that you are not talking of NullPointerException or the other common UI exceptions .
See this for learning about Sending Email
I tried to use
try {
new TwitterFactory(new ConfigurationBuilder()
.setOAuthConsumerKey(TWITTER_KEY)
.setOAuthConsumerSecret(TWITTER_SECRET)
.setOAuthAccessToken(TWITTER_TOKEN)
.setOAuthAccessTokenSecret(TWITTER_TOKEN_SECRET)
.build()).getInstance().updateStatus("HELLO WORLD!");
} catch (TwitterException e) {
e.printStackTrace();
}
But as soon as I run it, it gives me this error:
this might be a possible answer: In order to get access acquire AccessToken using xAuth, you must apply by sending an email to api#twitter.com — all other applications will receive an HTTP 401 error. from here but his answer is not complete (does not have steps to follow)
How to fix this? Thanks!
I had this code that worked well last Thursday (04/19/2012):
Connection conn = null;
Statement inst;
try {
System.out.println("Connected to the database");
Class.forName ("net.sourceforge.jtds.jdbc.Driver");
//217.126.108.151
conn = java.sql.DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/prueba;sa;sa1234");
inst = conn.createStatement();
System.out.println("Connected to the database");
inst.executeUpdate("INSERT INTO TIENDAS (NOMBRE) VALUES ('ZZZZZZZ') ");
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
But after the last update of the Android SDK stopped working.
Now I get this error:
java.lang.RuntimeException: No message resource found for message property prop.servertype
Does anyone know why?
Thanks in advance.
Clean your project and rebuild at again. Still if your getting the same problem
try the following way..
-> Instead of localhost in url use this ip : 10.0.2.2
I'm not sure, but since Android >=3.0, network connection have to run in seperate Thread or Task. But if this is the problem, you should get an other exception.
But give it a try :)
And don't forget to check the permissions in your Manifest.
Hello Everyone i am new to android and i am currently stuck on this.
I have to return list of public rooms created on xmpp server. The problem i am having is that the code below works fine for java but there is a null pointer exception in case of android.
Any help regarding this would be appreciated.
I am using an openfire server and testing it on local machine so that is the reason why i am using ip Address instead of domain name.
I am using smack library for JAVA and Asmack Library for android
String server_name = "192.168.3.113";
ConnectionConfiguration config = new ConnectionConfiguration(
server_name, 5222);
XMPPConnection connection = new XMPPConnection(config);
try {
connection.connect();
connection.login("s1", "123");
Collection<HostedRoom> rooms = MultiUserChat.getHostedRooms(
connection, "conference.geekoid");
for (HostedRoom room : rooms) {
System.out.println(room.getName());
}
} catch (XMPPException e) {
System.out.println("Error" + e.getMessage() + "\n"); //for JAVA
log.e("Android Error",e.getmessage()); // For Android
}
The problem is that the static block of the ServiceDiscoveryManager class has to be evaluated before any connection is created. In smack this is done via an configuration file, but this approach does not work on Android and therefore on aSmack.
The workaround mentioned in the answer is somehow ugly, since you really don't want to use the Constructor to fetch the SDM object, instead the get() method should be used. But the get() method only works if there was actually a SDM created for the connection.
So in order to init the SDM correctly on Android you need to call the full forName notation to init the static blocks of the class before you create the first (XMPP)Connection object.
Class.forName("org.jivesoftware.smackx.ServiceDiscoveryManager", true, ClassLoader.getSystemClassLoader()):
This is tracked as aSmack Issue 8
I have found the Solution to the problem.
The Android asmack library was using this in
getHostedRooms(Connection connection,
String serviceName) method
ServiceDiscoveryManager discoManager =ServiceDiscoveryManager.getInstanceFor(connection);
i replaced it with
ServiceDiscoveryManager discoManager = new ServiceDiscoveryManager(connection);
For those who are confused where this method is its in
Package: org.jivesoftware.smackx.muc
File: MultiUserChat.java
After you have done this. We have to register all the providers in Android whose detail can be found here. These providers are automatically registered when are using JAVA's smack library (In java Development) but in Android we have to register them ourself.
I have a wierd problem. I have the following code:
if (fbIntent.hasExtra("Link")) {
try{
postData[0]= fbIntent.getStringExtra("Link");
} catch (Exception e) {Log.d("fbIntent error",e.getMessage() );}
}
fbIntent.hasExtra("Link") is true. So the compiler goes into the if statement. But I am not able to get the string using fbIntent.getStringExtra("Link"). This I know from debugging in eclipse. When I run it, I get :
01-21 14:12:01.030: ERROR/AndroidRuntime(311): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.examples.Kikin/com.examples.Kikin.FacebookLogin}: java.lang.NullPointerException: println needs a message
Please help me.
You need to initialize postData. Try something like String[] postData = new String[1]. Obviously, if you want use postData[1], [2], and [3], you'd need to say new String[4].
1) Your current issue is in
Log.d("fbIntent error", e.getMessage());
e.getMessage() may return null, so you get the java.lang.NullPointerException: println needs a message. Use e.toString() instead. Or the best way would be:
Log.e("some tag", "some comment", e);
2) When you fix this, you will be able to see the actual error to go further in fixing your root/real issue. So feel free to update your post with new log data.