RSS

Category Archives: Java

Tìm hiểu facebook sdk

https://developers.facebook.com/docs/android/

 

long pause at here

 
Leave a comment

Posted by on 11/26/2013 in Android

 

Android multiple screen support – hỗ trợ nhiều loại màn hình cho ứng dụng của android

Để 1 ứng dụng android có thể chạy (không bị lỗi layout) trên các thiết bị sử dụng android khác nhau (độ phân giải khác nhau), tôi có 1 thủ thuật nhỏ sau:

Quy luật chung:

–> nên sử dụng px để làm
–> chọn 1 size màn hình làm chuẩn
–> resize file thiết kế theo size màn hình
-> chuyển đơn vị của text trong pts sang px

Cách thực hiện:

Read the rest of this entry »

 
Leave a comment

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

 

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

— 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: com.google.android.gcm.GCMRegistrar
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 widget.java)

— 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() {

@Override
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) {
e.printStackTrace();
}
}
}).start();

— 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);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
— 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 progress.show
-> 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)
\progressDialog.dismiss();

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

— 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=”jp.co.machicomi.permission.C2D_MESSAGE”
android:protectionLevel=”signature” />

<uses-permission android:name=”jp.co.machicomi.permission.C2D_MESSAGE” />
<intent-filter>

<!– Receives the actual messages. –>
<action android:name=”com.google.android.c2dm.intent.RECEIVE” />
<!– Receives the registration id. –>
<action android:name=”com.google.android.c2dm.intent.REGISTRATION” />

<category android:name=”jp.co.machicomi” />
</intent-filter>

— 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 com.google.android.gcm.GCMBaseIntentService,
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 {
@Override
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: http://stackoverflow.com/questions/2134591/add-margin-between-a-radiobutton-its-label-in-android
–> 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

 

[Spring framework] Dự án Spring thực tế

 
Leave a comment

Posted by on 11/07/2013 in Spring framework

 

Apache Tomcat

 
Leave a comment

Posted by on 11/07/2013 in Java

 

[Android library] Giới thiệu & hướng dẫn thêm thư viện android: PullToRefresh

PullToRefresh

Đây là thư viện khá phổ biến trong các nền tảng ứng dụng trên di động, bao gồm cả android và ios – còn windows phone do chưa có cơ hội tiếp xúc nên tôi không dám khẳng định).
Thư viện này cũng được các ứng dụng nổi tiếng sử dụng, chắc rằng bạn đã từng gặp nó vài ba lần. (Trong các ứng dụng nổi đình nổi đám là facebook, nhưng tôi cũng chưa biết cộng đồng mạng mô phỏng theo hay facebook xài library này)

Mọi người có đọc được ở đâu vui lòng confirm dùm tôi được thì càng tốt 😀

<hình không liên quan>

OK.

Giới thiệu vậy có vẻ hơi thừa với những người đã biết còn với những người chưa biết thì có vẻ hơi mơ hồ. Vậy tôi sẽ giới thiệu clip ngắn này để quý vị dễ hiểu:

Tóm tắt quá trình: Người sử dụng scroll nội dung xuống 1 khoảng (pull) -> thả tay (release) -> dữ liệu được load mới (refesh).

OK lần 2.

Trong bài viết này tôi chỉ hướng dẫn implement nó trên android.

Để có thể implement thư viện này ta cần download thư viện tại đây:

Do thư viện có sử dụng action của SharkBar nên ta phải down thêm thư viện kèm thêm ở đây:

Thông tin về library: (github)

Thành phần:

Cách sử dụng:

Chức năng:

Lỗi của library: ….

Cách khắc phục:

Sẽ viết khi có đủ thời gian :”>

<long pause at here>

 
Leave a comment

Posted by on 10/29/2013 in Android, Java

 

Tags: , , , ,

No enclosing instance of type Class is accessible

Sáng nay ngồi code chơi gặp tình huống thế này.

public class A {
    public class B{
        private int num;
        public Date() {
            num = 0;
        }
    }

    public static void main(String[] args) {
        B b = new B();
    }
}

Read the rest of this entry »

 
Leave a comment

Posted by on 06/12/2013 in Java

 

Tags: , , , , , , , ,

Đừng định dạng comment trong clipse

Sử dụng /*- để eclipse bỏ qua

/*-
* không có
*           gom dòng hay định dạng
* @author longrainbow
*
*/

hoặc

// @formatter:off
/*
* không có
*           gom dòng hay định dạng
* @author longrainbow
*/

hoặc:

Java Formatter (Windows > Preferences > Java > Code Style > Formatter)
 
Leave a comment

Posted by on 06/10/2013 in Java

 

Tags: , , , , , , , , , , ,

Lập trình viên Java cần biết

Lập trình viên Java cần biết

Kể từ khi JAVA được công bố chính thức từ năm 1995, nó đã thay đổi rất nhiều cái nhìn của chúng ta về Hệ Điều hành. Bill Gate đã từng nói đùa rằng, nó – Hệ Điều hành – không phải là phần cứng mà là phần mềm, là tương lai. (It was not about the hardware but the software which will be the future). Một thập kỷ sau, John Gage (thành viên thứ năm của SUN) đã nói, “Mạng là máy tính” (The Network is the Computer). Và điều này đã nhanh chóng được chứng minh trong thế kỷ 21 này. Tuy nhiên, JAVA đã được xây dựng không phụ thuộc vào Hệ Điều hành và được triển khai qua mạng. JAVA với công nghệ Applet đã khai sinh cho những Ứng dụng Mạng Giàu Tương tác (Rich Network Application hay còn gọi là Rich Internet Application – RIA). JAVA không hoàn hảo và chúng ta liên tục có những bản phát hành khác nhau, tuy nhiên JAVA đã khai sinh một ngôn ngữ lập trình cực kỳ phổ biến.

Trở lại với nội dung bài viết, tác giả Armel Nene (Senior Java developer với kinh nghiệm làm việc trong lĩnh vực tài chính như Barclays, SMBC và công nghiệp game) muốn nhấn mạnh vào những gì mà mọi lập trình viên Java nên biết dù kinh nghiệm của họ có tới đâu đi chăng nữa và cũng không tin rằng một người với kinh nghiệm 5 năm thì không thể bằng một người có kinh nghiệm 10 năm. Mỗi người đều có một phương pháp làm việc tuy nhiên với một người lập trình viên, bạn luôn luôn phải đồng hành cùng công nghệ. Sau đây là 10 điều mà tác giả nghĩ là quan trọng hàng đầu đối với lập trình viên Java.

Read the rest of this entry »

 
Leave a comment

Posted by on 04/04/2013 in Java

 

Hibernate Quick Guide

Hibernate is an Object-Relational Mapping(ORM) solution for JAVA and it raised as an open source persistent framework created by Gavin King in 2001. It is a powerful, high performance Object-Relational Persistence and Query service for any Java Application.

Hibernate maps Java classes to database tables and from Java data types to SQL data types and relieve the developer from 95% of common data persistence related programming tasks.

Hibernate sits between traditional Java objects and database server to handle all the work in persisting those objects based on the appropriate O/R mechanisms and patterns.

Hibernate Position

Read the rest of this entry »

 
Leave a comment

Posted by on 02/23/2013 in Hibernate framework

 

Tags: