-1

我已经创建了 android 应用程序,我使用了 Listview,我想使用 Baseadapter 在 listview 中显示数据,但是我的应用程序在 logcat 中给了我错误。我搜索了很多找不到相关信息。

日志错误:

java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.oj2.exlistview/com.oj2.exlistview.TimeTrackerr}:
java.lang.ClassNotFoundException: com.oj2.exlistview.TimeTrackerr in loader
dalvik.system.PathClassLoader[/data/app/com.oj2.exlistview-1.apk]

在 src 文件夹中,我有三个文件

1)首先是适配器类 2)其次是活动类 3)这个普通类具有成员乐趣和数据成员

1)以下是适配器类

package com.oj2.exlistview;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class TimeTrackAdapter extends BaseAdapter {

    ArrayList<TimeRecord> times = new ArrayList<TimeRecord>();


    public TimeTrackAdapter() {
        super();

        times.add(new TimeRecord("23.43", "Feeling good"));
        times.add(new TimeRecord("11.43", "hi this adapter"));
        times.add(new TimeRecord("12.43", "I m Rocking it"));
        times.add(new TimeRecord("13.43", "Feeling good"));
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return times.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return getItem(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        if (convertView == null){
            LayoutInflater inflater = LayoutInflater.from(parent.getContext());
            convertView = inflater.inflate(R.layout.time_list_item, parent,false);
            TimeRecord time = times.get(position);

            TextView timeTextView = (TextView) convertView.findViewById(R.id.timeView);
            timeTextView.setText(time.getTimes());


            TextView noteTextView = (TextView) convertView.findViewById(R.id.noteView);
            timeTextView.setText(time.getTimes());

        }
        return null;
    }
}

2)第二个是活动类

package com.oj2.exlistview;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;

public class TimeTracker extends Activity{
    TimeTrackAdapter timeTrackAdapter= null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);
        ListView listView = (ListView) findViewById(R.id.timeListView);
        timeTrackAdapter = new TimeTrackAdapter();

        listView.setAdapter(timeTrackAdapter);
        listView.getAdapter();
    }


}

3)以下是Manifest文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.oj2.exlistview"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.oj2.exlistview.TimeTrackerr"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

感谢您

4

1 回答 1

2

你的班级名称是

TimeTracker

你写的

android:name="com.oj2.exlistview.TimeTrackerr"

从清单的活动属性中删除最后一个 r,如下所示

android:name="com.oj2.exlistview.TimeTracker" 

或者只是写

android:name=".TimeTracker" 
于 2013-01-11T05:09:40.477 回答