顯示具有 Java 標籤的文章。 顯示所有文章
顯示具有 Java 標籤的文章。 顯示所有文章

2017年3月21日

Unable to execute dex: GC overhead limit exceeded in Eclipse

Export專案時,發生上述的錯誤,原來是Eclipse的在Eclipse.ini中的Xms和Xmx值設定太小,將其設成 512 和 1024 即可。
-Xms512m 
-Xmx1024m

2014年12月28日

Android: JNI相關

Java调用C程序, C调用Java程序
JNI Tips
Android 開發筆記 - 使用 NDK / JNI 實作從底層呼叫上層 (C call Java)
Java Programming Tutorial Java Native Interface (JNI)
http://blog.csdn.net/i5suoi/article/details/19036975
探秘腾讯Android手机游戏平台之不安装游戏APK直接启动法
Android应用开发提高系列(4)——Android动态加载(上)——加载未安装APK中的类

2014年7月5日

Android: 解壓縮有密碼的zip檔(Zip4J)

Zip4j 
參考此jar,簡單用法如下:
public static void unzip(File zipFile, String dest, String passwd) throws ZipException {
        ZipFile zFile = new ZipFile(zipFile); 
        File destDir = new File(dest);   
        if (destDir.isDirectory() && !destDir.exists()) {   
            destDir.mkdir();   
        }   
        if (zFile.isEncrypted()) {   
            zFile.setPassword(passwd.toCharArray());   
        }   
        zFile.extractAll(dest);     
    }   

2014年7月3日

Android: Nano Sleep

來源CALL GLOP()

private static final long SLEEP_PRECISION=2*1000000 ;
private static final long SPIN_YIELD_PRECISION= 1000;

    public static void sleepNanos (long nanoDuration) throws InterruptedException {
        final long end = System.nanoTime() + nanoDuration;
        long timeLeft = nanoDuration;
        do {
            if (timeLeft > SLEEP_PRECISION)
                Thread.sleep (1);
            else
                if (timeLeft > SPIN_YIELD_PRECISION)
                    Thread.sleep(0);

            timeLeft = end - System.nanoTime();
            if (Thread.interrupted())
                throw new InterruptedException ();
        } while (timeLeft > 0);
    }

2012年6月22日

JavaScript: 簡單利用Chrome Javascript debugger

Google Chrome內建的Javascript控制台,就可以作Javascript程式的偵錯。
載入所要Debug的網頁,選擇工具->Javascript控制台

2012年6月13日

Java: 判斷字串是否為空?

簡單的空字串判斷,因為資料輸入人員的不同,導致有不同的空白格式,真是傷腦筋。
String tt = target.replace((char)12288,' ');//將全形空白換成半形空白
tt = tt.replace((char)65279,' ');//ZERO WIDTH NO-BREAK SPACE 沒有寬度的空格
if (tt.trim().equals("")){ //是空字串?
 // 空字串
 ...
}

2012年5月23日

音樂程式設計 JFugue on Processing @ DKBLOG :: 痞客邦 PIXNET ::

音樂程式設計 JFugue on Processing @ DKBLOG :: 痞客邦 PIXNET :::

'via Blog this'

2012年1月12日

在Java中實作HotSwap的功能 - JAVA SE - JavaWorld@TW

在java中實作HotSwap的功能 - JAVA SE - JavaWorld@TW:

Android: libgdx 跨平台的遊戲開發程式庫

libgdx - Android/desktop game development framework

  • libgdx 跨平台的遊戲開發程式庫,用Java和JNI當需要高效率時。
  • 開發桌上遊戲和Android將沒有差別,將底層OpenGL間的差別封包起來。
  • 應用程式可以完全在桌機測試和開發,只需6行程式碼就可以在Android上執行。
  • 在桌機環境中開發,可以用如HotSwap的工具節省開發時程

2011年12月14日

Java: 刪除整個目錄(子目錄和檔案)

public boolean deleteDir(File dir) {
   if (dir.isDirectory()) {
       File[] files = dir.listFiles();
       for (int i=0;i<files.length;i++) { 
            if (!deleteDir(files[i]))
               return false;
       }
   }
   //目錄現在清空了可以刪除
   return dir.delete();
}

2011年10月13日

Java: 文數字排序

出自 Kushal's Java Blog | Software Engineering Blog » Blog » Alphanumeric String Sorting In Java (Implementation):

用Java的基本字串排序,來排序底下字串,
名詞11 名詞1 名詞3 名詞10 名詞2 
變成
名詞1 名詞10 名詞11 名詞2 名詞3


用上面的Alphanumeric String Sorting可以得到我們想要的
名詞1 名詞2 名詞3 名詞10 名詞11 


2011年10月12日

Java: Split分割字串

看起來很簡單又好用的函數,竟讓我冒了一身冷汗,花了一會兒才知道自己錯在哪裡?
第一次用"@"切字串,矇到了ok。
第二次用"^"切字串,出不來;嚇了一跳。
第三次用"$"切字串,還是出不來;差點昏倒 :-(
連忙Google看是怎麼回事?
原來其分隔參數是Regular Expression正則表示式,所以底下那些符號都必須用 \ 避開。
剛好 \ 也在其中所以必須用兩個 \\
例如用"^"切字串,必須寫成 TestString.split("\\^");
^ $ * + ? { }.[ ] ( ) \ | \d \D \w \W \s \S

2011年9月5日

轉錄:如何把InputStream變成字串?

(出處: www.kodejava.org)
Learn Java by Examples - How do I convert InputStream to String?:

public String convertStream2String(InputStream is) throws IOException{
 if (is != null) {
   Writer writer = new StringWriter();
   char[] buffer = new char[1024];
   try {
     Reader rr=new BufferedReader(new InputStreamReader(is,"UTF-8"));
     int n;
     while ((n = rr.read(buffer)) != -1) 
             writer.write(buffer, 0, n);
   }finally {
     is.close();
   }
   return writer.toString();
 }else 
  return "";
}

2011年8月25日

Java : ==

== 運算在Java中被用來比較左右兩個名稱,是否指向同一物件,例如:
String a = new String("abcd");
String b = new String("abcd");
此時if (a==b)為false,因為a與b是分別指向不同的字串物件,

當要比較兩個字串內容是否相同,要用equals(),
例如:

String a = new String("abcd");
String b = new String("abcd");


此時 if (a.equals(b)) 為true