---
title: "异常汇总"
author: "jogickis"
date: "2013-12-17T12:55:55Z"
tags: ["Android", "异常"]
categories: ["移动开发"]
slug: "untitled"
draft: false
lastmod: "2014-01-17T17:51:11Z"
id: 1990790
url: "https://jogickis.iteye.com/blog/1990790"
---

- **java.lang.IllegalStateException: Fragment already active**  
  说明：当Fragment处于激活状态，使用Fragment.setArguments(bundle)就会跑出该异常  
  解决：setArguments()之前，判断Fragment是否可见，Fragment.isVisible();
- **token null is not valid; is your activity running?**  
  说明：我是在使用SlidingMenu一进入就使用Popupwindow.showAtLocation()方法  
  解释：这说明是Activity是否在执行，这个问题的关键是**you are showing your popup too early**. 就是显示的太早了，Activity还没有加载完成
- **has leaked ServiceConnection com.baidu.location.LocationClient$1@40554e10 that was originally bound here**  
  在使用百度地图时，结束后湖出现的错误  
  解决方法：结束LocationClient对象，这个原因是LocationClient定位服务没有结束，调用LocationClient.stop()  
  如果还有错误，则在service中添加一个标签:
  
  ```
  <service
              android:name="com.baidu.location.f"
              android:enabled="true"
              android:permission="android.permission.BAIDU_LOCATION_SERVICE"
              android:process=":remote" >
              <intent-filter>
                  <action android:name="com.baidu.location.service_v2.6" >
                  </action>
              </intent-filter>
  </service>
  ```
- **android.os.NetworkOnMainThreadException**  
  原因上在4.0之后在主线程里面执行Http请求都会报这个错，大概是怕Http请求时间太长造成程序假死的情况吧  
  解决方法：使用Thread、Runnable、Handler (推荐使用)
- 使用百度地图java.lang.StringIndexOutOfBoundsException: length=15; regionStart=0; regionLength=-1   bMapManager.init(KEY,new MyGeneralListener());时出现的问题