Android异常

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);
			}
		};


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值