Hey everyone so I am having a problem with a videoView inside of a popUp window, everytime I try open the window it shuts down the app for some reason. I know where is the problem but I dont know the correct way to fix the issue. If anyone knows how to fix this it would be much appriacated.
This is my main activity
public class Day1 extends AppCompatActivity {
Dialog myDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.part_sh_day1);
myDialog = new Dialog(this);
}
public void ShowFirstPopup(View v) {
TextView mTextView;
//================================-Text-View-====================================
myDialog.setContentView(R.layout.video_popup);
mTextView = myDialog.findViewById(R.id.txtclose);
mTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myDialog.dismiss();
}
});
//================================-Video-View-====================================
VideoView mVideoView;
mVideoView = findViewById(R.id.videoPlayer);
Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.gymsharktrain_1);
myDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
myDialog.show();
mVideoView.setVideoURI(uri);
}
}
And this is the xml file op popUp window
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="350dp"
android:layout_height="300dp"
android:background="@color/colorGrey"
android:padding="10dp"
android:layout_gravity="center">
<TextView
android:id="@+id/txtclose"
android:layout_width="30dp"
android:layout_height="30dp"
android:textColor="@color/colorLightGrey"
android:text="X"
android:textStyle="bold"
android:textSize="19sp"
android:layout_gravity="end"
android:gravity="center"
android:background="@drawable/circlebackground"
android:layout_marginBottom="7dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<VideoView
android:id="@+id/videoPlayer"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</LinearLayout>
Error messege:
2020-01-15 21:57:59.138 3179-3224/com.example..... D/IMonitor: Load library imonitor_jni
2020-01-15 21:57:59.140 3179-3179/com.example..... V/ActivityThread: Skipping new config:{1.0 231mcc2mnc [en_GB] ldltr sw360dp w360dp h679dp 480dpi nrml long hdr port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 2037) mAppBounds=Rect(0, 81 - 1080, 2118) mWindowingMode=fullscreen mActivityType=undefined} nonFullScreen=0 suim:1 s.22}, config:{1.0 231mcc2mnc [en_GB] ldltr sw360dp w360dp h679dp 480dpi nrml long hdr port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 2037) mAppBounds=Rect(0, 81 - 1080, 2118) mWindowingMode=fullscreen mActivityType=undefined} nonFullScreen=0 suim:1 s.22} for app:com.example.......
2020-01-15 21:57:59.142 3179-3207/com.example..... E/MemoryLeakMonitorManager: MemoryLeakMonitor.jar is not exist!
2020-01-15 21:57:59.148 3179-3224/com.example.....W/ZrHung.AppEyeUiProbe: Failed to get config from zrhung
2020-01-15 21:57:59.164 3179-3222/com.example..... E/AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@1093b93
2020-01-15 21:57:59.191 3179-3179/com.example..... V/HwPolicyFactory: : success to get AllImpl object and return....
2020-01-15 21:57:59.195 3179-3179/com.example..... V/ActivityThread: callActivityOnCreate
Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.VideoView.setVideoURI(android.net.Uri)' on a null object reference at com.example......ShowFirstPopup