Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.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列表页脚_Java_Android - Fatal编程技术网

Java Android列表页脚

Java Android列表页脚,java,android,Java,Android,我在代码的第五行/第七行得到一个空指针异常: LayoutInflater inflater = getLayoutInflater(); View header = inflater.inflate(R.layout.footer_row, (ViewGroup) findViewById(R.id.header_layout_root)); TextView tv_footer = (TextView) findViewById(R.id.tv_footertext)

我在代码的第五行/第七行得到一个空指针异常:

    LayoutInflater inflater = getLayoutInflater();
    View header = inflater.inflate(R.layout.footer_row, (ViewGroup) findViewById(R.id.header_layout_root));
    TextView tv_footer = (TextView) findViewById(R.id.tv_footertext);
    if(getListView().getCount()<=8) {
        tv_footer.setText("You have no more assignments");
    } else {
        tv_footer.setText(Integer.toString(getListView().getCount()) + " assignments shown");
    }
    getListView().addFooterView(header, null, false);
LayoutInflater充气机=getLayoutInflater();
视图页眉=充气器。充气(R.layout.footer\u行,(视图组)findViewById(R.id.header\u layout\u根));
TextView tv\u footer=(TextView)findViewById(R.id.tv\u footertext);

如果(getListView().getCount()而不是从
活动的
视图
中使用
findViewById()
方法,则应该从膨胀的
视图
中指定
文本视图
(我假定它是
R.layout.footer行
中的页脚
TextView

示例代码:

TextView tv_footer = (TextView) header.findViewById(R.id.tv_footertext);

更改下面指定的代码的第三行。因为膨胀视图包含指定的textView

TextView tv_footer = (TextView) header.findViewById(R.id.tv_footertext);

谢谢。

你能发布logcat信息吗,似乎没有设置tv\u页脚值,可能是R.id.tv\u页脚文本不是你在setContentView(..)方法中设置的布局部分。请检查一下。最好提供详细的代码(因为你发布的代码看起来不错)

没错,但另一个人先回答,所以得到了勾号。无论如何,谢谢你!无论如何,我感谢你点击上面的三角形。:)。