Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - The Method i(String, String) is undefined for the type Log

I keep getting this error in my Main.Activity.java.

    The Method i(String, String) is undefined for the type Log

The error happens on this line:

Log.i("HelloListView", "You clicked Item: " + id + " at position:" + position);

I do not know what is wrong, so here is my whole MainActivity.java. If someone could help, that would be great.

    package com.example.uc.pf;

import org.apache.commons.logging.Log;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class MainActivity extends Activity implements OnItemClickListener {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);

    //* *EDIT* * 
    ListView listview = (ListView) findViewById(R.id.listView1);
    listview.setOnItemClickListener(this);
}

public void onItemClick(AdapterView<?> l, View v, int position, long id) {
    Log.i("HelloListView", "You clicked Item: " + id + " at position:" + position);
        // Then you start a new Activity via Intent
        Intent intent = new Intent();
        intent.setClass(this, ListItemDetail.class);
        intent.putExtra("position", position);
        // Or / And
        intent.putExtra("id", id);
        startActivity(intent);
    }
}
like image 465
Michael Abreu Avatar asked Dec 11 '22 20:12

Michael Abreu


1 Answers

You are importing org.apache.commons.logging.Log;. Change to android.util.Log

like image 75
Marcelo Avatar answered May 15 '23 22:05

Marcelo