我已经编写了一个应用程序,我在其中获取 facebook 好友列表,但现在我决定在我现有的应用程序中添加一个新功能 - 多个选项卡,
而且我还编写了必要的代码来获得它,但是每当我运行我的程序时 - 不幸的是应用程序已经停止
我想下面的行正在制造问题,但没有办法解决这个问题?
this.setDisplayShowIconEnabled(false);
ActionBarActivity.java:
protected void setDisplayShowIconEnabled(boolean bool) {
mActionBarHelper.setDisplayShowIconEnabled(bool);
}
ActionBarHelperICS.java:
@Override
public void setDisplayShowIconEnabled(boolean bool) {
mActivity.getActionBar().setDisplayShowHomeEnabled(bool);
}
闪屏.java:
public void onRequestReceived(int result, String message) {
Log.d(LOG_TAG, "onRequestReceived(" + result + ")");
if(isFinishing())
return;
switch (result) {
case FacebookRequest.COMPLETED:
Intent intent = new Intent(this, Main.class);
intent.putExtra("FRIENDS", message);
while (System.currentTimeMillis() - startTime < DELAY) {
try { Thread.sleep(50); } catch (Exception e) {}
}
startActivityForResult(intent, FRIENDS_LIST_ACTIVITY);
isLoadingFriends = false;
break;
case FacebookRequest.IO_EXCEPTION:
case FacebookRequest.FILE_NOT_FOUND_EXCEPTION:
case FacebookRequest.MALFORMED_URL_EXCEPTION:
case FacebookRequest.FACEBOOK_ERROR:
FacebookUtility.displayMessageBox(this, this.getString(R.string.friends_error));
onButton();
break;
}
}
主.java:
public class Main extends TabActivity {
private TabHost tabHost;
private final String FRIENDS_TAB = "friends";
private final String MONTH_TAB = "month";
private final String WEEK_TAB = "week";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost = (TabHost) findViewById(android.R.id.tabhost);
TabSpec contactSpec = tabHost.newTabSpec(FRIENDS_TAB).setIndicator(
"FB Friends", getResources().getDrawable(R.drawable.friends))
.setContent(new Intent(Main.this, FriendsList.class));
TabSpec monthSpec = tabHost.newTabSpec(MONTH_TAB).setIndicator(
"This Month", getResources().getDrawable(R.drawable.month))
.setContent(new Intent(Main.this, FriendsList.class));
TabSpec weekSpec = tabHost.newTabSpec(WEEK_TAB).setIndicator(
"This Week", getResources().getDrawable(R.drawable.week))
.setContent(new Intent(Main.this, FriendsList.class));
tabHost.addTab(contactSpec);
tabHost.addTab(monthSpec);
tabHost.addTab(weekSpec);
tabHost.setCurrentTab(0);
}
}
好友列表.java:
public class FriendsList extends ActionBarActivity implements FacebookRequest, OnItemClickListener {
private static String LOG_TAG = "FriendsList";
private static JSONArray jsonArray;
private static ListView friendsList;
private Handler mHandler;
private Button saveGreeting;
@Override
public void onCreate(Bundle savedInstanceState) {
mHandler = new Handler();
super.onCreate(savedInstanceState);
try {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
} catch (Exception e) {}
setContentView(R.layout.friends_list_screen);
try {
setProgressBarIndeterminateVisibility(false);
setProgressBarInDVisibility(false);
} catch (Exception e) {}
this.setDisplayShowIconEnabled(false);
init();
saveGreeting = (Button) findViewById(R.id.greeting);
saveGreeting.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
customGreeting(v);
}
});
}
日志报告:
01-14 16:18:02.954: E/AndroidRuntime(960): FATAL EXCEPTION: main
01-14 16:18:02.954: E/AndroidRuntime(960): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chr.tatu.sample.friendslist/com.chr.tatu.sample.friendslist.Main}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chr.tatu.sample.friendslist/com.chr.tatu.sample.friendslist.FriendsList}: java.lang.NullPointerException
01-14 16:18:02.954: E/AndroidRuntime(960): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-14 16:18:02.954: E/AndroidRuntime(960): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-14 16:18:02.954: E/AndroidRuntime(960): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-14 16:18:02.954: E/AndroidRuntime(960): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-14 16:18:02.954: E/AndroidRuntime(960): at android.os.Handler.dispatchMessage(Handler.java:99)
01-14 16:18:02.954: E/AndroidRuntime(960): at android.os.Looper.loop(Looper.java:137)
01-14 16:18:02.954: E/AndroidRuntime(960): at android.app.ActivityThread.main(ActivityThread.java:5039)
01-14 16:18:02.954: E/AndroidRuntime(960): at java.lang.reflect.Method.invokeNative(Native Method)
01-14 16:18:02.954: E/AndroidRuntime(960): at java.lang.reflect.Method.invoke(Method.java:511)
01-14 16:18:02.954: E/AndroidRuntime(960): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-14 16:18:02.954: E/AndroidRuntime(960): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-14 16:18:02.954: E/AndroidRuntime(960): at dalvik.system.NativeStart.main(Native Method)
01-14 16:18:02.954: E/AndroidRuntime(960): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chr.tatu.sample.friendslist/com.chr.tatu.sample.friendslist.FriendsList}: java.lang.NullPointerException
01-14 16:18:02.954: E/AndroidRuntime(960): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-14 16:18:02.954: E/AndroidRuntime(960): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2023)
01-14 16:18:02.954: E/AndroidRuntime(960): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
01-14 16:18:02.954: E/AndroidRuntime(960): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
01-14 16:18:02.954: E/AndroidRuntime(960): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:749)
01-14 16:18:02.954: E/AndroidRuntime(960): at android.widget.TabHost.setCurrentTab(TabHost.java:413)
01-14 16:18:02.954: E/AndroidRuntime(960): at android.widget.TabHost.addTab(TabHost.java:240)
01-14 16:18:02.954: E/AndroidRuntime(960): at com.chr.tatu.sample.friendslist.Main.onCreate(Main.java:37)
01-14 16:18:02.954: E/AndroidRuntime(960): at android.app.Activity.performCreate(Activity.java:5104)
01-14 16:18:02.954: E/AndroidRuntime(960): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-14 16:18:02.954: E/AndroidRuntime(960): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-14 16:18:02.954: E/AndroidRuntime(960): ... 11 more
01-14 16:18:02.954: E/AndroidRuntime(960): Caused by: java.lang.NullPointerException
01-14 16:18:02.954: E/AndroidRuntime(960): at com.chr.tatu.sample.friendslist.ActionBarHelperICS.setDisplayShowIconEnabled(ActionBarHelperICS.java:38)
01-14 16:18:02.954: E/AndroidRuntime(960): at com.chr.tatu.sample.friendslist.ActionBarActivity.setDisplayShowIconEnabled(ActionBarActivity.java:85)
01-14 16:18:02.954: E/AndroidRuntime(960): at com.chr.tatu.sample.friendslist.FriendsList.onCreate(FriendsList.java:56)
01-14 16:18:02.954: E/AndroidRuntime(960): at android.app.Activity.performCreate(Activity.java:5104)
01-14 16:18:02.954: E/AndroidRuntime(960): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-14 16:18:02.954: E/AndroidRuntime(960): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-14 16:18:02.954: E/AndroidRuntime(960): ... 21 more