ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » Code runs on pure java but not as an app in Android Studio

Post new topic  Reply to topic
 Code runs on pure java but not as an app in Android Studio « View previous topic :: View next topic » 
Author Message
Jthai
PostPosted: Fri Mar 08, 2019 7:20 am    Post subject: Code runs on pure java but not as an app in Android Studio Reply with quote

Newbie

Joined: 08 Mar 2019
Posts: 3

Hello, I am trying to develop an app on Android Studio to display the queue messages on the app. I have written the code below and it runs perfectly fine when I run it as java (using main) in Android Studio. But as soon as I run it as an app, it shows that the queueManager is null and throws me some errors. What could the problem be? Could it be that the MQ library is not made for Android Studio? The code below is called in the method onCreate.

public void init() {
int openOptions = CMQC.MQOO_INQUIRE | CMQC.MQOO_INPUT_AS_Q_DEF;
MQEnvironment.hostname = HOST;
MQEnvironment.channel = CHANNEL;
MQEnvironment.port = PORT;
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
MQEnvironment.properties.put(CMQC.THREAD_AFFINITY_PROPERTY, new Boolean(true));

try {
queueManager = new MQQueueManager(QMGR);
System.out.println("Successfully connected to " + queueManager.getName());
defaultQueue = queueManager.accessQueue(QUEUE_NAME,openOptions);
System.out.println("Queue size: " + defaultQueue.getCurrentDepth());

} catch (MQException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
System.exit(2);
}
finally {
try {
if (queueManager != null);
queueManager.disconnect();
} catch (MQException e) {
e.printStackTrace();
}
try {
if (defaultQueue != null);
defaultQueue.close();
} catch (MQException e) {
e.printStackTrace();
}
}
}

The errors I get are:

2019-03-08 15:33:31.394 29777-29777/com.example.johnthai.testapp W/System.err: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.Map.get(java.lang.Object)' on a null object reference
2019-03-08 15:33:31.395 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.jmqi.JmqiEnvironment.getVersionProperty(JmqiEnvironment.java:2297)
2019-03-08 15:33:31.396 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.jmqi.JmqiEnvironment.getProductIdentifier(JmqiEnvironment.java:2316)
2019-03-08 15:33:31.396 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.jmqi.remote.impl.RemoteConnection.initSess(RemoteConnection.java:1194)
2019-03-08 15:33:31.397 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.jmqi.remote.impl.RemoteConnection.connect(RemoteConnection.java:863)
2019-03-08 15:33:31.398 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.jmqi.remote.impl.RemoteConnectionSpecification.getSessionFromNewConnection(RemoteConnectionSpecification.java:409)
2019-03-08 15:33:31.398 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.jmqi.remote.impl.RemoteConnectionSpecification.getSession(RemoteConnectionSpecification.java:305)
2019-03-08 15:33:31.399 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.jmqi.remote.impl.RemoteConnectionPool.getSession(RemoteConnectionPool.java:146)
2019-03-08 15:33:31.400 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1721)
2019-03-08 15:33:31.400 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1285)
2019-03-08 15:33:31.401 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.MQSESSION.MQCONNX_j(MQSESSION.java:916)
2019-03-08 15:33:31.402 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.MQManagedConnectionJ11.<init>(MQManagedConnectionJ11.java:235)
2019-03-08 15:33:31.403 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.MQClientManagedConnectionFactoryJ11._createManagedConnection(MQClientManagedConnectionFactoryJ11.java:450)
2019-03-08 15:33:31.404 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.MQClientManagedConnectionFactoryJ11.createManagedConnection(MQClientManagedConnectionFactoryJ11.java:487)
2019-03-08 15:33:31.404 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.StoredManagedConnection.<init>(StoredManagedConnection.java:97)
2019-03-08 15:33:31.405 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManager.java:194)
2019-03-08 15:33:31.406 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.MQQueueManagerFactory.obtainBaseMQQueueManager(MQQueueManagerFactory.java:868)
2019-03-08 15:33:31.407 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.MQQueueManagerFactory.procure(MQQueueManagerFactory.java:816)
2019-03-08 15:33:31.408 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.MQQueueManagerFactory.constructQueueManager(MQQueueManagerFactory.java:758)
2019-03-08 15:33:31.408 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.MQQueueManagerFactory.createQueueManager(MQQueueManagerFactory.java:200)
2019-03-08 15:33:31.409 29777-29777/com.example.johnthai.testapp W/System.err: at com.ibm.mq.MQQueueManager.<init>(MQQueueManager.java:805)

These are just some errors. There are a lot more...
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Fri Mar 08, 2019 7:54 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20695
Location: LI,NY

Did you upload the MQ jars (com.ibm.mq.allclient.jar) ?
Is it on the class path? and by the way your transport is all wrong. It needs to be MQ_CLIENT... (you are not running the mqserver on Android...)
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
tczielke
PostPosted: Fri Mar 08, 2019 10:16 am    Post subject: Reply with quote

Guardian

Joined: 08 Jul 2010
Posts: 939
Location: Illinois, USA

It does look like your Android application is failing when the IBM MQ code gets into the environment part of an MQ call. I am not aware of the IBM MQ code being supported on Android.

<psuedo-vendor plug>
On a separate note, I did write an MQ application that does work on Android that you can download (for a $1) on the Google Play Store -> http://www.mqseries.net/phpBB2/viewtopic.php?t=75570

However, this Android application is not using any of the IBM MQ Java code. Just Java code that I wrote to resolve MQ options to their constant values.
<psuedo-vendor plug>
_________________
Working with MQ since 2010.
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Fri Mar 08, 2019 3:52 pm    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3251
Location: London, ON Canada

(1) As I have posted here many times, do NOT use MQEnvironment class as it is not thread safe. Put the connection information into a Hashtable and pass the Hastable to the MQQueueManager class. See here for an example of what I'm talking about.

(2) Putting "System.exit(2);" in the middle of your code is bad form and that means the finally clause will not be called. Hence, the code will leave open the queue and connection to queue manager.

(3) In your finally clause, you have the "disconnect" and "close" backwards. You must close the queue before you disconnect from the queue manager.

Regards,
Roger Lacroix
Capitalware Inc.
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
Jthai
PostPosted: Mon Mar 11, 2019 12:02 am    Post subject: Reply with quote

Newbie

Joined: 08 Mar 2019
Posts: 3

Thank you all for the great answers!

No, @fjb_saper I deleted the library as it would not let me run the app and show me messages like "More than one file was found with OS independent path 'META-INF/ccsid_merged.map'" because some libraries are overlapping.

@tczielke, I will take a look at it.

@RogerLacroix, I have two versions in whichI use the hashtables in my alternative version. I just commented it out because I was testing it in different ways.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Mar 11, 2019 6:45 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20695
Location: LI,NY

Jthai wrote:
Thank you all for the great answers!

No, @fjb_saper I deleted the library as it would not let me run the app and show me messages like "More than one file was found with OS independent path 'META-INF/ccsid_merged.map'" because some libraries are overlapping.

Looks like a classpath or class loader problem. You still need to use transport MQ_CLIENT for Android... and should have used that too on your stand alone Java...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Jthai
PostPosted: Mon Mar 11, 2019 11:41 pm    Post subject: Reply with quote

Newbie

Joined: 08 Mar 2019
Posts: 3

fjb_saper wrote:
Jthai wrote:
Thank you all for the great answers!

No, @fjb_saper I deleted the library as it would not let me run the app and show me messages like "More than one file was found with OS independent path 'META-INF/ccsid_merged.map'" because some libraries are overlapping.

Looks like a classpath or class loader problem. You still need to use transport MQ_CLIENT for Android... and should have used that too on your stand alone Java...


Ok, I will try that thank you
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Code runs on pure java but not as an app in Android Studio
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.