diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp index 9de967e586088d..2aa4a474977ab8 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp @@ -161,17 +161,21 @@ CHIP_ERROR convertJVideoPlayerToTargetVideoPlayerInfo(jobject videoPlayer, Targe jfieldID getInstanceNameField = env->GetFieldID(jVideoPlayerClass, "instanceName", "Ljava/lang/String;"); jstring jInstanceName = static_cast(env->GetObjectField(videoPlayer, getInstanceNameField)); - const char * instanceName = env->GetStringUTFChars(jInstanceName, 0); + const char * instanceName = {}; + if(jInstanceName != nullptr) + { + instanceName = env->GetStringUTFChars(jInstanceName, 0) + } jfieldID jLastDiscoveredMs = env->GetFieldID(jVideoPlayerClass, "lastDiscoveredMs", "J"); long lastDiscoveredMs = static_cast(env->GetLongField(videoPlayer, jLastDiscoveredMs)); jfieldID getMACAddressField = env->GetFieldID(jVideoPlayerClass, "MACAddress", "Ljava/lang/String;"); jstring jMACAddress = static_cast(env->GetObjectField(videoPlayer, getMACAddressField)); - const char * MACAddress = env->GetStringUTFChars(jMACAddress, 0); + const char * MACAddress = jMACAddress == nullptr ? nullptr : env->GetStringUTFChars(jMACAddress, 0); jfieldID jIsAsleep = env->GetFieldID(jVideoPlayerClass, "isAsleep", "Z"); - bool isAsleep = static_cast(env->GetLongField(videoPlayer, jIsAsleep)); + bool isAsleep = static_cast(env->GetBooleanField(videoPlayer, jIsAsleep)); outTargetVideoPlayerInfo.Initialize(nodeId, fabricIndex, nullptr, nullptr, vendorId, productId, deviceType, deviceName, hostName, 0, nullptr, port, instanceName, chip::System::Clock::Timestamp(lastDiscoveredMs));