安卓开发错误集合

本文汇总了Android开发过程中常见的错误及解决方案,包括匿名类使用非final变量、API版本不兼容问题、不同监听器间的冲突处理等,适用于初学者及有一定经验的开发者。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、Cannot refer to a non-final variable rb inside an inner class defined in a different method

一旦参数在匿名类内部使用,则必须是final

即:final TextView tv = (TextView)findViewById(R.id.TextView1);

2、Exception raised during rendering: java.lang.System.arraycopy([CI[CII)V Exception details are logged


出现这样的问题是API 20不支持EditView控件,需要选择一个低版本的API就可以了。

3、The method setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener) in the type CompoundButton is not applicable for the arguments (new RadioGroup.OnCheckedChangeListener(){})

当RadioGroup与CompoundButton同时存在且都要监听事件时CompoundButton.OnCheckedChangeListener与RadioGroup.OnCheckedChangeListener就会出现冲突,导入任何一个包importandroid.widget.RadioGroup.OnCheckedChangeListener;会出现错误:

添加CompoundButton.就可以了

RadioButton rb = (RadioButton)this.findViewById(R.id.kai);

tb.setOnCheckedChangeListener(
newCompoundButton.OnCheckedChangeListener()
{

}

);

4、The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the argum

import android.content.DialogInterface.OnClickListener;  改成    import android.view.View.OnClickListener;

5、Call requires API level 5 (current min is 1): android.bluetooth.BluetoothAdapter#getDefaultAdapter

暂时解决办法:右击工程->Android Tools->Clear Lint Markers

完全解决办法:

AndroidManifest.xml中添加

<uses-sdk
    android:minSdkVersion="5"
    android:targetSdkVersion="5" />

6、错误:【The method setOnItemSelectedListener(AdapterView.OnItemSelectedListener) in the type AdapterView<ListAdapter> is not applicable for the arguments (new OnItemSelectedListener(){})】【OnItemSelectedListener cannot be resolved to a type】

添加:import android.widget.AdapterView.OnItemSelectedListener;

7、AutoUpdateReceiver cannot be resolved to a type

手动添加

import com.coolweather.app.receiver.AutoUpdateReceiver;

快捷键没有反应

8、The constructor ArrayAdapter<String>(Top, int, String[]) is undefined

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,st);

设置this为:活动名.this或者getContext()

9、No AVD available

如果有创建AVD,还出现这种情况,是因为版本过高,修改AndroidManifest.xml中android:minSdkVersion="8"

10、The import android.support.v7 cannot be resolved

ActionBarActivity cannot be resolved to a type

The method onCreate(Bundle) of type MainActivity must override or implement a supertype method

解决办法:api版本不对,可能api版本太低,右击项目->属性(Properties)->android

Library中先删除有×的,然后点击Add添加一个新的,点击OK

11、R cannot be resolved to a variable

注意所以的资源问题和文件名不能为大写、中文符号

12、不允许有匹配 "[xX][mM][lL]" 的处理指令目标。

检查AndroidManifest.xml中头部<?xml version="1.0" encoding="utf-8"?>前面是不是有空格,去掉空格就好了

13、导入android-support-v7项目错误

右击项目->Properties>Android->Library中选中带× 的android-support-v7,选择Remove,然后Add.....选择新的v7包,OK

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值