使用eclipse的nodejs的插件,右鍵運行app.js,控制臺一閃而過,沒有啟動起來.
通過搜索,發現原來是JDK版本的問題,我用的是JDK6,不好使,使用JDK7就好使了.
如果有多個JDK版本共存,可以使用在eclipse安裝目錄下的文件eclipse.ini指定要使用的JDK:
-vm
C:/Program Files/Java/jdk1.7.0_55/bin/javaw.exe
很多人在安裝完Eclipse之后什么都不設置,直接用默認的設置,默認的設置有很多問題。
在項目管理中應該統一Eclipse的設置。
通過菜單Window->Preferences打開設置窗口。
其他如果有Editor的地方,縮進也都要改成4個空格. 比如: Web節點下面的CSS Files, HTML Files.
使用這個東西的好處是,可以發布到多個Blog上,免得使用Web編輯器苦逼地編輯.
下載地址: http://windows.microsoft.com/zh-cn/windows-live/essentials-other#essentials=overviewother
* 使用Live Writer在oschina上寫Blog: http://my.oschina.net/javayou/blog/39107
* 使用Live Writer在BlogJava上鞋Blog: http://www.aygfsteel.com/vulcan/archive/2010/11/05/337323.html
注意: - 在日志類型中選擇Metaweblog API
- API連接為: http://www.aygfsteel.com/你的blog名稱/services/metaweblog.aspx
更新了最新Android ADT工具后,出現 TypeError: argument of type 'NoneType' is not iterable.
解決:
復制 build-tool/17.0.0/ 下所有內容到 platform-tools 目錄下.
參考:
有時候Titanium中的終端會顯示:
This Terminal Emulator is not functional because no 'bash' shell could be found. Please correct the problem and restart the IDE.
解決辦法:
然后重啟終端就好了.
在WebView控件中,如果頁面中調用了javascript腳本console.log 方法,就調用一個Java方法.
在Android的WebView控件中,有一個setChromeClient(WebChromeClient)方法,
此方法的參數是WebChromeClient對象,通過重載此對象中的onConsoleMessage方法就
可以達到此目的.看代碼:
WebView webView = new WebView(); webView.setWebChromeClient(new DefaultWebChromeClient); // 以上代碼放在在Activity或則Fragment中的onCreate方法中 private class DefualtWebChromeClient extends WebChromeClient { @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { String message = consoleMessage.message(); int lineNumber = consoleMessage.lineNumber(); String sourceID = consoleMessage.sourceId(); String messageLevel = consoleMessage.message(); Log.i("[WebView]", String.format("[%s] sourceID: %s lineNumber: %n message: %s", messageLevel, sourceID, lineNumber, message)); return super.onConsoleMessage(consoleMessage); } @Override public void onConsoleMessage(String message, int lineNumber, String sourceID) { Log.i("[WebView]", String.format("sourceID: %s lineNumber: %n message: %s", sourceID, lineNumber, message)); super.onConsoleMessage(message, lineNumber, sourceID); } }
第一個方法onConsoleMessage(ConsoleMessage consoleMessage)是新版本的android才有的方法,第二個方法是舊版本的.
第二個方法已經不推薦使用了,但是在舊版本的android中,仍然需要此方法.所以最好兩個方法都實現.
默認的實現在某些版本的手機中不好使,onConsoleMessage方法死活不被調用
使用WebView的addJavascriptInterface方法:
// 首先,定一個類,叫什么名稱都可以,但是里面的方法名必須與 // Javascript的console中的方法名對應 private class Console{ private static final String TAG="[WebView]"; public void log(String msg){ Log.i(TAG,msg); } // 還可以添加其他的方法,比如: warn,assert等等 } // 然后,為WebView添加對應的接口 webView.addJavascriptInterface(new Console, "console");
這個解決方案有一個不好的地方,就是輸出的內容沒有onConsoleMessage方法那么詳細,比如行號,就沒法輸出.
所以,我們應該在onConsoleMessage好使的時候使用onConsoleMessage,不好使的時候在使用我們自定義的方式.
那么,如何來判斷onConsoleMessage是否好使呢? 我們可以在程序初始化的時候,先在WebView中運行一下console.log,
如果onConsoleMessage運行了,就添加一個標記,表示默認的實現是好使的.
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // 這些代碼也可以放到onCreate方法中 this.webView = (WebView) layout.findViewById(R.id.webview); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); // Set WebChromeClient WebChromeClient webChromeClient = new TestConsoleMessageWebChromeClient(); // 先執行console.log,測試是否調用了onConsoleMessage webView.loadUrl("javascript:console.log('testConsoleMessage')"); if (((TestConsoleMessageWebChromeClient)webChromeClient).isConsoleMessageOK()){ // 這里額外使用了一個新的類 TestConsoleMessageWebChromeClient // 如果不適用TestConsoleMessageWebChromeClient,就需要在 // DefaultWebChromeClient中添加標記字段 consoleMessageOK, // 這樣如果方法onConsoleMessage好使,那么每次都給consoleMessageOK賦值, // 這個有些多余,也影響性能. webChromeClient = new DefualtWebChromeClient(); }else{ // onConsoleMessage不好使,就使用這種方式,第二個參數值必須是"console" webView.addJavascriptInterface(new Console(), "console"); } webView.loadUrl("http://www.baidu.com"); return super.onCreateView(inflater, container, savedInstanceState); } // 當默認的onConsoleMessage不好使的時候使用的類 private class Console { private static final String TAG = "[WebView]"; public void log(String msg) { Log.i(TAG, msg); } // 這里還可以添加其他方法console對象中有的方法,比如 assert } // 默認 private class DefualtWebChromeClient extends WebChromeClient { @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { String message = consoleMessage.message(); int lineNumber = consoleMessage.lineNumber(); String sourceID = consoleMessage.sourceId(); String messageLevel = consoleMessage.message(); Log.i("[WebView]", String.format("[%s] sourceID: %s lineNumber: %n message: %s", messageLevel, sourceID, lineNumber, message)); return super.onConsoleMessage(consoleMessage); } @Override public void onConsoleMessage(String message, int lineNumber, String sourceID) { Log.i("[WebView]", String.format("sourceID: %s lineNumber: %n message: %s", sourceID, lineNumber, message)); super.onConsoleMessage(message, lineNumber, sourceID); } } // 用于測試onConsoleMessage是否調用的類 private class TestConsoleMessageWebChromeClient extends WebChromeClient { private boolean consoleMessageOK = false; @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { this.consoleMessageOK = true; return super.onConsoleMessage(consoleMessage); } @Override public void onConsoleMessage(String message, int lineNumber, String sourceID) { this.consoleMessageOK = true; super.onConsoleMessage(message, lineNumber, sourceID); } public boolean isConsoleMessageOK() { return this.consoleMessageOK; } }
1: // 方式一,這種方式多用了一個括號,看著別扭
2: (function(param) {
3: alert(param);
4: })(10);
5:
6: // 方式二,使用 ! 操作符
7: !function(param) {
8: alert(param);
9: }(10);
使用匿名立即執行函數的好處是,可以避免變量沖突.
1: //========================= 條件判斷
2: var sabiable = true;
3: //普通方式
4: if (sabiable) {
5: alert('You are sability!');
6: }
7:
8: //詭異方式,利用 ||和 && 操作符
9: // a||b : 只有在a為fasle或者返回false時才會執行b,當a為true時,直接返回a,后面的b不會執行
10: // a&&b : 只有在a為true或者返回true時才會執行b,當a為時,直接返回a,后面的b不會執行
11:
12: // 上面的代碼可以改為:
13: sabiable && alert('You are sability!');
問題: 以下代碼,tab1的click事件在Android中生效,在iOS不生效
1: function ApplicationTabGroup(Window) {
2: //create module instance
3: var self = Ti.UI.createTabGroup();
4:
5: //create app tabs
6: var win1 = new Window(L('home')), win2 = new Window(L('settings'));
7:
8: var tab1 = Ti.UI.createTab({
9: title : L('home'),
10: icon : '/images/KS_nav_ui.png',
11: window : win1
12: });
13: win1.containingTab = tab1;
14:
15: var tab2 = Ti.UI.createTab({
16: title : L('settings'),
17: icon : '/images/KS_nav_views.png',
18: window : win2
19: });
20: win2.containingTab = tab2;
21:
22: self.addTab(tab1);
23: self.addTab(tab2);
24:
25: tab1.addEventListener('click',function(){
26: //這個事件在iOS中不會被觸發
27: });
28:
29: return self;
30: };
31:
32: module.exports = ApplicationTabGroup;
解決方案:
通過看Titanium附帶的示例程序 Kitcken Sink , 找到了解決方案.
為TabGroup添加focus事件,然后對事件參數進行判斷,來確定當前被點擊的是那個tab.
1: function ApplicationTabGroup(Window) {
2: //create module instance
3: var self = Ti.UI.createTabGroup();
4:
5: //create app tabs
6: var win1 = new Window(L('home')), win2 = new Window(L('settings'));
7:
8: var tab1 = Ti.UI.createTab({
9: title : L('home'),
10: icon : '/images/KS_nav_ui.png',
11: window : win1
12: });
13: win1.containingTab = tab1;
14:
15: var tab2 = Ti.UI.createTab({
16: title : L('settings'),
17: icon : '/images/KS_nav_views.png',
18: window : win2
19: });
20: win2.containingTab = tab2;
21:
22: self.addTab(tab1);
23: self.addTab(tab2);
24:
25: self.addEventListener('focus', function(e) {
26:
27: var info = Titanium.API.info;
28:
29: // 在iOS中, e.source 是 TabGroup對象,
30: // 在Android中,e.source 是 Tab對象
31: var src = e.source;
32: var tab = e.tab;
33: var preTab = e.previousIndex;
34:
35: // e.tab 是當前獲得焦點的tab
36: // e.index 當前獲得焦點的tab的索引,首次為-1
37: // e.previousTab 上個tab
38: // e.previousIndex 上個tab的索引,首次為null
39:
40: // On iOS, the "More..." tab is actually a tab container, not a tab. When it is clicked, e.tab is undefined.
41: if (!tab) {
42: info('在iOS中點擊了"More..."');
43: return;
44: }
45:
46: // 首次
47: if (!preTab) {
48: info('首次進入');
49: return;
50: }
51:
52: if (tab === tab1) {
53: info('點擊了tab1');
54: } else if (tab === tab2) {
55: info('點擊了tab2');
56: }
57: });
58:
59: return self;
60: };
61:
62: module.exports = ApplicationTabGroup;
以下的插件都可以使用Eclipse Marketplace進行查找,安裝.
一安裝插件eclipse就提示
?? Properties Search for Eclipse 3.1.x (2.0.0) requires plug-in "org.eclipse.search (3.1.0)", or equivalent.
靠,搞得我什么插件都安裝不了 :(
??
| |||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
---|---|---|---|---|---|---|---|---|---|
27 | 28 | 29 | 30 | 1 | 2 | 3 | |||
4 | 5 | 6 | 7 | 8 | 9 | 10 | |||
11 | 12 | 13 | 14 | 15 | 16 | 17 | |||
18 | 19 | 20 | 21 | 22 | 23 | 24 | |||
25 | 26 | 27 | 28 | 29 | 30 | 31 | |||
1 | 2 | 3 | 4 | 5 | 6 | 7 |