當我點擊我的應用程序上的按鈕時,我在日誌上得到上述錯誤。我將發佈發送活動和接收活動的代碼。致命例外:主,無法啓動活動ComponentInfo
發送活動:
private TrackerDAO dbHelper;
private SimpleCursorAdapter dataAdapter;
String historyString = "";
long idDB;
long getlastID;
String getAD;
String Check;
public static long TripID;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history_list);
try{
dbHelper = new TrackerDAO(this);
}catch(SQLException e){
e.printStackTrace();
}
dbHelper.open();
displayListView();
}
private void displayListView() {
Cursor cursor = dbHelper.fetchAllEntries();
// The desired columns to be bound
String[] columns = new String[] {
DBConfiguration.KEY_NAME,
DBConfiguration.KEY_CITY,
DBConfiguration.KEY_REASON,
DBConfiguration.KEY_BUDGET
};
// the XML defined views which the data will be bound to
int[] to = new int[]{
R.id.TV_trip_name,
R.id.TV_city_name,
R.id.TV_trip_reason,
R.id.TV_budget,
};
//create the adapter using the cursor pointing to the desired data
//as well as the layout information
dataAdapter = new SimpleCursorAdapter(this, R.layout.history_list_item, cursor, columns, to, 0);
ListView listView = (ListView) findViewById(R.id.listView_tripHistory);
// Assign adapter to ListView
listView.setAdapter(dataAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> listView, View view, int position, long id) {
intentMethod(id);
}
private void intentMethod(long ID) {
//Bundle basket_tripID = new Bundle();
//basket_tripID.putExtra("key_ID",TripID);
TripID = ID;
Intent Openactivity = new Intent(HistoryListActivity.this, HistoryViewerActivity.class);
//Openactivity.putExtra("key_ID",id);
startActivity(Openactivity);
}
});
}
protected void onPause() {
super.onPause();
finish();
}
}
這裏的Recieving活動:
TextView TripName, TripReason, cityName, SD, AD, budget, HE, TE, FE, EE, SE, OE, RemainBudget;
ImageButton CheckedIn;
long idDB = HistoryListActivity.TripID;
String name ;
String city;
String reason;
String startingdate;
String arrivaldate;
String tbudget;
int hexp;
int texp;
int fexp;
int eexp;
int sexp;
int oexp;
int rbudget;
TrackerDAO dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history_viewer);
TripName = (TextView) findViewById(R.id.textView_History_TripName);
cityName = (TextView) findViewById(R.id.textView_History_CityName);
TripReason = (TextView) findViewById(R.id.textView_History_TripReason);
SD = (TextView) findViewById(R.id.textView_History_SD);
AD = (TextView) findViewById(R.id.textView__History_AD);
budget = (TextView) findViewById(R.id.textView_History_Budget);
HE = (TextView) findViewById(R.id.textView_History_Hotel);
TE = (TextView) findViewById(R.id.textView_History_Transport);
FE = (TextView) findViewById(R.id.textView__History_Food);
EE = (TextView) findViewById(R.id.textView_History_Entertainment);
SE = (TextView) findViewById(R.id.textView_History_Shopping);
OE = (TextView) findViewById(R.id.textView_History_Other);
RemainBudget = (TextView) findViewById(R.id.textView_History_RemainingBudget);
CheckedIn = (ImageButton) findViewById(R.id.imageButton_CheckedIN);
displayshowHistory(idDB);
TripName.setText(name);
cityName.setText(city);
TripReason.setText(reason);
SD.setText(startingdate);
AD.setText(arrivaldate);
budget.setText(tbudget);
HE.setText(String.valueOf(hexp));
TE.setText(String.valueOf(texp));
FE.setText(String.valueOf(fexp));
EE.setText(String.valueOf(eexp));
SE.setText(String.valueOf(sexp));
OE.setText(String.valueOf(oexp));
RemainBudget.setText(String.valueOf(rbudget));
CheckedIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
private void displayshowHistory(long id) {
dbHelper.open();
Cursor cursor = dbHelper.getInfo(id);
if (cursor.moveToFirst()) {
//idDB = cursor.getLong(TrackerDAO.COL_ROWID);
name = cursor.getString(TrackerDAO.COL_NAME);
city = cursor.getString(TrackerDAO.COL_CITY);
reason = cursor.getString(TrackerDAO.COL_REASON);
startingdate = cursor.getString(TrackerDAO.COL_SOD);
arrivaldate = cursor.getString(TrackerDAO.COL_AD);
tbudget = cursor.getString(TrackerDAO.COL_BUDGET);
hexp = cursor.getInt(TrackerDAO.COL_HE);
texp = cursor.getInt(TrackerDAO.COL_TE);
fexp = cursor.getInt(TrackerDAO.COL_FE);
eexp = cursor.getInt(TrackerDAO.COL_EE);
sexp = cursor.getInt(TrackerDAO.COL_SE);
oexp = cursor.getInt(TrackerDAO.COL_OE);
rbudget = cursor.getInt(TrackerDAO.COL_REMAINBUDGET);
/*historyString = "Trip Name: " + tripname + "\n"
+ "City: " + city + "\n"
+ "Reason For travel: " + tripreason + "\n"
+ "Starting Date: " + sd + "\n"
+ "Date of Arrival: " + ad + "\n"
+ "Estimated Budget: " + tbudget + "\n"
+ "Hotel Rents: " + he + "\n"
+ "Tansport Fares: " + te + "\n"
+ "Food Costs: " + fe + "\n"
+ "Entertainment Spendings: " + ee + "\n"
+ "Shopping Expenditure: " + se + "\n"
+ "Other Expenses: " + oe + "\n"
+ "Remain Money: " + rbudget; */
}
dbHelper.close();
}
}
現在這裏是logcat的:
01-28 08:23:56.612: E/AndroidRuntime(1140): FATAL EXCEPTION: main
01-28 08:23:56.612: E/AndroidRuntime(1140): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.blackcat.triporganizer/com.blackcat.triporganizer.history.HistoryViewerActivity}: java.lang.NullPointerException
01-28 08:23:56.612: E/AndroidRuntime(1140): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
01-28 08:23:56.612: E/AndroidRuntime(1140): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
01-28 08:23:56.612: E/AndroidRuntime(1140): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-28 08:23:56.612: E/AndroidRuntime(1140): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
01-28 08:23:56.612: E/AndroidRuntime(1140): at android.os.Handler.dispatchMessage(Handler.java:99)
01-28 08:23:56.612: E/AndroidRuntime(1140): at android.os.Looper.loop(Looper.java:137)
01-28 08:23:56.612: E/AndroidRuntime(1140): at android.app.ActivityThread.main(ActivityThread.java:5103)
01-28 08:23:56.612: E/AndroidRuntime(1140): at java.lang.reflect.Method.invokeNative(Native Method)
01-28 08:23:56.612: E/AndroidRuntime(1140): at java.lang.reflect.Method.invoke(Method.java:525)
01-28 08:23:56.612: E/AndroidRuntime(1140): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-28 08:23:56.612: E/AndroidRuntime(1140): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-28 08:23:56.612: E/AndroidRuntime(1140): at dalvik.system.NativeStart.main(Native Method)
01-28 08:23:56.612: E/AndroidRuntime(1140): Caused by: java.lang.NullPointerException
01-28 08:23:56.612: E/AndroidRuntime(1140): at com.blackcat.triporganizer.history.HistoryViewerActivity.displayshowHistory(HistoryViewerActivity.java:92)
01-28 08:23:56.612: E/AndroidRuntime(1140): at com.blackcat.triporganizer.history.HistoryViewerActivity.onCreate(HistoryViewerActivity.java:63)
01-28 08:23:56.612: E/AndroidRuntime(1140): at android.app.Activity.performCreate(Activity.java:5133)
01-28 08:23:56.612: E/AndroidRuntime(1140): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-28 08:23:56.612: E/AndroidRuntime(1140): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
01-28 08:23:56.612: E/AndroidRuntime(1140): ... 11 more
我認爲你正在displayshowHistory method.The問題中的空指針異常可能會被初始化的對象在method.So請檢查是否有任何 –