我找不出輸出int logcat的正確方法,並且api document對我來說沒有意義。創建一個簡單的輸出到logcat
我覺得這應該這樣做:
package com.example.conflip;
import java.util.Random;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
flip();
}
public int flip() {
Random randomNumber = new Random();
int outcome = randomNumber.nextInt(2);
Log.d(outcome);
return outcome;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
但是我只得到錯誤The method d(String, String) in the type Log is not applicable for the arguments (int)
我是否需要整型轉換爲字符串?如果是這樣,怎麼樣?
更新:
雖然下面的所有解決方案做的工作,logcat的不會,直到我選擇我的硬件設備DDMS顯示輸出。
好吧,我沒有得到一個錯誤,但我不logcat中看到任何要麼... – nipponese 2013-03-15 06:43:50