2013年12月8日 星期日

[Android] The library 'xxxx.jar' contains native libraries that will not run on the device.

Error

[2013-11-22 15:34:58 - group] Installation failed due to invalid APK file!
[2013-11-22 15:34:58 - group] Please check logcat output for more details.
[2013-11-22 15:34:58 - group] Launch canceled!
[2013-11-22 16:02:45 - group] The library 'xxxx.jar' contains native libraries that will not run on the device.
[2013-11-22 16:02:45 - group] The following libraries were found:
[2013-11-22 16:02:45 - group] - assets/xxxx.so


Solution

jar library 中不能包含 .so 檔

可放入 project assets/


* Reference
http://www.v-key.com/solutions/v-guard/
http://www.cnblogs.com/mengshu-lbq/archive/2011/11/19/2255566.html

2013年9月19日 星期四

[Android] Zygote, Dalvik and JVM

Android 系統開啟時 由 init.rc 來啟動外部程式

其中 Zygote 是 Android 的 monitor process,負責:
1. Listening Socket (Forking child process, 執行 Android 應用程式)
2. Preload Resource
3. Preload Class
4. Start System Server
5. Enter Zygote Fork Mode

「System Server」是由 Zygote 所建立的另外一個 process
  • 建立的方式是使用典型的 Linux system call - fork()
  • 當 Zygote 成功建立 system server 後,便進入 socket listening 模式。在此模式下,zygote 會監聽(listen)由 socket 所傳入的「命令」,並依據命令的內容啟動 Android 應用程式

「Zygote Mode」: 在 socket 做 listening,並依據命令來 fork() 並執行外部 Android 應用程式。


Dalvik VM Class preloading 
  • 與 JVM 最大的不同是,Dalvik VM 透過 Zygote 進行「Class Preloading」,是 Dalvik VM 最重要的特色之一。
  • 意思是,把絕大部份的「Java class file」載入記憶體。
  • Java class file 被打包成 *.jar 檔,Java class file 就是 Java library,提供 Android 應用程式與框架所需的 API。
  • 所載入的 class file,幾乎包含所有的 API,當然,大部份自已都用不到,因此稱之為「preload」,也就是「預載」。
  • 透過 preload,讓 Android 應用程式在載入時,不需要重覆「class loading」的動作,除了加快應用程式啟動速度外,也達到許多效果。
  • 在 Android 裝置開機時進行,可能產生的不良效應之一就是「開機變慢」,不過,已經有一些方法可以解決這個問題。


* Reference
- Jollen 的 Android 觀念解析, #1: Zygote Mode
- Dalvik VM 與 JVM 差異比較:Zygote 與 Class Preload

marshalling/unmarshalling

傳遞變數的過程。

在不同機器間通過網路傳遞變數(包括Java基本類型和物件),如果目的機器表示資料的方式和原機器不同(ex: 二進位庫),就必須轉譯變數(ex: 序列化),marshalling/unmarshalling 就是傳遞變數的過程。



* Reference
- Java RMI-IIOP - ulinaboy 的部落格 - udn部落格

2013年9月18日 星期三

[Struts2] Interceptor

struts2 重點在於加入 MVC
所以 interceptor 是和 struts1 很大的不同處


struts2 中有預設的 interceptor
package struts-default
name defaultStack

當我們的 package extends struts-default 就繼承了 struts-default 中的所有設定!


ActionInvocation: 包裝所有與 Action 執行有關資訊的物件
在開發 interceptor 時,我們並不會直接的與 ActionInvocation 物件互動,而是間接的與 ActionInvocation 有關係!
當我們的 framework 接收到一個使用者的 request 時,Struts2 framework 會根據使用者呼叫的 URL 來 mapping 所對應的 Action,並將此 Action 的相關資訊加入到 ActionInvocation 物件中,接著 Struts2 framework 就會搜尋所有 configuration file 中的所有 interceptors 並且加到 ActionInvocation 中,幫助 ActionInvocation 走訪所有的 interceptors。



    
    
        
    
     .......

    
    
        
    

    
    
        
            dojo\..*        
    
      ..........     





    
    
    /WEB-INF/pages/finish.jsp



* Reference
- [Struts2] Introduce Interceptor
- [Struts2] 宣告與設定 Interceptors
- [Struts2] 深入探討 Interceptor

2013年9月3日 星期二

[JPA] Note

<tx:jta-transaction-manager>
觸發系統去找 JTA Transaction Manager


singulatAttribute 
A extends B, if B 中的屬性不是基本型別 在 A 中無法識別 所以 singulatAttribute 要寫在 A 中 寫在 B 中無效

embedded object 必須宣告在 child's metamodel


namedQuery
server 開啟後便會執行 像是函數 只要有參數就能直接執行
不能做子查詢
不能使用 like


entityManager.detach(Object);
和 Object 脫鉤


construct
建立物件時 只取出其中某些欄位
criteriaQuery.select(builder.construct(
    User.class,
     root.get(User_.name)
))


boolean attribute 
預設是 insert 0/1
加上 @Type(type = "yes_no") 則 insert Y/N


A join B
In A, if joinColumn is not primary key JPA not allowed lazy fetch.


@filterDef
filter join 後的結果

2013年9月2日 星期一

[Java] Not a Number (NaN)

NaN - Not a Number 表示非定義的數字

ex:
0.0 / 0 (被 0 除的結果)
0.0 / 0.0

不論是和數字或是和 NaN 都不能用關係運算子做比較(<, <=, >, and >=)

Double.isNaN()/Float.isNaN()


* Reference

[SQL] ORA-00937:非單組分組函數

Error

ORA-00937:非單組分組函數


Solution

如果 select 了一個分組函數,其它也必須是分組函數,否則就出錯。這是語法規定的

ex:

select min(sal), max(sal) from emp;



* Reference
- 韓順平老師Oracle教程筆記——網摘_StackDoc

[Android] View API

setPivotX(0)
圖上的位置 非螢幕上位置


getLeft
relative parent 從 parent 上算來的位置 (由 parent's top and left 為初始)


[Android] The key must be an application-specific resource id.

Error

E/AndroidRuntime(15393): java.lang.IllegalArgumentException: The key must be an application-specific resource id.


Solution

新增 id resource

使用此 resource 作為 key 以確定為 unique.


[Web] Note

disable
設為 true 欄位值不會被送出




< form:input path= "name" value = "${name}" ${xxx ?  "disabled='disbaled'" : ""}  />




value
沒有 value 不會觸發 setXXX 用 getParameter 會取到 null
value="" 會送空的
value 會送null


url mapping
"/{" + ATTRIBUTE_PACKAGE_NAME + ":.+}"


htmlEscape
true = render(escape?) to html
false = show the text

[JQuery] API


:first 


.prev()      


  
$(selector1).find(selector2);      


$(selector1).filter(selector2);  



$(selector).length 


$(selector).eq(i)  


$("p").insertBefore("#foo") = $("#foo").before("p")   



* Reference
- jQuery基础---filter()和find()
- Difference Between Filter() And Find() In JQuery

[Web] enum form value

Error

<form:radiobutton value="enum type object">

post 時發生 mistypematched exception



Solution

<form:radiobutton value="enum.toString">

因為 enum 會被 toString


http param string <-> enum name


2013年8月25日 星期日

[Android] rating bar size

Error

使用 minHeight and maxHeight 會切掉星星。


Solution

android:scaleX="0.8"
android:scaleY="0.8"

可以縮小 但效果不佳 難以控制位置

最好的方式 直接使用希望呈現的大小圖片



* Reference
- How to set the custom size of the stars in RatingBar
- android ratingbar size

[SQL] Index

in, like 不會使用 index


[Android] tag requires a 'drawable' attribute or child tag defining a drawable

Error Message

想在 selector 中使用顏色做為 drawable

<item> tag requires a 'drawable' attribute or child tag defining a drawable


Solution

要放在 /res/color/list_item_selector.xml



   
   
   
   





[Android] Could not open Selected VM debug port (8700). Make sure you do not have another instance of DDMS or of the eclipse plugin running....

Error Message

Could not open Selected VM debug port (8700). Make sure you do not have another instance of DDMS or of the eclipse plugin running. If it's being used by something else, choose a new port number in the preferences.



Solution

Window -> Preferences -> Android -> DDMS

- Set Base local debugger port to "8601"
- Check the box that says "Use ADBHOST" and the value should be "127.0.0.1"


[Android] The connection to adb is down, and a severe error has occured....

Error Message

The connection to adb is down, and a severe error has occured.
You must restart adb and Eclipse.
Please ensure that adb is correctly located at 'D:\sdk\platform-tools\adb.exe' and can be executed.


Solution

找到工作管理員中的 adb.exe 執行中的 process
關閉 adb.exe
重啟 eclipse



* Reference
- Android故障排除_The connection to adb is down, and a severe error has occured.
- Android : The Connection To Adb Is Down, And A Severe Error Has Occurred.

[SQL] ORA-00932: 不一致的資料類型: 應該是 -, 但為 CLOB

Error Message

ORA-00932: 不一致的資料類型: 應該是 -, 但為 CLOB



Solution

當 field type is lob

可以寫

... where field like xxxx

但不能寫成

... where field = xxxx




[Android] Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY

Error Message

Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY


Solution

在 local 設定 external build path 使用 library xxxx

並在 AndroidManifest.xml 宣告

<uses-library android:name="xxxx">

使用系統上共用的 library.


[Spring] Neither BindingResult nor plain target object for bean name ''

Error Message

RequestContextAwareTag.java org.sprin
rk.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:86) ERROR - Neither BindingResult nor plain target object fo
ame 'loginForm' available as request attribute
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'loginForm' available as request attribute
at org.springframework.web.servlet.support.BindStatus.(BindStatus.java:141)
............
............
............



Solution

因為沒有指定 jsp form modelAttribute 所對應的物件

ex:

// Controller
public String login(Map model) {
model.put("login", new new LoginForm());
}


// JSP
<form:form method="POST" modelattribute="login">


* Reference
- Neither BindingResult nor plain target object for bean name available as request attribute
- Spring MVC – Neither BindingResult Nor Plain Target Object For Bean Name ‘Xxx’ Available As Request Attribute.

[Android] AdapterView


  • after set adapter default select position 0.
  • 若被選的位置和原本的相同 那麼不會觸發 onItemSelected.

  • setSelection(position)
    • position 那個 item 會被移動到 top (not touch mode)
  • getChildAt(index)
    • index: 畫面的位置。
    • 所以如果 index 是在不可視的位置 可能會得到 null。



* Related post:
[ListView] The World of List View
[Android] ListView Tips

2013年6月1日 星期六

[Android] AsyncTask

AsyncTask from API 1.5+
不過事實上 1.0 and 1.1 上也有此功能 只是 API 為 UserTask

Lifecycle
  • activity 結束時 AsyncTask 會繼續執行直到完成,然後呼叫 onCancelled(Result result)或 onPostExecute(Result result),然而因為 activity 已不在,所以 AsyncTask 也無法做接下來的工作。
  • 所以希望能在 activity 結束前先取消 AsyncTask,因此呼叫 cancel(boolean mayInterruptIfRunning),mayInterruptIfRunning 表示是否中斷 執行 thread。


cancel() 不總能正確的發揮效用?!
  • cancel(false): 工作不會被中斷並完整執行完,但執行完後不會呼叫 onPostExecute()
  • cancel(true): 只是會試著盡早中斷我們的工作,若是遇到不可被中斷的工作(ex: BitmapFactory.decodeStream()) 就仍然會執行完。


Memory leaks
AsyncTask 會執有 activity reference。


Serial or parallel?? It depends on the API level.
假設執行下列兩個 task:

new AsyncTask1().execute();
new AsyncTask2().execute();

Before API 1.6 (Donut): Serial
等 task1 執行完才會再執行 task2。
=> performance problems.

API 1.6 to API 2.3 (Gingerbread): Parallel
同時執行在不同的 worker thread。
=> concurrency issues.

API 3.0 (Honeycomb) until now: Serial or parallel
public static void execute(AsyncTask as) {
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB_MR1) {
        as.execute();
    } else {
        as.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}

* Reference - The dark side of AsyncTask

[Android] View Animation attributes

Translate
  • 執行次數: android:repeatCount="2"
    • 會連原本的一次,所以會執行三次。
  • 移動距離
    • 0: 表示目前位置,距離是相對位置,往上/左是 -,往下/右是 +。
    • -100%p: 上/左; 100%p: 下/右。
      • android:fromYDelta="-100%p" 上
      • android:fromXDelta="0" android:toXDelta="-100%p" 往左邊消失
      • android:fromXDelta="-100%p" android:toXDelta="0" 從左邊進
      • android:fromXDelta="0" android:toXDelta="100%p" 往右邊消失
      • android:fromXDelta="100%p" android:toXDelta="0" 從右邊進
  • 没有指定 fromXType toXType fromYType toYType 時候, 默許是以自己為相對参照物。


Scale
  • fromXScale/toXScale/fromYScale/toYScale
    • 動畫開始與结束時的縮放比例。
  • 縮小 < 1.0 (無變化) < 放大。 
  • pivotX/pivotY: 缩放時的中心。
    • 0.5 or 50% 為 X 或 Y 座標上的中點位置。 


Rotate
  • fromDegrees/toDegrees: 動畫開始結束時旋轉的角度。
  • 逆時針 < 0 < 順時針。 
  • (-, +): 順時針旋轉。 
  • (-, -): 逆時針旋轉。 
  • (+, +): 順時針旋轉。 
  • (+, -): 逆時針旋轉。 
  • pivotX/pivotY: 旋轉時的中心。 
    • 數字: 相對於自己左邊的 pixel 位置。
    • num%: 相對於自己左邊或上邊的百分比。 
    • num%p: 相對於 parent 左邊或上邊的百分比。 


* Reference
- View Animation
- 详解Android动画之Tween Animation

2013年5月15日 星期三

TFT-LCD vs. OLED vs. PMOLED vs. AMOLED vs. Super AMOLED

TFT-LCD
  • 在 AMOLED 出現之前,佔最大量比例的螢幕技術。
  • 兩塊玻璃中間夾著液晶,就像計算機或是電子錶的螢幕那樣(非彩色的),LCD本身不發光,我們之所以能看到螢幕成像,是因為螢幕後面還有一層背光模組將光線透過玻璃讓我們看見各種顏色,所以螢幕有兩層
  • LCD 面板加上背光模組再怎麼薄也薄不過本身就會發光的螢幕面板吧! 因此OLED技術就慢慢抬頭。

OLED = 有機發光二極體。
  • 使用黑色畫面能有省電的效果。
  • 因為每個 pixel 都會發光,越亮則需要更多能量

PMOLED = Passive Matrix OLED

AMOLED = Active Matrix OLED
  • 自發光的OLED技術,在原有的 TFT-LCD 技術上加引延伸發展。
  • ex: Google Nexus、Galaxy S2、Galaxy Tab。
  • 缺點:
    • 在大太陽下看不清楚畫面。
    • 螢幕顏色雖然豔麗,但是還原不夠真實,時常在拍照後從手機螢幕上看起來很好看,實際存到電腦後才發現顏色不對。
    • 烙印問題。
      • 由於 AMOLED 每個像素都會自己發光,因此不像 TFT-LCD 那樣一整片背光,即使年久老化後也只會整片光度不如以往;
      • 但是 AMOLED 每個像素都有自身的壽命,如果某塊區域長期顯示高光源,便會老化得比周圍像素快很多,就像燈泡點愈久光度愈暗那樣,造成圖像像是印在螢幕上,也就是烙印的原因。
      • 最常出現烙印的區域是螢幕最上方的通知列,因為這裡的像素使用率較其他區域低,所以很容易產生烙印。
  • 優於 TFT-LCD 的原因:
    • 更優異的視角。
    • 色彩對比。
    • 反應速度。
    • 因為不需背光模組,因此成本更低,也比較省電。
  • 比 PMOLED 適合用在手機或平板裝置上,優點有:
    • 耗電量低
    • 更新時間快
    • 反應速度快


Super AMOLED
  • 比原來的技術更亮(約提昇 18%), 顏色更鮮艷。
  • 將觸控層由原本分離的構造整合進螢幕本身,達到更輕薄的目標。
  • 優點:
    • 耗電量更低,亮度也愈亮。
    • 傳統的三原色 RGB 顯示方式是除了三個原色的互相搭配調出來的各種顏色,還有三原色全開的白色與三原色全關閉時的黑色;
    • 不過 Super AMOLED 使用了新的子像素排列方式,稱為「PenTile」,相比傳統的 RGB 更多了一個白色子像素,因此即使是顯示純白色的畫面都不需將所有顏色全開,只要單純顯示白色就好了。
  • 缺點:
    • PenTile 的排列方式會造成文字周圍有毛邊鋸齒。
    • 畫質下降。
      • PenTile 的每個單獨子像素都可以與鄰近的子像素搭配來產生顏色,不必像傳統 RGB 一定得 3 個子像素同時運作;
      • 如此一來即可最少以 2 種顏色來搭配顯示,達到近似的效果。既然可以用 2 色即可達成顯色目標,那不顯示的子像素當然會對畫質產生影響。


* Reference
- 讓手機畫面更鮮艷的AMOLED螢幕顯示技術 | T客邦 - 我只推薦好東西
- T小編烙行話:AMOLED 怎麼讀?Kepler 又是啥?
- Battery Saver Tips & Tricks - How to extend your Android's battery!

2013年5月14日 星期二

[Android] onSaveInstanceState/onRestoreInstanceState

  • 在離開畫面時 onSaveInstanceState() 會被呼叫並保存下當時畫面狀態於 bundle 中,以預防此畫面被不預期關閉; 這樣要重新開啟時,onRestoreInstanceState() 能藉由保存下來的資料來回到關閉前的狀態。
  • 預設會保留住 setContentView 狀態 (ex: 輸入值)。
  • onSaveInstanceState 一定會發生在 onStop 前 但不一定是在 onPause 前或後。
  • 從 Honeycomb 開始 在收到 onStop 回傳前 都不是 kiiable status 這時 onSaveInstanceState 可能會在 onPause 後才被呼叫。

Activity a to Activity b running orders:
  • Open b in a
    • a: onSaveInstanceState -> onPause -> onStop
  • Change orientation:
    • a: onSaveInstanceState -> onPause -> onStop -> onDestroy -> onCreate -> onStart -> onRestoreInstanceState -> onResume
  • Open b with dialog theme in a:
    • a: onSaveInstanceState -> onPause (因為還能看到 a 所以不會呼叫 onStop()!)


以下狀態下不會呼叫 onRestoreInstanceState
  • 從程式集開啟 app 時。
    • onCreate -> onStart -> onResume
  • 從 Activity b 返回 Activity a。
    • onRestart -> onStart -> onResume


* Reference
- onSaveInstanceState
- onRestoreInstanceState

[Linux] shell

當你要電腦傳輸出來『音樂』的時候,你的電腦需要什麼東西呢?
  • 硬體:當然就是需要你的硬體有『音效卡晶片』這個配備,否則怎麼會有聲音;
  • 核心管理:作業系統的核心可以支援這個晶片組,當然還需要提供晶片的驅動程式囉;
  • 應用程式:需要使用者 (就是你) 輸入發生聲音的指令囉!
步驟:
  1. 你必須要『輸入』一個指令之後,『硬體』才會透過你下達的指令來工作!
  2. 透過『 Shell 』將我們輸入的指令與 Kernel 溝通,kernel 控制硬體工作。

from http://linux.vbird.org/linux_basic/0105computers/os_01.gif

  • 只要能夠操作應用程式的介面都能夠稱為殼程式。
  • 狹義的殼程式指的是指令列方面的軟體,ex: bash 等; 廣義的殼程式則包括圖形介面的軟體。
  • 殼程式可以呼叫其他軟體。
    • ex: man, chmod, chown, vi, fdisk, mkfs 等等指令。
      • 這些指令都是獨立的應用程式,透過殼程式 (就是指令列模式) 來操作這些應用程式,讓這些應用程式呼叫核心來運作所需的工作。
  • shell 可分為多種:
    • 在 Sun 裡頭預設的 C SHell、 商業上常用的 K SHell、 TCSH 等等。
    • 至於 Linux 使用的這一種版本就稱為『 Bourne Again SHell (簡稱 bash) 』。
    • 是 Bourne Shell 的增強版本,也是基準於 GNU 的架構下發展出來的!


* Reference
- 鳥哥的 Linux 私房菜 -- 學習 bash shell

2013年5月12日 星期日

[Graphic] Vector Drawables

Drawable 分為兩類:


Bitmap Drawables
  • Bitmap files, ex:
    • PNG which are rendered as images by the OS.
    • 9-patch bitmaps which enable the OS to anamorphically distort the image to fit a particular region.
Vector Drawables
  • Consist of XML files which contain some basic vector drawing command which the OS renders dynamically at runtime.
  • 缺點:
    • Require more processing power to render,particularly gradients; 
    • The drawing primitives are not as flexible as those in your favorite image manipulation software.


兩種差異是單一的 vector drawable 在不同顯示規格下的縮放表現較好(a single vector drawable will scale much better on a variety of different display types)。


* Reference
- Vector Drawables – part 1

[Android] context for SharedPreferences

  • Does not support use across multiple processes
  • SharedPreferences of specific name is a single instance of this class that all clients share.


Relative post
[Android] Context


* Reference
- SharedPreferences
- getSharedPreferences (String name, int mode)
- android - Application context for SharedPreferences? - Stack Overflow
- android - SharedPreferences application context vs activity context - Stack Overflow

2013年3月26日 星期二

[Android] Directory path for APIs


  • getFilesDir = /data/data/{package name}/files
  • getDatabasePath = /data/data/{package name}/databases/{database name}.db
  • // 私人的檔案,當移除 APP,此路徑下的也都會移除。
  • getExternalFilesDir = /mnt/sdcard/Android/data/{package name}/files/{file}
  • getDownloadCacheDirectory = /cache
  • getDataDirectory = /data
  • // 與應用程式的關聯直接分開的,當移除 APP,此路徑下的也不會被移除。
  • getExternalStorageDirectory = /mnt/sdcard 
  • getExternalStoragePublicDirectory = /mnt/sdcard/pub_test

2013年2月21日 星期四

[Android] Optimised ImageView

在 4.0 前,使用 ImageView.setImageDrawable(),會執行下列動作:
  1. Set the new Drawable (and keep a reference to it).
  2. Request a layout pass.
  3. Invalidate itself to display the new contents.

step 1 and step 3 是必要的
step 2 是定位 drawable 自 ImageView 中的位置,因此只需要在 drawable 大小改變時使用到。

也就是若 AdapterView 中使用的都是大小相同的 drawable,則能省略 step 2,讓滑動的效能獲得改善


在 4.0 中會先比對大小才呼叫 requestLayout()(run the step 2),4.0 後則能使用 reference 中所提供的 OptimisedImageView。


Relative post
- [Android] Avoid Memory leak


* Reference
- Snippet: ImageView Layout Optimisation | senab

2013年1月31日 星期四

[Android] Errors when sign projecct

Failure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES]

重新 sign 前 沒有刪掉以下檔案 安裝時便會發生此錯誤。

\META-INF\CERT.RSA
\META-INF\CERT.SF


jarsigner: unable to open jar file: test.apk

沒有找到 test.apk。


jarsigner: unable to sign jar: java.util.zip.ZipException: invalid entry compressed size (expected 483 but got 480 bytes)

要 sign 的檔案已經 sign 過。

2013年1月26日 星期六

[Android] get system values when reboot

Error Message

若是 livewallpaper app

重開機時 取到的 system values 會是 0 (ex: imei, iccid...)



Solution

若已設定 livewallpaper 然後重開機

在開機中 system 便會呼叫 livewallpaper

此時所取到的 system values 便會是 0

可等接收到 BOOT_COMPLETED action 後 再去取 便能取到正確值

或是判定為 SIM_STATE_READY 才將取到的值視為有效值


飛安模式 -> SIM_STATE_UNKNOWN -> 取不到

關閉網路 -> SIM_STATE_READY -> OK


測試中(HTC One V) 轉換飛安模式和一般模式的行為 會使得物件等被清除

仍不確定是否依手機而異 與影響範圍

2013年1月21日 星期一

[Web] object from request parameters

Error Message

ERROR - [Ljava.lang.String; cannot be cast to java.lang.String
java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.lang.String


Solution

注意使用的物件 type,Map<String, String[]> or Map<String, String>。


Map<String, String[]> requestParameters = request.getParameterMap();
Map<String, String> parameters = new Map<String, String>();
for(String key: requestParameters.keySet())  {
    parameters.put(key, requestParameters.get(key)[0]);
}

[JPA] EntityNotFoundException

Error Message

javax.persistence.EntityNotFoundException: Unable to find ObjectA with id ObjectB.


Solution

join ObjectA 時,對應不到 ObjectA 時會發生該 exception。

Using @NotFound(action = NotFoundAction.IGNORE)

optional="tru|false"
表示該屬性是否允許為 null,預設為 true。


* Reference
- Annotation Type NotFound
- @Basic(fetch=FetchType,optional=true)
- @NotFound(action=NotFoundAction.IGNORE)

[ibatis] removeFirstPrepend


    

  • true/false
    • 是否移除 iterator 全部後的 statement 的結果的第一個 prepend。
  • iterate
    • 移除每次 iterator 中 statement 的第一個 prepend。


* Reference
- ibatis中的dynamic sql特性
- ibatis教程

2013年1月20日 星期日

[ibatis] object type in

Error Message

com.ibatis.sqlmap.client.SqlMapException: ParameterObject or property was not a Collection, Array or Iterator.

Solution

<iterator property="Object">

property 只能放入 type Collection, Array or Iterator.


[Android] Service notices

  • Service 會被開啟在和 caller 同個 process 中,並且執行在 main thread 中,所以若是要在 service 中執行耗時動作時,必須執行在 background thread 中。
  • 如果想讓 service 執行在另一個 process 中,則可在 AndroidManifest 中宣告 android:process=":process_description"
    • 此 service 有自己的分配空間。
    • a garbage collection, will not affect the user interface of your Activity。
    • 其中的 ":" 是表示此 service 為我們 application 私有的,若是沒有宣告,則表示是全域的而其他人也能存在到。
    • 當 service 執行在另外的 process,則需透過 interprocess communication (IPC) 與其溝通。


Binding to local service
  • If the Service is started in the same process as the Activity
    • The Activity can directly bind to the service a call of the bindService() method. This method has the ServiceConnection parameter.
    • The onServiceConnected() method is called on this object once the Service is available.
    • The Service return on its onBind() method an object of type IBinder which can be used to call to the service.



android.intent.action.BOOT_COMPLETED
  • 若 application 被安裝在 SD card 則接收不到 android.intent.action.BOOT_COMPLETED,因此必須再 register android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE。 (?)
    • If you application is installed on the SD card, then it is not available after the android.intent.action.BOOT_COMPLETED event. Register yourself in this case for the android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE event.
  • 在 Android 3.0,則是至少 user 開啟過 application 一次, application 才能接收到 android.intent.action.BOOT_COMPLETED。



* Reference
- Android Service Tutorial

2013年1月19日 星期六

[Android] Process has died

Error Message

12-28 11:25:03.191: I/ActivityManager(1614): Process com.package.name (pid 17766) has died.



Testing

  • Register BroadcastReceiver in ServiceA will not active when process is died but except register in manifest.
  • If create ServiceA in another process(android:process) and BroadcastReceiver will be create in this process, too.
    • So that even though process of activity that creates service is died service will not died immediately.


2013年1月6日 星期日

[Javascript] iframe(child) and its parent

//--- parent to child

// get child's object
$('#childId').contents().find('childObjectSelector')


//--- child to parent

// call the method defined in parent.
parent.methodInParent();

// get parent's object
$('parentObjectSelector', window.parent.document);


[SQL] 分頁 performance


select * from(
  select x.*, rownum r from(
    ...
  )x
)y where y.r >= 1 and y.r <= 10


select * from (
  select row_.*, rownum rownum_ from (
    ...
  ) row_ where rownum <= 10
) where rownum_ > 0

寫法二會比寫法一快很多

而 JPA 的 Query setFirstResult(), setMaxResults() 生成的分頁 SQL 就會是寫法二

但 rownum <= 的值越大,查詢時間會越久

所以翻頁翻到越後面 頁面顯示的速度會越慢

[JPA] Unable to find column with logical name COLUMNNAME in table TABLENAME

Error Message
Unable to find column with logical name COLUMNNAME in table TABLENAME


Solution
若 A join B,則 B 必須被宣告在 A 之前。


<persistence-unit>
    <class>B</class>
    <class>A</class>
</persistence-unit>




[Java] violate and synchronized


  • violate:
    • 確保使用到的是正確值。
  • synchronized
    • 鎖定使用中的物件。