shareSDK第三方登录,返回了用户登录信息,但是一直报空指针异常,可是有返回值 -问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

shareSDK第三方登录,返回了用户登录信息,但是一直报空指针异常,可是有返回值

2016-05-30 09:59:49 3475 0

这是我的代码,先点击一个图片按钮,然后跳转到授权界面,当授权完成的时候,再把值返回在这个类里面,但是运行的时候一直报这句left_menu_fragment_textview.setText(userInfo.getUserName());是空指针异常,这是怎么回事

public class LeftMenuFragment extends BaseFragment {
 private ImageButton left_menu_fragment_imagebutton;
 private ListView left_menu_fragment_listview;
 private String[] itemname = new String[] { "设置文字大小", "收藏", "检查更新" };
 /************************************ 后面增加的方法 **********************************************/
 private OnLoginListener signupListener;
 private Platform platform;
private String picturePath;
private UserInfo userInfo = new UserInfo();
/** 加载用户icon */
private static final int LOAD_USER_ICON = 2;
/** 图片名字 */
private static final String PICTURE_NAME = "userIcon.jpg";
private TextView left_menu_fragment_textview;

/**********************************************************************************/

@Override
public View initview() {
    View view = View.inflate(mActivity, R.layout.left_menu_fragment, null);

    left_menu_fragment_imagebutton = (ImageButton) view
            .findViewById(R.id.left_menu_fragment_imagebutton);
    left_menu_fragment_listview = (ListView) view
            .findViewById(R.id.left_menu_fragment_listview);
    left_menu_fragment_textview = (TextView) view
            .findViewById(R.id.left_menu_fragment_textview);
    left_menu_fragment_listview.setAdapter(new myListAdapter());
    left_menu_fragment_imagebutton
            .setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Log.i("pan", "已经点击跳转界面");
                    Intent intent = new Intent();
                    intent.setClass(mActivity,
                            AuthorizationLoginActivity.class);
                    mActivity.startActivity(intent);

                }
            });
    return view;
}

/**
 * 初始化数据
 */
@Override
public void initData() {

    if (platform != null) {
        userInfo.setUserIcon(platform.getDb().getUserIcon());
        userInfo.setUserName(platform.getDb().getUserName());

        Log.i("pan", "leftMenuFragment中的username" + userInfo.getUserName());
        Log.i("pan", "leftMenuFragment中的icon" + userInfo.getUserIcon());

        if (userInfo.getUserName() != null) {
            Log.i("pan", "leftMenuFragment中的username222222" + userInfo.getUserName());

            left_menu_fragment_textview.setText(userInfo.getUserName());
        }
    }
    if (!TextUtils.isEmpty(userInfo.getUserIcon())) {
        Log.i("pan", "执行进入了获取icon方法吗");
        loadIcon();
    }
    // 初始化照片保存地址
    if (Environment.getExternalStorageState().equals(
            Environment.MEDIA_MOUNTED)) {
        String thumPicture = Environment.getExternalStorageDirectory()
                .getAbsolutePath()
                + "/"
                + mActivity.getPackageName()
                + "/download";
        File pictureParent = new File(thumPicture);
        File pictureFile = new File(pictureParent, PICTURE_NAME);

        if (!pictureParent.exists()) {
            pictureParent.mkdirs();
        }
        try {
            if (!pictureFile.exists()) {
                pictureFile.createNewFile();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        picturePath = pictureFile.getAbsolutePath();
        Log.e("picturePath ==>>", picturePath);
    } else {
        Log.e("change user icon ==>>", "there is not sdcard!");
    }

    // Bundle bundle = mActivity.getIntent().getExtras();
    // if (bundle != null) {
    //
    // Log.i("pan", "LeftMenuFragment中的res值:" + bundle.get("myMap"));
    // Map<String, Object> hashmap = (Map<String, Object>)
    // bundle.getSerializable("myMap");
    // String name = (String) hashmap.get("nickname");
    // Log.i("pan", "LeftMenuFragment中的res值:" + hashmap);
    // Log.i("pan", "LeftMenuFragment中的name值:" + name);
    // }
}

private Handler handler = new Handler() {
    public void handleMessage(Message msg) {
        switch (msg.what) {

        case LOAD_USER_ICON:
            left_menu_fragment_imagebutton.setImageURI(Uri
                    .parse(picturePath));
            break;
        default:
            break;
        }
    };
};

/**
 * 加载头像
 */
public void loadIcon() {
    final String imageUrl = platform.getDb().getUserIcon();
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                URL picUrl = new URL(imageUrl);
                Bitmap userIcon = BitmapFactory.decodeStream(picUrl
                        .openStream());
                FileOutputStream b = null;
                try {
                    b = new FileOutputStream(picturePath);
                    userIcon.compress(Bitmap.CompressFormat.JPEG, 100, b);// 把数据写入文件
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } finally {
                    try {
                        b.flush();
                        b.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                userInfo.setUserIcon(picturePath);

                Message msg = new Message();
                msg.what = LOAD_USER_ICON;
                // UIHandler.sendMessage(msg);

                handler.sendMessage(msg);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();
}

public boolean handleMessage(Message msg) {
    switch (msg.what) {

    case LOAD_USER_ICON:
        left_menu_fragment_imagebutton.setImageURI(Uri.parse(picturePath));
        break;
    default:
        break;
    }
    return false;
}

/**
 * listview的适配器
 *
 * @author Administrator
 *
 */
class myListAdapter extends BaseAdapter {

    private TextView text;

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return itemname.length;
    }

    @Override
    public Object getItem(int position) {
        return itemname[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(mActivity,
                    R.layout.left_menu_fragment_listview, null);
        }
        text = (TextView) convertView
                .findViewById(R.id.left_menu_fragment_listview_textview);
        text.setText(itemname[position]);
        return convertView;
    }

}

/****************************************************************************************/

/** 设置授权回调,用于判断是否进入注册 */
public void setOnLoginListener(OnLoginListener l) {
    this.signupListener = l;
}

public void setPlatform(String platName) {
    Log.i("pan", "platName的值为:" + platName);
    platform = ShareSDK.getPlatform(platName);
    initData();

}

这下面是打印的值:

10-30 09:11:52.480: I/pan(8062): leftMenuFragment中的username额路的快乐
 10-30 09:11:52.480: I/pan(8062): leftMenuFragment中的iconhttp://q.qlogo.cn/qqapp/100371282/C9F7933B7F1457206982CCF2EC3548F9/40
 10-30 09:11:52.480: I/pan(8062): leftMenuFragment中的username222222额路的快乐
 10-30 09:11:52.480: I/pan(8062): 执行进入了获取icon方法吗

这下面是错误的提示:

10-30 09:11:52.490: E/AndroidRuntime(8062): java.lang.NullPointerException
 10-30 09:11:52.490: E/AndroidRuntime(8062): at com.pan.foucstoday.fragment.LeftMenuFragment.initData(LeftMenuFragment.java:121)
 10-30 09:11:52.490: E/AndroidRuntime(8062): at com.pan.foucstoday.fragment.LeftMenuFragment.setPlatform(LeftMenuFragment.java:270)
 10-30 09:11:52.490: E/AndroidRuntime(8062): at com.pan.foucstoday.AuthorizationLoginActivity.handleMessage(AuthorizationLoginActivity.java:201)
 10-30 09:11:52.490: E/AndroidRuntime(8062): at com.mob.tools.utils.UIHandler.handleMessage(Unknown Source)
 10-30 09:11:52.490: E/AndroidRuntime(8062): at com.mob.tools.utils.UIHandler.access$000(Unknown Source)
取消 提交回答
全部回答(0)
相关问答

1

回答

对JDK的安装有什么建议呢?

2022-04-01 14:20:38 234浏览量 回答数 1

1

回答

我们昨天使用flink 1.12提交任务到yarn时,遇到个比较奇怪的问题

2021-12-08 10:56:56 460浏览量 回答数 1

1

回答

Sublime的安装路径能带特殊字符吗?

2021-10-31 10:06:12 136浏览量 回答数 1

1

回答

自动装箱、自动拆箱是Jdk什么版本添加的功能

2021-01-08 14:05:42 300浏览量 回答数 1

1

回答

请教各位,大家公司springcloud服务间调用用的什么?feign?openfeign#Java

2020-07-15 16:33:05 467浏览量 回答数 1

1

回答

关于flink读取json的问题

2020-04-01 15:50:36 3799浏览量 回答数 1

2

回答

是否可以将flink部署在运行在JDK1.7的YARN上?

2019-04-26 20:22:39 4105浏览量 回答数 2

1

回答

修改绑定的手机号码时提示:此手机号码绑定的账户数已达上限

2018-07-16 16:42:36 4532浏览量 回答数 1

5

回答

如何在网上修改电信宽带上网账号密码?

2018-02-28 21:32:09 9386浏览量 回答数 5

4

回答

新用户10点领取免费ECS时,提示资格账号异常,请更换账号参与,谢谢!

2017-08-07 10:04:13 3741浏览量 回答数 4
+关注
2
文章
9426
问答
问答排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载