多了寄託,多了方向,長年來的空缺開始注入活水,即便那只是道娟娟細流,即使這一切極大可能只是虛幻;即便我知道那其實是這一路上所遇過的人的幫助與體諒,以及我每次都敗得非常難看,但卻總是屢敗屢戰所開闢出來的渠道,心中仍是感謝。好一陣子沒有這麼輕鬆的感覺了,雖然日後我可能沒辦法從這字裡行間確切體會出我現在的心靈狀態;但我認為,我能藉由記錄強化我當下的感受,就活在當下吧!
這種感覺是眉目俱笑、是怡然自得、是悠然自得不患得患失(好啦!偶而還是會有),是開心卻不是狂喜、是掛念卻不是踮念、有份量卻如清風一般不留痕跡,渴望坦承也贊成神祕。我真的很享受這種感覺,如果你們發現了什麼,能不能當做不知道,給我點空間呢?
其實在我第一次意會到的時候,我是很排斥的;我很怕會因為這樣而分心,甚至產生牽掛使得我未來的路出了差錯,我不想要有任何變數發生,我放不開。只是,我突然發覺到這種想法真的很幼稚,誰說念書和交朋友一定是會互相排斥的呢?就算會,現在說這也太找了吧!我在擔心什麼阿?這種想太多的心態才是真的會讓我兩者皆空停滯不前的毒瘤,我應該要放輕鬆、讓一切順其自然發展就好,不管會有怎樣的結局,不要讓自己後悔就好。
只願接下來的日子裡,一切隨緣、正常、自在。
大道不移,兩不捨。
Imps are always mischievous, uncontrollable, only obedient to somebody special, and not as powerful as the real demons, yet.
小惡魔:調皮難控制的猴小孩,還在努力成為真正的大惡魔中。
As the title suggests, this is my everything notebook, may in traditional Chinese or English.
這裡什麼都寫,不管是食譜、遊記、練習寫作的爛文,抑或是個人的一些狗屁倒灶的東西都有可能出現,使用語言也是隨性。
*Sometimes, those bilingual articles are not formed by translation, I will represent the concepts twice using different ways of thinking based on the language I use.
Thursday, June 26, 2014
Tuesday, June 24, 2014
[Android] Error inflating class fragment
We have a project that will contain several fragments in one activity, we compile and deploy it to a device without any error message. However, runtime exception occurs when we launch the App, even though we just declare a fragment and not use it yet.
At the first glance, I would consider that it is caused by the fragment class. But it is actually caused by the XML syntax while declaring the fragment component in the layout file of my main activity. See the rectangular area
android.view.InflateException: Binary XML file line #25: Error inflating class fragment
What happened?
It is due to the line 27 in the editor, which uses capital characters (even though it is exactly the same with the real java file we are going to use). All I need to do it change them with all lower characters (it is legal to use capital ones in the rear). That is to say, we revise it as
android:name="com.example.soundclassifier2.MusicFragment"
And everything works now!
[Android] Missing AppTheme (styles)
Although I use git to include most of the resources and libraries for deploying my Android project, sometimes I get stuck when importing my own project among different machines, even in the same OS.
There is a typical one:
in your res/values/styles.xml
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.
It is because I did not include a library appcompat_vXXX correctly. The fastest way to include it, though locally (you have to do it once on every machine), is load an suitable appcompat_vXXX project on your machine.
Right click on your project -> Properties -> Android -> (scroll down) Library
Then you will see an item X ../appcompat_vXXX in the window. All we have to do is click the 'Add...' button to select one of them (in my case: appcompat_v7_4), and click 'Apply' and 'OK'.
If there no any appcompat_XXX available, then you have to download them via Android SDK Manager and download 'Android Support Library' first.
You can see more details in
http://developer.android.com/tools/support-library/index.html
There is a typical one:
in your res/values/styles.xml
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.
It is because I did not include a library appcompat_vXXX correctly. The fastest way to include it, though locally (you have to do it once on every machine), is load an suitable appcompat_vXXX project on your machine.
Right click on your project -> Properties -> Android -> (scroll down) Library
Then you will see an item X ../appcompat_vXXX in the window. All we have to do is click the 'Add...' button to select one of them (in my case: appcompat_v7_4), and click 'Apply' and 'OK'.
If there no any appcompat_XXX available, then you have to download them via Android SDK Manager and download 'Android Support Library' first.
You can see more details in
http://developer.android.com/tools/support-library/index.html
Thursday, May 8, 2014
[Android] Run C/C++ codes on Android–Android NDK
Before Start
When we develop Android projects, Java codes can handle most of the cases. However, we may need to run C/C++ codes under some circumstances:- Some of your methods have performance issues.
- Re-use some open-sourced codes written in C/C++.
- The methods written in C/C++ handle CPU-intensive tasks such as signal process, machine learning algorithms, etc.
Again, running C/C++ codes on Android does NOT guarantee performance improvement, it somethings make your application slower. Only transform the methods that are really CPU-intensive.
What is Android NDK
Android NDK stands for Android Native Development Kit. As Java run the codes in the JVM, no matter what the hardware is; however, it does matter to C/C++ codes, which need to be compiled in different ways (implicitly) according to the hardware architecture before we can run it, that is why we call it "native".
How it work
- Install the NDK to compile the C/C++ code to native libraries
https://developer.android.com/tools/sdk/ndk/index.html - Declare an "interface" as a bridge from C/C++ functions to Java methods
- Declare the Java methods in your application, then use it like (most) normal Java methods
Case study
Instead of using a "HelloWorld" for demonstration, I would like to trace a open-source project for your reference, and that is how I learned by the way.Libsvm-androidjni -- LIBSVM for android jni environment
https://github.com/cnbuff410/Libsvm-androidjni
Libsvm is one of the most powerful tools for SVM and widely used in many classification problems in the world, and it is definitely CPU-intensive. To make this tutorial simple, I just introduce the svm-train function here in a bottom up approach (target the C/C++ codes first, then the interface and how to call the Java methods and so on).
Original source code
/jni/src/svm/svm-train.cpp
/jni/src/svm/svm-train.h
The entry in the svm-train.cpp file is
int svmtrain(int argc, char **argv)
that is the function we want to link to Java
Interface C/C++ code
/jni/src/train.cpp
/jni/src/train.h
int train(const char *trainingFile, int kernelType, int cost, float gamma,
int isProb, const char *modelFile)
This function receive some parameters from another interface C/C++ code, and call the svmtrain(int argc, char **argv) in the original source code to do the real work.
Interface C/C++ (2)
/jni/jni/info_kunli_androidlibsvmexample_AndroiLibsvmExampleActivity.cppThis is an unusual C/C++ that really link the native codes (C/C++) to you Android (Java) code
static jint trainClassifier(JNIEnv *env, jobject obj, jstring trainingFileS,
jint kernelType, jint cost, jfloat gamma, jint isProb, jstring modelFileS) {
jboolean isCopy;
const char *trainingFile = env->GetStringUTFChars(trainingFileS, &isCopy);
const char *modelFile = env->GetStringUTFChars(modelFileS, &isCopy);
int v = train(trainingFile, kernelType, cost, gamma, isProb, modelFile);
env->ReleaseStringUTFChars(trainingFileS, trainingFile);
env->ReleaseStringUTFChars(modelFileS, modelFile);
return v;
}
This is the native function that will be compiled and imported to the Android Java codes. It receives the parameters from your other Java codes, and pass them to int train() in the interface C/C++ function mentioned above.
Three rules observed here
- Besides the real parameters, please add JNIEnv *env and jobject obj as the first two parameters
- Add j in front of type identifier; use Array instead of []. For instance, int becomes jint, int[] becomes jintArray
- Use objectArray for any multi-dimensional array. For instance both int[][] and float[][] will become objectArray
- Convert the strings before and after use them.
static JNINativeMethod sMethods[] = {
/* name, signature, funcPtr */
{"trainClassifierNative", "(Ljava/lang/String;IIFILjava/lang/String;)I",
(void*)trainClassifier},
};
Declare the real type of parameters in the native function. That is, the real type that are accepted in the compiled native method in your Java codes depend on this statement.Put the parameters in the () pair, followed by the return value type
Several mappings here
[type in Java]:[identifier here]
int: I
float: F
double: D
String: Ljava/lang/String; (do not forget the semicolon)
float[][]: [[F
int[][]: [[I
For example:
float HelloWord(int i, String s1, String s2, int[][] arrayI) becomes
"(ILjava/lang/String;Ljava/lang/String;[[I)F"
Register this interface and native methods
int register_Signal(JNIEnv *env)
Change the second parameter in static int jniRegisterNativeMethods() with this file's title (without the extension). For example:
int register_library(JNIEnv *env) {
return jniRegisterNativeMethods(env, "info/kunli/AndroidLibsvmExampleActivity",
sMethods, sizeof(sMethods) / sizeof(sMethods[0]));
}
}
Again, you must replace "info/kunli/AndroidLibsvmExampleActivity" to the file name where you register the library.
Link the interface java codes with Java Virtual Machine
onload.cpp
Makefile of the NDK
jni/src/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES += $(JNI_H_INCLUDE)
LOCAL_SRC_FILES := \
jni/onload.cpp \
jni/info_kunli_androidlibsvmexample_AndroidLibsvmExampleActivity.cpp \
src/train.cpp \
src/svm/svm-train.cpp \
src/svm/svm.cpp
LOCAL_NDK_VERSION := 4
LOCAL_SDK_VERSION := 10
LOCAL_MODULE := libsignal
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
Call NDK to compile the cpp files into a native library (*.so)
libsignal is the name of compiled native library here
jni/src/Application.mk
Set up the hardware architecture
Call NDK to compile the library
ndk-build clean
ndk-build
ndk-build
Overview of the native library building process (top-down)
NDK configuration
Android.mk
Application.mk
Linking JVM to native library
onload.cpp
Set up the interface between Java and native codes
info_kunli_androidlibsvmexample_AndroiLibsvmExampleActivity.cpp
Call the native function as Java methods in the Android project
AndroidLibsvmExampleActivity.java
Note:
If you are familiar with libsvm, you probably found that the lasted version when I am writing this post (May/2014) does not fully support the original LIBSVM well. That is why I want (have) to learn how the NDK work so that I can expand it via the interface codes (not the original C/C++ codes).
Saturday, May 3, 2014
Less is more
"Less is more", it is a well known saying, which I have been eager to understand the meaning. Recently, I found that this is a concept with multiple aspects, and I figured out one of them.
I am always a hard-working person, and I have been suffered from enormous stuffs I am working on. In the past, I had spent more and more time on working even than holidays; however, spending more time on working does not always work. In my personal experience, allocating more time for working somehow does not work! Why? It turns out that I would assuming I still have much time to finish the works, resulting the decrease of efficiency.
Fortunately, I have found such a hazard. The solution is: Do not expect extra time (e.g. weekend and night) and have some recreational activities on holidays to strike a balance between work and life. With a tight schedule, I have to finish the tasks within the weekdays and the normal working hours; therefore, both my throughput and happiness increase due to the fact that I have better working efficiency and relax.
"Less is more" means that spending less time on working brings more throughput and pleasure.
I am always a hard-working person, and I have been suffered from enormous stuffs I am working on. In the past, I had spent more and more time on working even than holidays; however, spending more time on working does not always work. In my personal experience, allocating more time for working somehow does not work! Why? It turns out that I would assuming I still have much time to finish the works, resulting the decrease of efficiency.
Fortunately, I have found such a hazard. The solution is: Do not expect extra time (e.g. weekend and night) and have some recreational activities on holidays to strike a balance between work and life. With a tight schedule, I have to finish the tasks within the weekdays and the normal working hours; therefore, both my throughput and happiness increase due to the fact that I have better working efficiency and relax.
"Less is more" means that spending less time on working brings more throughput and pleasure.
Wednesday, April 30, 2014
重回軌道了
總算總算阿~我各項要做的事終於又回到穩定發展的軌道上了。
專業上,開始能夠複習程式開發方面的技能;網球方面開始能放鬆的打球,而不是緊繃的只練某些固定的弱點項目,即使各項技能仍有很大的進步空間;作息也開始慢慢回復到早睡早起的模式了,我記得這幾乎是一年多以前的事情了,哈哈!
最重要的我想就是人際方面了!現在的我,可以在依然真誠待人的心境下,而能保有自我的空間,一步一步在實現「邀請對方進入我的世界,而不是一味的付出」,這樣的相處模式有什麼好處呢?一言難盡。但我想,最大的好處就是不會再患得患失,心境可以常保平靜卻又不致於對世間的感情覺得冷漠,我喜歡這種感覺。
終於又感到在成長了呢! <3
專業上,開始能夠複習程式開發方面的技能;網球方面開始能放鬆的打球,而不是緊繃的只練某些固定的弱點項目,即使各項技能仍有很大的進步空間;作息也開始慢慢回復到早睡早起的模式了,我記得這幾乎是一年多以前的事情了,哈哈!
最重要的我想就是人際方面了!現在的我,可以在依然真誠待人的心境下,而能保有自我的空間,一步一步在實現「邀請對方進入我的世界,而不是一味的付出」,這樣的相處模式有什麼好處呢?一言難盡。但我想,最大的好處就是不會再患得患失,心境可以常保平靜卻又不致於對世間的感情覺得冷漠,我喜歡這種感覺。
終於又感到在成長了呢! <3
Friday, April 11, 2014
放鬆
我好像知道什麼叫做醉成屍體的感覺了。
我的身體跟脾氣的僵硬度基本上我已經放棄去挽救了(sign),不過今天倒是在一陣小沮喪和放鬆下(這啥詭異的順序?),整個肩膀像融化般的化在床上了;身體的疲累是還好,我甚至還是有意識的(所以才能記下這感覺),但卻隱約感受到,原來我不只是騙過身體的疲累,似乎心理上的壓力其實有一部分也被蓋下了,而我以為那是我小時候才會作的事。
幹!我真的越來越不像人類了,從「我身體叫我休息」繼續突變到「我的心理叫我休息,雖然我不是很想」。
好吧!以理智來思考的話,這種現象其實是可以解釋的,第一個可能是我把各種敏感度不知不覺中越調越低了,以致外界引發的負面影響無論大小我都只能感覺到「還好」;第二個就是我只是個很帥的北七,三不五時不知所云而已。
對了,因為我沒當過真的屍體,今天也沒喝酒,這是比喻而已,筆記一下以防以後忘記。
我的身體跟脾氣的僵硬度基本上我已經放棄去挽救了(sign),不過今天倒是在一陣小沮喪和放鬆下(這啥詭異的順序?),整個肩膀像融化般的化在床上了;身體的疲累是還好,我甚至還是有意識的(所以才能記下這感覺),但卻隱約感受到,原來我不只是騙過身體的疲累,似乎心理上的壓力其實有一部分也被蓋下了,而我以為那是我小時候才會作的事。
幹!我真的越來越不像人類了,從「我身體叫我休息」繼續突變到「我的心理叫我休息,雖然我不是很想」。
好吧!以理智來思考的話,這種現象其實是可以解釋的,第一個可能是我把各種敏感度不知不覺中越調越低了,以致外界引發的負面影響無論大小我都只能感覺到「還好」;第二個就是我只是個很帥的北七,三不五時不知所云而已。
對了,因為我沒當過真的屍體,今天也沒喝酒,這是比喻而已,筆記一下以防以後忘記。
Subscribe to:
Posts (Atom)



