关于IllegalStateException: Bindings already cleared

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_30983519/article/details/88885769

关于IllegalStateException: Bindings already cleared

我们在使用用viewpager的时候 往往里面会加载多个Fragment,如果在Fragment数量超过3个fragment的时候,我们发现,在相互切换的时候会报错报错:java.lang.IllegalStateException: Bindings already cleared.

检查发现,由于(viewpager有回收fragment的机制)

03-29 10:28:35.535 1896-1896/com.xxx.xxx D/2次加载:    onCreateView------>root not null
03-29 10:28:35.958 1896-1896/com.xxx.xxx D/2次加载:    onCreateView------>root not null

在第一次(第一次回收fragment正常)unbind的时候没有报错,第二次(第二次回收fragment报Bindings already cleared. )的时候就报错,也就是第二次没有bind成功。

这个时候我们应对当前代码进行判断处理:

 @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (view == null) {
            view = inflater.inflate(R.layout.activity_myrecord, container, false);
        }
        else {
            Log.d("2次加载","   onCreateView------>root not null");
            //  二次加载删除上一个子view
            ViewGroup viewGroup = (ViewGroup) view.getParent();
            if (viewGroup != null) {
                viewGroup.removeView(view);
            }
        }
        initView(view);
        return view;
    }

再次运行  问题解决!

 

展开阅读全文

关于IllegalStateException!!!

11-26

在做分页处理的时候,遇到一个奇怪的问题:rnrn--------------- 我的jsp页面 ---------------rn......rn// 略去了对表单输入内容的判断部分,保留了提交代码rn rn........rn//略去次要部分,只留下主要部分rn//提交对象为一个Servletrn rn......rn首页rn上页rn rn下页rn尾页rn共<%=totalPage%>页rn......rnrnrnrn-------------------- 我的Servlet -------------------rn/*主要思路和处理方法如下:rn *将要显示的当前页的数据,放入Vector中,然后通过session传至JSP页面;rn *showURL为要显示的JSP页面的地址,即上面的那个JSP页面;rn *用sendRedirect()进行跳转;rn *sendRedirect()处一直报错,加入try-catch捕获IllegalStateException验证rn */rn......rnVector resultVector = null;rnresultVector = getResult(sql);rnsession.setAttribute("resultVector",resultVector);rn...... rntryrn response.sendRedirect(showURL); rncatch( IllegalStateException h)rn System.out.println("Catch IllegalStateException in Method senRedirect()!"+ h.getMessage());rn h.printStackTrace();rnrnreturn;rn......rnrnrn--------------------- 运行情况 ----------------------rn1、在用上页、下页、首页和尾页链接模式进行提交时,无论如何测试,均不会有异常出现。JSP与Servlet均工作正常;rn2、在用输入数字,进行action-post请求模式时:rna) 如果没有加入try-catch语句块,会不定时的出现IllegalStateException异常,并在页面打出,程序中断。异常跟踪指向response.sendRedirect(showURL)语句;而且出错频率高--基本实验这种action-post请求模式两三次就会出错一次;rnb) 如果加上try-catch语句块,会在后台打印出如a)页面打印的错误,异常跟踪也指向response.sendRedirect(showURL)语句,但,程序不中断,会继续执行,在客户端无法感知异常。但是,偶尔也会出现白屏,无异常信息。rnrn-------------------- 我的怀疑 ----------------------rn以下是IllegalStateException的解释:rn“Signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation. ”rn我想,应该与“链接”和“action-post”这两种请求模式有关。因为,对应的是同一个JSP和Servlet,只是因为请求方式不同而已!rnrn麻烦大家:)rnrnrnrnrn 论坛

IllegalStateException

06-08

java.lang.IllegalStateExceptionrn at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:433)rn at com.studentM.web.student.loadExcelServlet.doPost(loadExcelServlet.java:55)rn at com.studentM.web.student.loadExcelServlet.doGet(loadExcelServlet.java:31)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:627)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)rn at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)rn at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)rn at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)rn at java.lang.Thread.run(Thread.java:619)rn 论坛

没有更多推荐了,返回首页