国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Log.i()的用法

2019-11-14 22:44:40
字體:
來源:轉載
供稿:網友
Log.i()的用法2011-04-16 09:4417486人閱讀評論(4)收藏舉報androidlayoutbuttonstringencodingeclipse

在調試代碼的時候我們需要查看調試信息,那我們就需要用Android Log類。

android.util.Log常用的方法有以下5個:Log.v()Log.d()Log.i()Log.w()以及Log.e()。根據首字母對應VERBOSEDEBUG,INFO,WARN,ERROR。

1、Log.v 的調試顏色為黑色的,任何消息都會輸出,這里的v代表verbose啰嗦的意思,平時使用就是Log.v("","");

2、Log.d的輸出顏色是藍色的,僅輸出debug調試的意思,但他會輸出上層的信息,過濾起來可以通過DDMS的Logcat標簽來選擇.

3、Log.i的輸出為綠色,一般提示性的消息information,它不會輸出Log.v和Log.d的信息,但會顯示i、w和e的信息

4、Log.w的意思為橙色,可以看作為warning警告,一般需要我們注意優化Android代碼,同時選擇它后還會輸出Log.e的信息。

5、Log.e為紅色,可以想到error錯誤,這里僅顯示紅色的錯誤信息,這些錯誤就需要我們認真的分析,查看棧的信息了。

注意:不同的打印方法在使用時都是某個方法帶上(String tag, String msg)參數,tag表示的是打印信息的標簽,msg表示的是需要打印的信息。

下面是我做的一個簡單的LogDemo(Step By Step):

Step 1:準備工作(打開LogCat視窗).

啟動Eclipse,在Window->Show View會出來一個對話框,當我們點擊Ok按鈕時,會在控制臺窗口出現LogCat視窗.如下圖:

Step 2:新建一個Android工程,命名為LogDemo.

Step 3:設計UI界面,我們在這里就加了一個Button按鈕(點擊按鈕出現Log日志信息).

Main.xml代碼如下:

[xhtml]view plaincopy
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. >
  7. <TextView
  8. android:layout_width="fill_parent"
  9. android:layout_height="wrap_content"
  10. android:text="@string/hello"
  11. />
  12. <Button
  13. android:id="@+id/bt"
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:text="
  17. />
  18. </LinearLayout>

Step 4:設計主類LogDemo.java,代碼如下:

[java]view plaincopy
  1. publicclassLogDemoextendsActivity{
  2. privatestaticfinalStringACTIVITY_TAG="LogDemo";
  3. privateButtonbt;
  4. publicvoidonCreate(BundlesavedInstanceState){
  5. super.onCreate(savedInstanceState);
  6. setContentView(R.layout.main);
  7. //通過findViewById找到Button資源
  8. bt=(Button)findViewById(R.id.bt);
  9. //增加事件響應
  10. bt.setOnClickListener(newButton.OnClickListener(){
  11. @Override
  12. publicvoidonClick(Viewv){
  13. Log.v(LogDemo.ACTIVITY_TAG,"ThisisVerbose.");
  14. Log.d(LogDemo.ACTIVITY_TAG,"ThisisDebug.");
  15. Log.i(LogDemo.ACTIVITY_TAG,"ThisisInformation");
  16. Log.w(LogDemo.ACTIVITY_TAG,"ThisisWarnning.");
  17. Log.e(LogDemo.ACTIVITY_TAG,"ThisisError.");
  18. }
  19. });
  20. }
  21. }

Step 5:運行LogDemo工程,效果如下:

當我們點擊按鈕時,會觸發事件,在Logcat視窗下有如下效果:


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乐至县| 平舆县| 凤台县| 石首市| 元江| 仪征市| 瓮安县| 鱼台县| 永嘉县| 大竹县| 临颍县| 大悟县| 中西区| 仁化县| 洛浦县| 鄂伦春自治旗| 武宁县| 合水县| 房山区| 台南县| 法库县| 华亭县| 武定县| 和田县| 宁陵县| 南安市| 南通市| 庆安县| 东乌| 泰宁县| 屏山县| 泰宁县| 合川市| 高密市| 玉树县| 庆城县| 霍州市| 苏尼特右旗| 奉化市| 五常市| 营口市|