下のようなコードでframeLayoutを取得できません。
java
1 public void onCreate(Bundle savedInstanceState) { 2 super.onCreate(savedInstanceState); 3 4 mSurfaceView = new AnimationSurfaceView(this); 5 6 mSurfaceView = (AnimationSurfaceView) this.findViewById(R.id.surface); 7 FrameLayout frameLayout =(FrameLayout)this.findViewById(R.id.root); 8 9 10 frameLayout.addView(mSurfaceView, 0, new FrameLayout.LayoutParams(WC, WC)); 11 12 setContentView(R.layout.player_activity); 13 } 14
//fragmentで使っていたコード(もともとActivityのコードをFragmentように変更したのに、Activityのコードをどう書いていいかわからなくなってしまいました。Fragmentでは動いています。
java
1 @Override 2 public View onCreateView(LayoutInflater inflater, ViewGroup container, 3 Bundle savedInstanceState) { 4 return inflater.inflate(R.layout.fragment_camera2_basic, container, false); 5 } 6 7 @Override 8 public void onViewCreated(final View view, Bundle savedInstanceState) { 9 mTextureView = (AutoFitTextureView) view.findViewById(R.id.texture); 10 11 12 if(mTextureView==null){ 13 Log.e(TAG,"mTextureVieがnull"); 14 } 15 Log.e(TAG,"mSurfaceViewに値をセットした"); 16 mSurfaceView = (AnimationSurfaceView) view.findViewById(R.id.surface); 17 Log.e(TAG,"mSurfaceViewに値をセットした"); 18 mSurfaceView.setZOrderOnTop(true); 19 mSurfaceView = new AnimationSurfaceView(getActivity()); 20 21 FrameLayout frameLayout =(FrameLayout)view.findViewById(R.id.framelayout); 22 frameLayout.addView(mSurfaceView, 0, new FrameLayout.LayoutParams(WC, WC)); 23 }
java
1<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 android:id="@+id/root" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 android:keepScreenOn="true"> 8 9 10 <com.google.android.exoplayer2.demo.AutoFitTextureView 11 android:id="@+id/texture" 12 android:layout_width="wrap_content" 13 android:layout_height="wrap_content" 14 android:layout_alignParentBottom="true" 15 android:layout_alignParentStart="true" 16 android:layout_alignParentTop="true" /> 17 18 <com.google.android.exoplayer2.ui.SimpleExoPlayerView android:id="@+id/player_view" 19 android:layout_width="match_parent" 20 android:layout_height="match_parent" 21 app:resize_mode="fill" 22 /> 23 <!--app:resize_mode="fixed_height"--> 24 <!--app:resize_mode="fill" これを入れると、AutoLayoutに影響が出る--> 25 26 27 <com.example.android.camera2basic.AnimationSurfaceView 28 android:id="@+id/surface" 29 android:layout_width="match_parent" 30 android:layout_height="match_parent" 31 32 /> 33 34</FrameLayout>
java
1E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.exoplayer2.demo/com.google.android.exoplayer2.demo.PlayerActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.FrameLayout.addView(android.view.View, int, android.view.ViewGroup$LayoutParams)' on a null object reference 2 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596) 3 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2678) 4 at android.app.ActivityThread.-wrap11(ActivityThread.java) 5 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1494) 6 at android.os.Handler.dispatchMessage(Handler.java:111) 7 at android.os.Looper.loop(Looper.java:207) 8 at android.app.ActivityThread.main(ActivityThread.java:5822) 9 at java.lang.reflect.Method.invoke(Native Method) 10 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888) 11 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749) 12 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.FrameLayout.addView(android.view.View, int, android.view.ViewGroup$LayoutParams)' on a null object reference 13 at com.google.android.exoplayer2.demo.PlayerActivity.onCreate(PlayerActivity.java:478)
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/26 00:19
2017/09/26 13:26 編集
2017/09/26 13:37