java - Android - Log 类型未定义方法 i(String, String)

标签 java android listview logging onitemclicklistener

我的 Main.Activity.java 中一直出现此错误。

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

错误发生在这一行:

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

我不知道哪里出了问题,所以这是我的整个 MainActivity.java。如果有人可以提供帮助,那就太好了。

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

最佳答案

您正在导入 org.apache.commons.logging.Log;。 改为android.util.Log

关于java - Android - Log 类型未定义方法 i(String, String),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13297579/

相关文章:

Java 直接强制转换与使用局部变量强制转换

java - 没有父信息的节点到字符串

android - 为什么我不能将文本设置为 Android TextView?

android - ListView 自定义适配器 - 何时调用 notifyDataSetChanged?

Android - 带有 popupWindow 的 OAuth 应用程序

java - Android ListView 不再突出显示选择 onclick

java - Mybatis在select语句中动态列

java - 使用 Spring @Transactionnal,Spring 如何知道使用哪个数据源?

c# - 将项目添加到 Winforms 中 ListView 的特定列

jquery - ListView 分隔符 JQuery Mobile