使用eclipse的nodejs的插件,右鍵運(yùn)行app.js,控制臺(tái)一閃而過(guò),沒(méi)有啟動(dòng)起來(lái).
通過(guò)搜索,發(fā)現(xiàn)原來(lái)是JDK版本的問(wèn)題,我用的是JDK6,不好使,使用JDK7就好使了.
如果有多個(gè)JDK版本共存,可以使用在eclipse安裝目錄下的文件eclipse.ini指定要使用的JDK:
-vm
C:/Program Files/Java/jdk1.7.0_55/bin/javaw.exe
很多人在安裝完Eclipse之后什么都不設(shè)置,直接用默認(rèn)的設(shè)置,默認(rèn)的設(shè)置有很多問(wèn)題。
在項(xiàng)目管理中應(yīng)該統(tǒng)一Eclipse的設(shè)置。
通過(guò)菜單Window->Preferences打開(kāi)設(shè)置窗口。
- General->Editors->Text Editors:
選上Insert spaces for tabs : 縮進(jìn)使用空格,不使用Tab.原因是當(dāng)把代碼復(fù)制給網(wǎng)絡(luò)上的顯示的時(shí)候,
Tab經(jīng)常會(huì)被刪除,導(dǎo)致格式完全亂套.
選上Show line numbers : 顯示行號(hào),這個(gè)在debug的時(shí)候快速定位非常方便.
選上Show print margin,然后在下面的Print margin column輸入框中輸入120 : 顯示一條豎線,
用于標(biāo)示打印機(jī)打印時(shí)的寬度.這里用于代碼自動(dòng)換行的寬度. 設(shè)置為120個(gè)字符.這個(gè)同樣在Java
代碼格式化的時(shí)候用到,后繼會(huì)說(shuō)到.
![Y3RDP4``Q@][2]JX]3DYVA7[4] Y3RDP4``Q@][2]JX]3DYVA7[4]](http://www.tkk7.com/images/blogjava_net/xmlspy/Windows-Live-Writer/99ccd53365ce_D03E/Y3RDP4%60%60Q@%5D%5B2%5DJX%5D3DYVA7%5B4%5D_thumb.jpg)
- General->Workspace
在Text file encoding中選擇Other,然后在下拉框中選UTF-8 : 這樣所有項(xiàng)目都是用UTF-8編碼.默認(rèn)的是GBK.
- Java->Code Style->Formatter
這里是Java代碼格式化相關(guān)的選項(xiàng), 要修改默認(rèn)的設(shè)置,需要新建一個(gè)配置.
點(diǎn)擊按鈕 New… 在彈出框中的 Profile name 輸入框輸入新配置的名稱,這里輸入 11, 然后點(diǎn)擊OK按鈕.
在新彈出的配置窗口中,選擇標(biāo)簽Indentation, 在Tab policy下拉框中選擇 Spaces only : 縮進(jìn)使用空格.
這里需要注意,如果在General->Editors->Text Editors中選擇了Insert spaces for tabs, 而在格式化選項(xiàng)中
沒(méi)有改成使用空格,那么在Java代碼格式化后,仍然使用Tab.
選擇標(biāo)簽 Line Wrapping,在Maximum line width輸入框輸入120 : 在120個(gè)字符后換行, 上面的 Print margin column
也用的120,這樣就知道換行的標(biāo)示了.
其他如果有Editor的地方,縮進(jìn)也都要改成4個(gè)空格. 比如: Web節(jié)點(diǎn)下面的CSS Files, HTML Files.
posted @
2013-11-17 15:32 xmlspy 閱讀(2720) |
評(píng)論 (2) |
編輯 收藏
使用這個(gè)東西的好處是,可以發(fā)布到多個(gè)Blog上,免得使用Web編輯器苦逼地編輯.
下載地址: http://windows.microsoft.com/zh-cn/windows-live/essentials-other#essentials=overviewother
* 使用Live Writer在oschina上寫B(tài)log: http://my.oschina.net/javayou/blog/39107
* 使用Live Writer在BlogJava上鞋Blog: http://www.tkk7.com/vulcan/archive/2010/11/05/337323.html
注意: - 在日志類型中選擇Metaweblog API
- API連接為: http://www.tkk7.com/你的blog名稱/services/metaweblog.aspx
更新了最新Android ADT工具后,出現(xiàn) TypeError: argument of type 'NoneType' is not iterable.

解決:
復(fù)制 build-tool/17.0.0/ 下所有內(nèi)容到 platform-tools 目錄下.
參考:
https://developer.appcelerator.com/question/152497/titanium-sdk-310-error-typeerror-argument-of-type-nonetype-is-not-iterable-on-building-android-app
有時(shí)候Titanium中的終端會(huì)顯示:
This Terminal Emulator is not functional because no 'bash' shell could be found.
Please correct the problem and restart the IDE.
解決辦法:
- Team / Git / Git Executable (was empty) --指定正確的git.exe文件位置
- Titanium Studio / NodeJS / Node Executable (was empty also) ---- 指定NodeJS的node.exe的位置
然后重啟終端就好了.
1.目的
在WebView控件中,如果頁(yè)面中調(diào)用了javascript腳本console.log 方法,就調(diào)用一個(gè)Java方法.
2.默認(rèn)實(shí)現(xiàn)方法
在Android的WebView控件中,有一個(gè)setChromeClient(WebChromeClient)方法,
此方法的參數(shù)是WebChromeClient對(duì)象,通過(guò)重載此對(duì)象中的onConsoleMessage方法就
可以達(dá)到此目的.看代碼:
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);
}
}
第一個(gè)方法onConsoleMessage(ConsoleMessage consoleMessage)是新版本的android才有的方法,第二個(gè)方法是舊版本的.
第二個(gè)方法已經(jīng)不推薦使用了,但是在舊版本的android中,仍然需要此方法.所以最好兩個(gè)方法都實(shí)現(xiàn).
3.問(wèn)題
默認(rèn)的實(shí)現(xiàn)在某些版本的手機(jī)中不好使,onConsoleMessage方法死活不被調(diào)用
4.解決方案
使用WebView的addJavascriptInterface方法:
// 首先,定一個(gè)類,叫什么名稱都可以,但是里面的方法名必須與
// Javascript的console中的方法名對(duì)應(yīng)
private class Console{
private static final String TAG="[WebView]";
public void log(String msg){
Log.i(TAG,msg);
}
// 還可以添加其他的方法,比如: warn,assert等等
}
// 然后,為WebView添加對(duì)應(yīng)的接口
webView.addJavascriptInterface(new Console, "console");
這個(gè)解決方案有一個(gè)不好的地方,就是輸出的內(nèi)容沒(méi)有onConsoleMessage方法那么詳細(xì),比如行號(hào),就沒(méi)法輸出.
所以,我們應(yīng)該在onConsoleMessage好使的時(shí)候使用onConsoleMessage,不好使的時(shí)候在使用我們自定義的方式.
那么,如何來(lái)判斷onConsoleMessage是否好使呢? 我們可以在程序初始化的時(shí)候,先在WebView中運(yùn)行一下console.log,
如果onConsoleMessage運(yùn)行了,就添加一個(gè)標(biāo)記,表示默認(rèn)的實(shí)現(xiàn)是好使的.
@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();
// 先執(zhí)行console.log,測(cè)試是否調(diào)用了onConsoleMessage
webView.loadUrl("javascript:console.log('testConsoleMessage')");
if (((TestConsoleMessageWebChromeClient)webChromeClient).isConsoleMessageOK()){
// 這里額外使用了一個(gè)新的類 TestConsoleMessageWebChromeClient
// 如果不適用TestConsoleMessageWebChromeClient,就需要在
// DefaultWebChromeClient中添加標(biāo)記字段 consoleMessageOK,
// 這樣如果方法onConsoleMessage好使,那么每次都給consoleMessageOK賦值,
// 這個(gè)有些多余,也影響性能.
webChromeClient = new DefualtWebChromeClient();
}else{
// onConsoleMessage不好使,就使用這種方式,第二個(gè)參數(shù)值必須是"console"
webView.addJavascriptInterface(new Console(), "console");
}
webView.loadUrl("http://www.baidu.com");
return super.onCreateView(inflater, container, savedInstanceState);
}
// 當(dāng)默認(rèn)的onConsoleMessage不好使的時(shí)候使用的類
private class Console {
private static final String TAG = "[WebView]";
public void log(String msg) {
Log.i(TAG, msg);
}
// 這里還可以添加其他方法console對(duì)象中有的方法,比如 assert
}
// 默認(rèn)
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);
}
}
// 用于測(cè)試onConsoleMessage是否調(diào)用的類
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;
}
}
posted @
2013-04-28 01:46 xmlspy 閱讀(3038) |
評(píng)論 (0) |
編輯 收藏
匿名立即執(zhí)行函數(shù)
1: // 方式一,這種方式多用了一個(gè)括號(hào),看著別扭
2: (function(param) {
3: alert(param);
4: })(10);
5:
6: // 方式二,使用 ! 操作符
7: !function(param) {
8: alert(param);
9: }(10);
使用匿名立即執(zhí)行函數(shù)的好處是,可以避免變量沖突.
條件判斷
1: //========================= 條件判斷
2: var sabiable = true;
3: //普通方式
4: if (sabiable) {
5: alert('You are sability!');
6: }
7:
8: //詭異方式,利用 ||和 && 操作符
9: // a||b : 只有在a為fasle或者返回false時(shí)才會(huì)執(zhí)行b,當(dāng)a為true時(shí),直接返回a,后面的b不會(huì)執(zhí)行
10: // a&&b : 只有在a為true或者返回true時(shí)才會(huì)執(zhí)行b,當(dāng)a為時(shí),直接返回a,后面的b不會(huì)執(zhí)行
11:
12: // 上面的代碼可以改為:
13: sabiable && alert('You are sability!');
問(wèn)題: 以下代碼,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: //這個(gè)事件在iOS中不會(huì)被觸發(fā)
27: });
28:
29: return self;
30: };
31:
32: module.exports = ApplicationTabGroup;
解決方案:
通過(guò)看Titanium附帶的示例程序 Kitcken Sink , 找到了解決方案.
為TabGroup添加focus事件,然后對(duì)事件參數(shù)進(jìn)行判斷,來(lái)確定當(dāng)前被點(diǎn)擊的是那個(gè)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對(duì)象,
30: // 在Android中,e.source 是 Tab對(duì)象
31: var src = e.source;
32: var tab = e.tab;
33: var preTab = e.previousIndex;
34:
35: // e.tab 是當(dāng)前獲得焦點(diǎn)的tab
36: // e.index 當(dāng)前獲得焦點(diǎn)的tab的索引,首次為-1
37: // e.previousTab 上個(gè)tab
38: // e.previousIndex 上個(gè)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中點(diǎn)擊了"More..."');
43: return;
44: }
45:
46: // 首次
47: if (!preTab) {
48: info('首次進(jìn)入');
49: return;
50: }
51:
52: if (tab === tab1) {
53: info('點(diǎn)擊了tab1');
54: } else if (tab === tab2) {
55: info('點(diǎn)擊了tab2');
56: }
57: });
58:
59: return self;
60: };
61:
62: module.exports = ApplicationTabGroup;