私はFabricプラグインを使用しています。私はちょうどログインボタンを含む別のXMLレイアウトファイルにレイアウトがあるポップアップウィンドウにTwitterログインボタンを埋め込みたい。Androidファブリック - ヌルポインタ例外:ポップアップウィンドウレイアウトのボタン
ログインボタンは、それを開始する活動のonCreate()
関数の内部で呼ばれますが、私にloginButtonでnullポインタ例外を警告logcat次の関数で定義されています。
XMLのボタンのIDに問題はありません。それのどこが悪いんだい?
ありがとうございます!
loginButton = (TwitterLoginButton) findViewById(R.id.btn_twitter_login);
loginButton.setCallback(new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> result) {
// The TwitterSession is also available through:
// Twitter.getInstance().core.getSessionManager().getActiveSession()
TwitterSession session = result.data;
// TODO: Remove toast and use the TwitterSession's userID
// with your app's user model
String msg = "@" + session.getUserName() + " logged in! (#" + session.getUserId() + ")";
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}
@Override
public void failure(TwitterException exception) {
Log.d("TwitterKit", "Login with Twitter failure", exception);
}
});
をそしてのonCreate()メソッドの上に置く:
private void TwitterLoginBtn() {
btn_twitter = (Button) findViewById(R.id.btn_twitter);
btn_twitter.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.twitter_login, null);
TWin = new PopupWindow(
popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
//LinearLayout popLayout = (LinearLayout)getLayoutInflater().inflate(R.layout.twitter_login, null);
//TWin = new PopupWindow(ShotActivity1.this);
//TWin.setContentView(popLayout);
loginButton = (TwitterLoginButton) findViewById(R.id.btn_twitter_login);
loginButton.setCallback(new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> result) {
// The TwitterSession is also available through:
// Twitter.getInstance().core.getSessionManager().getActiveSession()
TwitterSession session = result.data;
// TODO: Remove toast and use the TwitterSession's userID
// with your app's user model
String msg = "@" + session.getUserName() + " logged in! (#" + session.getUserId() + ")";
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}
@Override
public void failure(TwitterException exception) {
Log.d("TwitterKit", "Login with Twitter failure", exception);
}
});
Button btn_closeTwitter = (Button)findViewById(R.id.btn_closeT);
btn_closeTwitter.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
TWin.dismiss();
}
});
TWin.setBackgroundDrawable(null);
TWin.showAsDropDown(v, 0, 0);
}
});
雅がお役に立てば幸いです。私はそれも知っていないが、logcatはボタン自体がnullだと言った。なぜ私は不思議です。 – Anndexi9
正しい場合は、正解とマークできますか?私はあなたがカスタムbuttomを追加しようとしていると思いますよね?私は動作しないかもしれない、元のTwitterのbuttomを使用します。 twitterbuttomを宣言する前にあなたのカスタムbuttomをクリックしているかもしれません... – Jaco