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
    • 鎖定使用中的物件。