Name some exceptions in android?
Exception
RuntimeException
throw new RuntimeException("you must provide not null data");
IllegalArgumentException
throw new IllegalArgumentException("can not find page by value:" + pageValue);
ClassCastException
@Override public void onAttach(Activity activity) { super.onAttach(activity); // This makes sure that the container activity has implemented the callback interface. // If not, it throws an exception try { mCallback = (CallbackListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " not implement the interface."); } }
NullPointerException
Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
IOException
FileNotFoundException
NetworkOnMainThreadException
CalledFromWrongThreadException
Only the original thread that created a view hierarchy can touch its views.
java.lang.InterruptedException (thread)
java.net.ConnectException (socket)
java.util.ConcurrentModificationException:
remove list item should use
Iterator
android.content.res.Resources$NotFoundException:
Resource ID #0x7f030000 一定是你在调用类似于如下API的地方,应该赋予的是资源ID,而你却直接给了一个整数。
SQLiteException
java.lang.SecurityException:
Permission Denial: starting Intent ... from Process ... (pid=11188, uid=10103) not exported from uid 10092 只有当 Activity 向外声明了自己是可以处理某些 intent action 时,第三方 App 才能通过 Intent 去启动它。通过配置文件中的 Intent 过滤器来声明。
android.support.v4.app.Fragment$InstantiationException
Unable to instantiate fragment MyFragment: make sure class name exists, is public, and has an empty constructor that is public 很难复现的crash,添加了一个空的构造器解决问题。
java.lang.IllegalStateException
You should check to see if a Fragment is already added before trying to add it.
java.lang.IllegalStateException
Can not perform this action after onSaveInstanceState, Use
commitAllowingStateLoss
.java.lang.ArrayIndexOutOfBoundsException
org.json.JSONException
Value <?xml of type java.lang.String cannot be converted to JSONObject.