Các lỗi thường gặp trong android – android error

09 Nov

— ActivityNotFoundException: Unable to find explicit activity class
have you declared this activity in your AndroidManifest.xml?
—> chưa khai báo lớp Activity trong manifest activity mà đã start

— java.lang.NumberFormatException: Color value ‘@drawable/border_black_topleftright’ must start with #
–> khai báo màu phải sử dụng #

— org.xmlpull.v1.XmlPullParserException: Binary XML file line #11: <item> tag requires a ‘drawable’ attribute or child tag defining a drawable
–> yêu cầu phải có thuộc tính con bên trong nó, giống như trong scrollView phải có linearlayout

— error: Apostrophe not preceded by \ (in PLEASE READ THESE TERMS OF USE CAREFULLY
-> post your complete string. Though, my guess is there is an apostrophe (‘) character in your string. replace it with (\’) and it will fix the issue. for example,
(-> sử dụng dấu \ trước dấu ‘)

— java.lang.noclassdeffounderror:
In the updated ADT(Above ADT 17) you have to put jar files inside libs folder and not lib. So make sure that you put gcm.jar file inside libs and not lib folder.
-> D:\adt-bundle-windows-x86_64-20130729\sdk\extras\google\gcm\gcm-client\dist

— OutOfMemory error? or cannot draw bitmap
-> gọi System.gc(); để quét rác trước
–> nếu k đc, coi file: xử lý large image

— This item is unreachable because a previous item (item #1) is a more general match than this one
-> thường bị trong tạo state -> kết quả: k run
–> tạo thêm thuộc tính cho default (đã xử lý đc trong: thay đổi state của

— UnknownHostException:
-> Chưa thêm permission internet
<uses-permission android:name=”android.permission.INTERNET” />

— android.os.NetworkOnMainThreadException
-> lỗi gọi network trong main thread ở android 4x
–> đưa vô trong 1 thread:
new Thread(new Runnable() {

public void run() {
try {
String jsonString = Ultils.getStringJSONFromUrl(StartupActitity.this.getString(R.string.url_push_31), mList);
Log.e(“–LOG jsonString:”, jsonString);
} catch (Exception e) {

— Unable to add window — token null is not for an application
-> change getApplicationContext = activity.this

— ConcurrentModificationException – khi sử dụng for trong list or hashmap mà có remove
-> tạm thời: k sử dụng for earch mà sử dụng for(;;)

— Calling startActivity() from outside of an Activity?
intent = new Intent(mContext, SelectionActivity.class);
— Activity has leaked window that was originally added
do gọi 1 sự kiện trong activity nhưng activity đó đã đóng
thường gặp trong
-> nên dismiss trước khi or trong destroy activity or check activity !=null thì show

— android View not attached to window manager
thường gặp trong progress.dismiss
-> nên check null trước khi dismiss
if (progressDialog != null)

–> nếu k đc nữa:
finally {
try {
} catch (Exception e) {

— IllegalStateException: Application does not define permission x.y.z.permission.C2D_MESSAGE
-> khai báo sai packet
x.y.z = tên packe.tenproject
sửa thành
<permission android:name=””
android:protectionLevel=”signature” />

<uses-permission android:name=”” />

<!– Receives the actual messages. –>
<action android:name=”” />
<!– Receives the registration id. –>
<action android:name=”” />

<category android:name=”” />

— Unable to instantiate service x.y.z.GCMIntentService
-> do sử dụng .GCMIntentService
nên chỉ rõ packet chứa nó (nếu tách riêng)

— lỗi k nhận đc receiver GCMIntentService ….. chung với lỗi GCMBroadcastReceiver(23422): GCM IntentService class
->[temp] nên chuyển chung packet với hàm gọi
-> lý do:
This intent service will be called by the GCMBroadcastReceiver (which is is provided by GCM library),
as shown in the next step. It must be a subclass of,
must contain a public constructor, and should be named my_app_package.GCMIntentService
(unless you use a subclass of GCMBroadcastReceiver that overrides the method used to name the service).

– xử lý:
public class GCMReceiver extends GCMBroadcastReceiver {
protected String getGCMIntentServiceClassName(Context context) {
return “com.dexxtr.gcm.GCMService”;

— radio button trên android 4.1.2 có padding giữa image và text -> sai layout
-> lý do:
–> nên chèn imageview, xử lý manual or set padding 0 cho radio

— null pointer exception setupchild listview java 1774
-> do trong quá trình get view của adapter cho listview bị lỗi
–> try catch quá trình get object + khi khởi tạo đối tượng nên khai báo giá trị mặc định (nếu có lỗi hiển thị default)

— The method getSupportActionBar() is undefined for the type
-> do sliding menu chưa add library: actionbarsherlock

— Jar Mismatch Found 2 versions of android-support-v4.jar in the dependency list
or Found 2 versions of android-support-v4.jar in the dependency list,
but not all the versions are identical (check is based on SHA-1 only at this time).
All versions of the libraries must be the same at this time.
-> sử dụng 2 thư viện giống nhau nhưng khác version
–> chuyển về lib mới nhất or cùng reference tới 1 lib duy nhất

Leave a comment

Posted by on 11/09/2013 in Android, Java


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: