Erstellen einer einfachen Ausgabe in logcat

Ich kann nicht herausfinden, den richtigen Weg, um die Ausgabe einer int das logcat und die api-Dokument macht keinen Sinn für mich.

Ich glaube, das sollte es tun:

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;
    }

}

Jedoch bekomme ich nur die Fehlermeldung The method d(String, String) in the type Log is not applicable for the arguments (int)

Muss ich cast den int in einen string? Und wenn ja, wie?

Update:

Obwohl alle Lösungen arbeiten, LogCat würde keine display-Ausgabe, bis ich ausgewählt habe, meine hardware in DDMS.

InformationsquelleAutor nipponese | 2013-03-15
Schreibe einen Kommentar