Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java android中的LayoutFlater nullpointerexception_Java_Android_Nullpointerexception_Layout Inflater_Android Framelayout - Fatal编程技术网

Java android中的LayoutFlater nullpointerexception

Java android中的LayoutFlater nullpointerexception,java,android,nullpointerexception,layout-inflater,android-framelayout,Java,Android,Nullpointerexception,Layout Inflater,Android Framelayout,我想在FrameLayout中设置Activity。这是我的密码: FrameLayout fl = new FrameLayout(this); fl = (FrameLayout ) findViewById(R.id.actioncontent); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

我想在
FrameLayout
中设置
Activity
。这是我的密码:

FrameLayout fl = new FrameLayout(this);
fl = (FrameLayout ) findViewById(R.id.actioncontent);           
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);           
View myview =LayoutInflater.from(this).inflate(R.layout.wallpaper, null);
fl.removeAllViews();
fl.addView(myview);

我收到一个错误NullPointerException

您没有说明“这”是什么,或者NPE发生在哪里-但可能是“这”显示了错误的上下文。 尝试改用您的活动名称?例如,
MainActivity.this

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            View myview =LayoutInflater.from(this).inflate(R.layout.wallpaper, null);
            fl.removeAllViews();
                fl.addView(myview);

另外,正如我下面所说的,从
View myview=LayoutInflater.from(this.inflate)替换为
View myview=inflater.inflate
您没有说明“this”是什么,也没有说明NPE发生在哪里,但可能是“this”呈现了错误的上下文。 尝试改用您的活动名称?例如,
MainActivity.this

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            View myview =LayoutInflater.from(this).inflate(R.layout.wallpaper, null);
            fl.removeAllViews();
                fl.addView(myview);

另外,正如我下面所说的,从
查看myview=LayoutInflater.从(此)开始,充气
查看myview=Flater.充气
您需要使用
充气机
而不是
LayoutInflater.从(此)

将上面的代码替换为下面的代码

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            View myview =inflater .inflate(R.layout.wallpaper, null);
            fl.removeAllViews();
                fl.addView(myview);

您需要使用
充气机
而不是
LayoutInflater.from(this)

将上面的代码替换为下面的代码

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            View myview =inflater .inflate(R.layout.wallpaper, null);
            fl.removeAllViews();
                fl.addView(myview);
改变

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

改变

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);


View myview=LayoutInflater.from(this).充气(R.layout.wallpaper,null);将此更改为查看myview=充气机。充气(R.layout.wallpaper,null);谢谢我知道了我解决了这个错误现在我有另一个问题我想在这个框架布局中显示一个活动,活动名称是Wallpaper如何在框架布局中显示这个活动myview=LayoutFlater.from(this).充气(R.layout.Wallpaper,null);将此更改为查看myview=充气机。充气(R.layout.wallpaper,null);谢谢我知道了我解决了这个错误现在我有另一个问题我想在这个框架布局中显示一个活动,活动名称是墙纸我如何在框架布局中显示这个活动