java.lang.IllegalStateException: No activity

Fragment里面包含ViewPager,ViewPager由多个Fragment组成

viewPager的adpter设置了getChildFragmentManager()后依然不起作用.报错

java.lang.IllegalStateException: No activity

解决办法:

覆盖包裹ViewPager的Fragment的onDetach方法

	@Override
    public void onDetach() {
    	super.onDetach();
    	try {
    	    java.lang.reflect.Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
    	    childFragmentManager.setAccessible(true);
    	    childFragmentManager.set(this, null);
    	} catch (NoSuchFieldException e) {
    	    throw new RuntimeException(e);
    	} catch (IllegalAccessException e) {
    	    throw new RuntimeException(e);
    	}
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
java.lang.IllegalStateException: No properties是一个异常,表示在代码中找不到配置属性。这个异常通常发生在使用Spring Boot时,没有正确配置@ConfigurationProperties注解的情况下。 解决这个问题的方法是确保在需要配置属性的类上添加@ConfigurationProperties注解,并在属性的getter和setter方法上添加@Value注解。这样Spring Boot就能正确地读取和注入配置属性。 以下是一个示例代码,演示了如何解决java.lang.IllegalStateException: No properties异常: ```java import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; @Component @ConfigurationProperties(prefix = "myapp") public class MyAppProperties { private String property1; private int property2; public String getProperty1() { return property1; } public void setProperty1(String property1) { this.property1 = property1; } public int getProperty2() { return property2; } public void setProperty2(int property2) { this.property2 = property2; } } ``` 在上面的示例中,我们创建了一个名为MyAppProperties的类,并在类上添加了@ConfigurationProperties注解,并指定了属性的前缀为"myapp"。然后,我们定义了两个属性property1和property2,并为它们分别提供了getter和setter方法。 通过这样的配置,Spring Boot就能正确地读取和注入配置属性,避免了java.lang.IllegalStateException: No properties异常的发生。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值