-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>
感謝你
檢查的最後一行是...它'.TimeTrackerr'它的'.TimeTracker'正確嗎? – Deepzz
感謝您的答案,但上面的應用程序給我錯誤Nullpointer異常。現在我的問題是,如何使用Logcat找出特定類別中的特定錯誤。我是android編程的初學者。 –
顯示你的logcat我會告訴你。 –