HTML/JavaScript小工具

HTML/JavaScript小工具

2013年4月29日 星期一

java Autoboxing 小迷題!!


public class Test1 {
static int i;
static Integer j;
public static void main(String[] args){

System.out.print("Howard i:"+i);
System.out.print("Howard j:"+j);
}
}
以上程式碼會產生什麼ㄌㄟ????????

想一下喔~!!!~~~原理跟答在分隔線下
1 可以編譯嗎?
2 可以執行嗎?
3 可以執行會出現什麼錯誤ㄌㄟ?









































答:
可編譯但執行時會出現
Exception in thread "main" java.lang.NullPointerException
at Test1.main(Test1.java:22)

原因如下:
當以上程式碼在編譯成class後
程式碼會轉變成如下
public class Test1
{
static int i = 0;
static Integer j = null;


    public static void main(String args[])
    {

    i = j.intValue();//這會出現NullPointerException


System.out.print("Howard i:"+i);
System.out.print("Howard j:"+j);

}
    


}




2013年4月25日 星期四

改變App顯示方向在UIScrollView重點

當設定了shouldAutorotateToInterfaceOrientation
之後app就可以改變方向啦!!
這時如果你有ScrollView 又作了paging
記得要改變ScrollView的contentOffset
變更順序為!

1 先修改主ScrollView的contentSize
2 在改變uiScrollView內容的長寬
3 最後調整主ScrollView 的contentOffset

還有一點如果主ScrollView有overwrite

scrollViewDidScroll
1 當轉換方向時會呼叫!~
2 當你設定主ScrollView的contentOffset時也會呼叫
以上要小心如果有程式寫在scrollViewDidScroll不該被呼叫他會一直被叫阿叫!!
程式就會頭很大


在UIScrollIView中預設會放2個UIImageView!!


    UIImageView* _verticalScrollIndicator;
    UIImageView* _horizontalScrollIndicator;
在UIScrollIView中預設會放2個UIImageView!!
小心阿阿~~~作paging時抓到不該抓的東西!!!

2013年4月15日 星期一

ios 6.1 UIAlertView會閃阿閃

要將show的那一段放在main thread

dispatch_async(dispatch_get_main_queue(), ^{ [alterView show]; });

4.0轉螢幕不到onCreate


android:configChanges="orientation|keyboardHidden|screenSize"

4.0開始~~轉螢幕不想跑到onCreate請服用以上宣告到<activity>中

2013年4月4日 星期四

在AndEange中使用Gesturer 記得在onCreateEngineOptions中宣告好!!


public EngineOptions onCreateEngineOptions() {
// TODO Auto-generated method stub
myGestureDetector = new GestureDetector(this.getBaseContext(),new TestGesture());
final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED
new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
}

2013年4月3日 星期三

AndEange--建立圖資約略步驟

1 建立BitmapTextureAtlas
2 建立某種Region
3 呼叫BitmapTextureAtlas load 圖片

AndEnage--Texture


  1. BitmapTextureAtlas or BuildableBitmapTextureAtlas-->讀靜態圖片
  2. TiledTextureRegion-->動畫圖片(連續)
    Compressed textures 壓縮圖片 


2013年4月1日 星期一

當你做Fragmnet 出現 The specified child already...時候


04-01 18:46:03.279: E/AndroidRuntime(3077): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testtab2/com.example.testtab2.MainActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.



以上錯誤可能因為
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
return inflater.inflate(R.layout.test_tab1, container,false);

}
inflater.inflate(R.layout.test_tab1, container,false);你的false沒有設定!!