Android Method i (String, String) undefined for 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 in this line is:

 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 can help, it will 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); } } 
+4
source share
2 answers

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

+11
source

It looks like you are using a different logging function than your own android: android.util.Log. If your heart is configured to use apache, use Log.info (message java.lang.Object, java.lang.Throwable t).

+2
source

Source: https://habr.com/ru/post/1444935/


All Articles