调用setadapter函数后,我的应用程序崩溃了,我很困惑。根据logcat,这是一个空异常,但我似乎无法弄清楚问题所在。任何帮助表示赞赏!
这是我的主要
package com.example.ridehistory;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.support.v4.app.NavUtils;
import android.annotation.TargetApi;
import android.os.Build;
public class MainActivity extends Activity {
private ListView rideHistoryListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Show the Up button in the action bar.
//setupActionBar();
//Initialize for fake data
ArrayList<String> array1 = new ArrayList<String>();
array1.add("first passenger1");
ArrayList<String> array2 = new ArrayList<String>();
array2.add("first passenger2");
ArrayList<String> array3 = new ArrayList<String>();
array3.add("first passenger3");
ArrayList<String> array4 = new ArrayList<String>();
array4.add("first passenger4");
ArrayList<String> array5 = new ArrayList<String>();
array5.add("first passenger5");
SimpleDateFormat date1 = new SimpleDateFormat("1/2/80");
SimpleDateFormat date2 = new SimpleDateFormat("2/3/80");
SimpleDateFormat date3 = new SimpleDateFormat("3/4/80");
SimpleDateFormat date4 = new SimpleDateFormat("4/5/80");
SimpleDateFormat date5 = new SimpleDateFormat("5/6/80");
//Start of the actual code
RideTransaction ride_data[] = new RideTransaction[]
{
new RideTransaction("A","Last",array1,"sf","la",date1),
new RideTransaction("B", "Last", array2, "la", "sd", date2),
new RideTransaction("C", "Last", array3, "sf", "ny", date3),
new RideTransaction("D", "Last", array4, "sf", "sd", date4),
new RideTransaction("E" , "Last", array5, "irvine", "la", date5)
};
RideHistoryAdapter adapter = new RideHistoryAdapter(this,
R.layout.listview_item_row,
ride_data);
rideHistoryListView = (ListView)findViewById(R.id.rideHistoryListView);
//RideHistoryAdapter adapter = new RideHistoryAdapter(this);
View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
rideHistoryListView.addHeaderView(header);
rideHistoryListView.setAdapter(adapter);
}
/**
* Set up the {@link android.app.ActionBar}, if the API is available.
*/
/*
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.ride_history, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}*/
}
这是我的适配器
package com.example.ridehistory;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class RideHistoryAdapter extends ArrayAdapter<RideTransaction>{
Context context;
int layoutResourceId;
RideTransaction data[] = null;
public RideHistoryAdapter(Context context, int layoutResourceId, RideTransaction[] data)
{
super( context, layoutResourceId, data);
this.context = context;
this.layoutResourceId = layoutResourceId;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
RideTransactionHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new RideTransactionHolder();
holder.txtFirstName = (TextView)row.findViewById(R.id.txtFirstName);
holder.txtLastName = (TextView)row.findViewById(R.id.txtLastName);
holder.txtPassengers = (TextView)row.findViewById(R.id.txtPassengers);
holder.txtStartLocation = (TextView)row.findViewById(R.id.txtStartLocation);
holder.txtEndLocation = (TextView)row.findViewById(R.id.txtEndLocation);
row.setTag(holder);
}
else
{
holder = (RideTransactionHolder)row.getTag();
}
RideTransaction rideTransaction = data[position];
holder.txtFirstName.setText(rideTransaction.firstName);
holder.txtLastName.setText(rideTransaction.lastName);
holder.txtPassengers.setText("hmm");
holder.txtStartLocation.setText(rideTransaction.startLocation);
holder.txtEndLocation.setText(rideTransaction.endLocation);
holder.txtDateTime.setText(rideTransaction.dateTime.toString());
return row;
}
static class RideTransactionHolder
{
TextView txtFirstName;
TextView txtLastName;
TextView txtPassengers;
TextView txtStartLocation;
TextView txtEndLocation;
TextView txtDateTime;
}
}
这是搭车交易
package com.example.ridehistory;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class RideTransaction {
public String firstName;
public String lastName;
public ArrayList<String> passengers;
//some kind promptness rating..?
public String startLocation;
public String endLocation;
public SimpleDateFormat dateTime;
public RideTransaction()
{
super();
}
public RideTransaction(String firstName, String lastName, ArrayList<String> passengers, String startLocation, String endLocation, SimpleDateFormat dateTime)
{
this.firstName = firstName;
this.lastName = lastName;
this.passengers = passengers;
this.startLocation = startLocation;
this.endLocation = endLocation;
this.dateTime = dateTime;
}
}
这是主要的xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ListView
android:id="@+id/rideHistoryListView"
android:layout_width = "fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>
这是项目行xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp">
<TextView
android:id="@+id/txtDateTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="date"
/>
<TextView
android:id="@+id/txtFirstName"
android:layout_width="wrap_content"
android:layout_height = "wrap_content"
android:gravity="center_horizontal"
android:layout_below="@id/txtDateTime"
android:text="first"
/>
<TextView
android:id="@+id/txtLastName"
android:layout_width="wrap_content"
android:layout_height = "wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/txtFirstName"
android:layout_below="@id/txtDateTime"
android:gravity="center_horizontal"
android:text="last"
/>
<TextView
android:id="@+id/txtPassengers"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:gravity="center_horizontal"
android:layout_below="@id/txtFirstName"
android:text="passengers"
/>
<TextView
android:id="@+id/txtStartLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_below="@id/txtPassengers"
android:text="start"
/>
<TextView
android:id="@+id/txtEndLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtPassengers"
android:layout_toRightOf="@id/txtStartLocation"
android:gravity="center_horizontal"
android:text="end"
/>
</RelativeLayout>
这是项目标题
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/txtHeader"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#FFFFFF"
android:padding="10dp"
android:text="Ride Transaction"
android:background="#336699" />
</LinearLayout>
这是我的日志
05-03 01:26:27.087: W/dalvikvm(272): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-03 01:26:27.107: E/AndroidRuntime(272): FATAL EXCEPTION: main
05-03 01:26:27.107: E/AndroidRuntime(272): java.lang.NullPointerException
05-03 01:26:27.107: E/AndroidRuntime(272): at com.example.ridehistory.RideHistoryAdapter.getView(RideHistoryAdapter.java:52)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.widget.AbsListView.obtainView(AbsListView.java:1315)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.widget.ListView.makeAndAddView(ListView.java:1727)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.widget.ListView.fillDown(ListView.java:652)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.widget.ListView.fillFromTop(ListView.java:709)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.widget.ListView.layoutChildren(ListView.java:1580)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.widget.AbsListView.onLayout(AbsListView.java:1147)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.view.View.layout(View.java:7035)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:909)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.view.View.layout(View.java:7035)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.view.View.layout(View.java:7035)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.view.View.layout(View.java:7035)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.view.View.layout(View.java:7035)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.os.Handler.dispatchMessage(Handler.java:99)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.os.Looper.loop(Looper.java:123)
05-03 01:26:27.107: E/AndroidRuntime(272): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-03 01:26:27.107: E/AndroidRuntime(272): at java.lang.reflect.Method.invokeNative(Native Method)
05-03 01:26:27.107: E/AndroidRuntime(272): at java.lang.reflect.Method.invoke(Method.java:521)
05-03 01:26:27.107: E/AndroidRuntime(272): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-03 01:26:27.107: E/AndroidRuntime(272): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-03 01:26:27.107: E/AndroidRuntime(272): at dalvik.system.NativeStart.main(Native Method)
05-03 01:26:36.588: I/Process(272): Sending signal. PID: 272 SIG: 9
05-03 04:13:50.917: D/AndroidRuntime(586): Shutting down VM
05-03 04:13:50.917: W/dalvikvm(586): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-03 04:13:50.937: E/AndroidRuntime(586): FATAL EXCEPTION: main
05-03 04:13:50.937: E/AndroidRuntime(586): java.lang.NullPointerException
05-03 04:13:50.937: E/AndroidRuntime(586): at com.example.ridehistory.RideHistoryAdapter.getView(RideHistoryAdapter.java:52)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.widget.AbsListView.obtainView(AbsListView.java:1315)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.widget.ListView.makeAndAddView(ListView.java:1727)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.widget.ListView.fillDown(ListView.java:652)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.widget.ListView.fillFromTop(ListView.java:709)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.widget.ListView.layoutChildren(ListView.java:1580)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.widget.AbsListView.onLayout(AbsListView.java:1147)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.view.View.layout(View.java:7035)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:909)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.view.View.layout(View.java:7035)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.view.View.layout(View.java:7035)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.view.View.layout(View.java:7035)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.view.View.layout(View.java:7035)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.os.Handler.dispatchMessage(Handler.java:99)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.os.Looper.loop(Looper.java:123)
05-03 04:13:50.937: E/AndroidRuntime(586): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-03 04:13:50.937: E/AndroidRuntime(586): at java.lang.reflect.Method.invokeNative(Native Method)
05-03 04:13:50.937: E/AndroidRuntime(586): at java.lang.reflect.Method.invoke(Method.java:521)
05-03 04:13:50.937: E/AndroidRuntime(586): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-03 04:13:50.937: E/AndroidRuntime(586): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-03 04:13:50.937: E/AndroidRuntime(586): at dalvik.system.NativeStart.main(Native Method)
05-03 04:18:50.997: I/Process(586): Sending signal. PID: 586 SIG: 9
05-03 04:35:30.760: D/AndroidRuntime(616): Shutting down VM
05-03 04:35:30.760: W/dalvikvm(616): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-03 04:35:30.779: E/AndroidRuntime(616): FATAL EXCEPTION: main
05-03 04:35:30.779: E/AndroidRuntime(616): java.lang.NullPointerException
05-03 04:35:30.779: E/AndroidRuntime(616): at com.example.ridehistory.RideHistoryAdapter.getView(RideHistoryAdapter.java:55)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.widget.AbsListView.obtainView(AbsListView.java:1315)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.widget.ListView.makeAndAddView(ListView.java:1727)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.widget.ListView.fillDown(ListView.java:652)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.widget.ListView.fillFromTop(ListView.java:709)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.widget.ListView.layoutChildren(ListView.java:1580)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.widget.AbsListView.onLayout(AbsListView.java:1147)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.view.View.layout(View.java:7035)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:909)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.view.View.layout(View.java:7035)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.view.View.layout(View.java:7035)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.view.View.layout(View.java:7035)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.view.View.layout(View.java:7035)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.os.Handler.dispatchMessage(Handler.java:99)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.os.Looper.loop(Looper.java:123)
05-03 04:35:30.779: E/AndroidRuntime(616): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-03 04:35:30.779: E/AndroidRuntime(616): at java.lang.reflect.Method.invokeNative(Native Method)
05-03 04:35:30.779: E/AndroidRuntime(616): at java.lang.reflect.Method.invoke(Method.java:521)
05-03 04:35:30.779: E/AndroidRuntime(616): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-03 04:35:30.779: E/AndroidRuntime(616): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-03 04:35:30.779: E/AndroidRuntime(616): at dalvik.system.NativeStart.main(Native Method)
05-03 04:35:35.667: I/Process(616): Sending signal. PID: 616 SIG: 9
05-03 04:37:52.767: D/AndroidRuntime(646): Shutting down VM
05-03 04:37:52.777: W/dalvikvm(646): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-03 04:37:52.787: E/AndroidRuntime(646): FATAL EXCEPTION: main
05-03 04:37:52.787: E/AndroidRuntime(646): java.lang.NullPointerException
05-03 04:37:52.787: E/AndroidRuntime(646): at com.example.ridehistory.RideHistoryAdapter.getView(RideHistoryAdapter.java:55)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.widget.AbsListView.obtainView(AbsListView.java:1315)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.widget.ListView.makeAndAddView(ListView.java:1727)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.widget.ListView.fillDown(ListView.java:652)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.widget.ListView.fillFromTop(ListView.java:709)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.widget.ListView.layoutChildren(ListView.java:1580)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.widget.AbsListView.onLayout(AbsListView.java:1147)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.view.View.layout(View.java:7035)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:909)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.view.View.layout(View.java:7035)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.view.View.layout(View.java:7035)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.view.View.layout(View.java:7035)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.view.View.layout(View.java:7035)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.os.Handler.dispatchMessage(Handler.java:99)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.os.Looper.loop(Looper.java:123)
05-03 04:37:52.787: E/AndroidRuntime(646): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-03 04:37:52.787: E/AndroidRuntime(646): at java.lang.reflect.Method.invokeNative(Native Method)
05-03 04:37:52.787: E/AndroidRuntime(646): at java.lang.reflect.Method.invoke(Method.java:521)
05-03 04:37:52.787: E/AndroidRuntime(646): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-03 04:37:52.787: E/AndroidRuntime(646): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-03 04:37:52.787: E/AndroidRuntime(646): at dalvik.system.NativeStart.main(Native Method)
05-03 04:37:56.817: I/Process(646): Sending signal. PID: 646 SIG: 9
05-03 04:39:41.727: D/AndroidRuntime(675): Shutting down VM
05-03 04:39:41.727: W/dalvikvm(675): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-03 04:39:41.761: E/AndroidRuntime(675): FATAL EXCEPTION: main
05-03 04:39:41.761: E/AndroidRuntime(675): java.lang.NullPointerException
05-03 04:39:41.761: E/AndroidRuntime(675): at com.example.ridehistory.RideHistoryAdapter.getView(RideHistoryAdapter.java:55)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.widget.AbsListView.obtainView(AbsListView.java:1315)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.widget.ListView.makeAndAddView(ListView.java:1727)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.widget.ListView.fillDown(ListView.java:652)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.widget.ListView.fillFromTop(ListView.java:709)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.widget.ListView.layoutChildren(ListView.java:1580)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.widget.AbsListView.onLayout(AbsListView.java:1147)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.view.View.layout(View.java:7035)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:909)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.view.View.layout(View.java:7035)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.view.View.layout(View.java:7035)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.view.View.layout(View.java:7035)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.view.View.layout(View.java:7035)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.os.Handler.dispatchMessage(Handler.java:99)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.os.Looper.loop(Looper.java:123)
05-03 04:39:41.761: E/AndroidRuntime(675): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-03 04:39:41.761: E/AndroidRuntime(675): at java.lang.reflect.Method.invokeNative(Native Method)
05-03 04:39:41.761: E/AndroidRuntime(675): at java.lang.reflect.Method.invoke(Method.java:521)
05-03 04:39:41.761: E/AndroidRuntime(675): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-03 04:39:41.761: E/AndroidRuntime(675): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-03 04:39:41.761: E/AndroidRuntime(675): at dalvik.system.NativeStart.main(Native Method)
05-03 04:39:46.888: I/Process(675): Sending signal. PID: 675 SIG: 9
05-03 04:58:52.298: D/AndroidRuntime(704): Shutting down VM
05-03 04:58:52.298: W/dalvikvm(704): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-03 04:58:52.318: E/AndroidRuntime(704): FATAL EXCEPTION: main
05-03 04:58:52.318: E/AndroidRuntime(704): java.lang.NullPointerException
05-03 04:58:52.318: E/AndroidRuntime(704): at com.example.ridehistory.RideHistoryAdapter.getView(RideHistoryAdapter.java:55)
05-03 04:58:52.318: E/AndroidRuntime(704): at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
最佳答案
NullPointerException
出现在holder.txtDateTime.setText(rideTransaction.dateTime.toString());
行,因为您尚未初始化holder.txtDateTime
。
在使用之前进行初始化,即添加此行holder.txtDateTime = (TextView)row.findViewById(R.id.txtDateTime);