我正在尝试这两个库在我的 android 应用程序NewQuickAction和NewQuickAction3D中创建一个按钮菜单。
使用它们的代码是一样的!但是,如果我使用 NewQuickAction,它可以正常工作,相反,如果我更改项目中的外部库并使用 NewQuickAction3D,它就不起作用并返回此错误:
致命异常:net.londatiga.android.QuickAction.addActionItem(QuickAction.java:213) 的主要 java.lang.NullPointerException
代码是:
ActionItem myLocationItem = new ActionItem(ID_MY_LOCATION, "Mia posizione", getResources().getDrawable(R.drawable.location));
ActionItem nearestItem = new ActionItem(ID_NEAREST_STATION, "Stazione piu vicina", getResources().getDrawable(R.drawable.location));
ActionItem activeGpsItem = new ActionItem(ID_ACTIVE_GPS, "Attiva GPS", getResources().getDrawable(R.drawable.gps));
// constructor for NewQuickAction
final QuickAction mQuickAction = new QuickAction(this );
// constructor for NewQuickAction3D
//final QuickAction mQuickAction = new QuickAction(this, QuickAction.VERTICAL);
mQuickAction.addActionItem(myLocationItem);
mQuickAction.addActionItem(nearestItem);
mQuickAction.addActionItem(activeGpsItem);
//setup the action item click listener
mQuickAction.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() {
@Override
public void onItemClick(QuickAction quickAction, int pos, int actionId) {
if (actionId == ID_MY_LOCATION) {
Toast.makeText(getApplicationContext(), "I have no info this time", Toast.LENGTH_SHORT).show();
} else if (actionId == ID_NEAREST_STATION ) {
Toast.makeText(getApplicationContext(), "I have no info this time", Toast.LENGTH_SHORT).show();
} else {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
}
});
ImageButton buttonMenu = (ImageButton) findViewById(R.id.button_menu);
buttonMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mQuickAction.show(v);
}
});
似乎用于创建新 ActionItem 的图标和文本在 NewQuickAction3D 中不可见
如果我将库作为普通项目运行(这些库也是演示项目),它们可以正常工作。
有什么想法吗?