1.java.lang.ClassCastException: android.app.Application cannot be cast to com.kingtime.buytogether.AppContext
出这个异常的原因是在项目中添加了新的Application之后,并没有在AndroidManifest,xml里面添加该类的声明,所以导致编译器抛出异常。
<application
android:name=".AppContext"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
</application>
2.No package identifier when getting value for resource number 0x00000002
主要原因是TextView的setText方法把传入的int类型的percent当做资源Id到项目中查询资源,而资源中却找不到相应的数值,就会报NotFoundException的错误。
在Android中利用id来索引资源的地方很多(如:Toast.makeText()等),所以如果不小心往方法中传入int类型的参数,虽然编译时IDE不会报错,但是运行时,很容易因找不到对应的资源而报错。
解决办法:
所以如果要在TextView中显示int类型的数据,应提前转换成字符串类型。如:
int args= 11;
textView1.setText(String.valueOf(args));
3. java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
一个TextView我换个位置就报错,怎么会这样!!找了很久,这个问题,如果你觉得代码本来是没问题的,那你就clean一下项目吧!!
或者是你的代码真的有问题,把在xml中的TextView在java代码中转换为LinearLayout。。。就报错了
4.java.net.MalformedURLException: Protocol not found: 192.168.0.100:8080/BuyTogetherServer/Images/UserPhoto/default.jpg
查查你URL前面有没有加http://吧,我的就这样:
public final static String Pic_HOST = "http://192.168.0.100:8080/BuyTogetherServer/";
5.android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
原因是:(只有原始创建这个视图层次(view hierachy)的线程才能修改它的视图(view)
说明你在其他线程中更新了视图更新界面,应该在主线程的handle中更新:
final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (info != null) {
titleTV.setText(info.getGoodsname());
}
super.handleMessage(msg);
}
};