2013-01-11 41 views
-1

我已经创建了Android应用程序,我已经采取了Listview,并且我想在使用Baseadapter的listview中显示数据,但是我的应用程序在logcat中给了我错误。我搜索很多无法找到相关的信息。如何使用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)以下是清单文件

<?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> 

感谢你

回答

2

你的类名是

TimeTracker 

和你写

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

从您的清单中的活动属性中删除了最后的R如下

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

或只写

android:name=".TimeTracker" 
+0

检查的最后一行是...它'.TimeTrackerr'它的'.TimeTracker'正确吗? – Deepzz

+0

感谢您的答案,但上面的应用程序给我错误Nullpointer异常。现在我的问题是,如何使用Logcat找出特定类别中的特定错误。我是android编程的初学者。 –

+0

显示你的logcat我会告诉你。 –

相关问题