10 Replies Latest reply on Jun 14, 2017 7:17 AM by supandey RSS
    dmishra Newbie

    thingworx android error

    i am trying to run the sample code provided in the thingworx android sdk

    I have a problem in every sample project


    it says cant resolve the constructor


    thing = new VirtualThing(thingName, "A basic virtual thing", client);

    because the client is not initiialized



    client.isConnected()  is also showing error



    i dont know what 'client' is  because the variable is also not declared anywhere.



    kindly tell the solution

      • Re: thingworx android error
        supandey Collaborator

        Hi Dibya, it seems to me that your project is not correctly setup in studio, here's the blog you could use to correct it Exploring ThingWorx Android SDK together with web based Revision Control System and secured connection to ThingWorx Server

        • Re: thingworx android error
          Ankit Gupta Ninja

          Hi dibya ranjan mishra,


          Have you added the ThingWorx Android SDK jars to your project?

          • Re: thingworx android error
            dmishra Newbie

            package com.thingworx.ptc.shell.utilities;



            import android.app.Service;

            import android.content.BroadcastReceiver;

            import android.content.Context;

            import android.content.Intent;

            import android.content.IntentFilter;

            import android.os.Bundle;

            import android.os.Handler;

            import android.os.HandlerThread;

            import android.os.IBinder;

            import android.os.Looper;

            import android.os.Message;

            import android.os.Process;

            import android.support.annotation.Nullable;

            import android.util.Log;


            <---------this is the error I am saying about-------------------------------->

            import com.thingworx.communications.client.AndroidConnectedThingClient;



            import com.thingworx.communications.client.things.VirtualThing;





            public class ThingworxProcessService extends Service {

                public final String TAG = ThingworxProcessService.class.getName();



                private Looper mServiceLooper;

                private ServiceHandler serviceHandler;

                private AndroidConnectedThingClient client;

                private IntentServiceReceiver serviceReceiver;




                public void onCreate() {

                    serviceReceiver = new IntentServiceReceiver();

                    HandlerThread thread = new HandlerThread("ThingworxProcessService", Process.THREAD_PRIORITY_BACKGROUND);




                    // Get the HandlerThread's Looper and use it for our Handler

                    mServiceLooper = thread.getLooper();

                    serviceHandler = new ServiceHandler(mServiceLooper);





                public int onStartCommand(Intent intent, int flags, int startId) {

                    // For each start request, send a message to start a job and deliver the

                    // start ID so we know which request we're stopping when we finish the job



                    Message msg = serviceHandler.obtainMessage();


                    msg.arg1 = startId;




                    return START_STICKY;






                public IBinder onBind(Intent intent) {

                    return null;







                public void onDestroy() {






                // Handler that receives messages from the thread

                private final class ServiceHandler extends Handler {

                    public ServiceHandler(Looper looper) {




                    public void handleMessage(Message msg) {

                        Log.i(TAG, "handleMessage Start");



                        try {

                            IntentFilter intentFilter = new IntentFilter();


                            registerReceiver(serviceReceiver, intentFilter);



                            Bundle bundle = msg.getData();

                            long pollingRate = bundle.getLong(Constants.POLLING_RATE_EXTRA, 1000l);

                            boolean lastConnectionState = bundle.getBoolean(Constants.LAST_CONNECT_STATE_EXTRA);

                            String stateObserver = bundle.getString(Constants.CONNECTION_OBSERVER);

                            client = ThingworxService.client;



                            boolean isConnected;



                            while (client == null || !client.isShutdown()) {

                                if (client != null && client.isConnected()) {

                                    isConnected = true;



                                    for (VirtualThing thing : client.getThings().values()) {

                                        try {


                                            Log.v(TAG, "Scanning device");


                                        } catch (Exception eProcessing) {

                                            Log.e(TAG, "Error Processing Scan Request for [" + thing.getName() + "] : " + eProcessing.getMessage());





                                    Intent scanned = new Intent();



                                } else {

                                    isConnected = false;





                                if(isConnected != lastConnectionState){

                                    if(stateObserver != null) {

                                        Intent stateChange = new Intent();




                                        stateChange.putExtra(Constants.CONNECTION_OBSERVER, stateObserver);




                                        lastConnectionState = isConnected;







                        } catch (InterruptedException e) {

                            Log.e(TAG, "Polling thread exiting." + e.getMessage());




                        // Stop the service using the startId, so that we don't stop

                        // the service in the middle of handling another job


                        Log.i(TAG, "handleMessage End");





                public class IntentServiceReceiver extends BroadcastReceiver {




                    public void onReceive(Context context, Intent intent) {

                        String action = intent.getAction();




                            if(client != null && client.isConnected())

                                try {


                                } catch (Exception e) {

                                    Log.e(TAG, "Error Shutting Down Client", e);






            • Re: thingworx android error
              dmishra Newbie

              I apologize for my mistake

              it was showing error in the beginning

              but the real error was in gradle dependancies

              then this thing works fine

              I am extremely pleased with the way you have responded to my problem

              Thank you so much.

              Hope to get this support though out