I have cloned android application from
https://github.com/Azure/azure-iot-sdk-java/tree/master/device/iot-device-samples/android-sample
and created a IOT Hub as directed Here
https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-csharp-csharp-getstarted
and I got Connection string as mentioned there
My code is as bellow
String connString = "HostName=********.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=FYhyjH***************c1rQ22g=";
IotHubClientProtocol protocol = IotHubClientProtocol.MQTT;
DeviceClient client = new DeviceClient(connString, protocol); // error at this line
try {
client.open();
}
catch(IOException e1)
{
System.out.println("Exception while opening IoTHub connection3: " + e1.toString());
}
catch(Exception e2)
{
System.out.println("Exception while opening IoTHub connection4: " + e2.toString());
}
but getting this error while running app, please correct me
06-21 17:29:13.865 12640-12640/com.ccc.iot_demo I/System.out: Exception while opening IoTHub connection2: java.lang.IllegalArgumentException: Device ID cannot be null.
06-21 17:29:13.865 12640-12640/com.ccc.iot_demo W/System.err: java.lang.IllegalArgumentException: Device ID cannot be null.
06-21 17:29:13.865 12640-12640/com.ccc.iot_demo W/System.err: at com.microsoft.azure.sdk.iot.device.IotHubConnectionString.validateTerms(IotHubConnectionString.java:206)
06-21 17:29:13.865 12640-12640/com.ccc.iot_demo W/System.err: at com.microsoft.azure.sdk.iot.device.IotHubConnectionString.<init>(IotHubConnectionString.java:90)
06-21 17:29:13.865 12640-12640/com.ccc.iot_demo W/System.err: at com.microsoft.azure.sdk.iot.device.DeviceClient.<init>(DeviceClient.java:141)
06-21 17:29:13.865 12640-12640/com.ccc.iot_demo W/System.err: at com.ccc.iot_demo.MainActivity.SendMessage(MainActivity.java:52)
06-21 17:29:13.865 12640-12640/com.ccc.iot_demo W/System.err: at com.ccc.iot_demo.MainActivity.onCreate(MainActivity.java:33)
06-21 17:29:13.865 12640-12640/com.ccc.iot_demo W/System.err: at android.app.Activity.performCreate(Activity.java:6259)
06-21 17:29:13.865 12640-12640/com.ccc.iot_demo W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
06-21 17:29:13.865 12640-12640/com.ccc.iot_demo W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
06-21 17:29:13.865 12640-12640/com.ccc.iot_demo W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
06-21 17:29:13.865 12640-12640/com.ccc.iot_demo W/System.err: at android.app.ActivityThread.-wrap11(ActivityThread.java)
06-21 17:29:13.865 12640-12640/com.ccc.iot_demo W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
06-21 17:29:13.865 12640-12640/com.ccc.iot_demo W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
06-21 17:29:13.866 12640-12640/com.ccc.iot_demo W/System.err: at android.os.Looper.loop(Looper.java:148)
06-21 17:29:13.866 12640-12640/com.ccc.iot_demo W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5443)
06-21 17:29:13.866 12640-12640/com.ccc.iot_demo W/System.err: at java.lang.reflect.Method.invoke(Native Method)
06-21 17:29:13.866 12640-12640/com.ccc.iot_demo W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
06-21 17:29:13.866 12640-12640/com.ccc.iot_demo W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)