cari

Rumah  >  Soal Jawab  >  teks badan

java - 微博第三方登陆获取用户昵称头像的程序,真机虚拟机都运行不了

概述:
学过c,c++,刚接触android,没学过java。。此程序为网上搜的资料(照抄都不对很是丢人),编译过了,运行不了,实在不清楚哪里错,大神求教。资料地址:http://blog.csdn.net/u0102149...

User为自定义类,其余类和包copy自微博官方给的sdk

//MainActivity.java

public class MainActivity extends AppCompatActivity {

    private Button btnLogin;
    private TextView tvNickname;
    private TextView tvToken;
    private ImageView ivFigure;

    private AuthInfo authInfo;
    private SsoHandler mssoHandler;
    private Oauth2AccessToken mAccessToken;
    private IWeiboShareAPI wbshareapi;
    private User user;

    private boolean isLogined = false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        wbshareapi = WeiboShareSDK.createWeiboAPI(MainActivity.this,Constants.APP_KEY);

        initView();
    }
    private void initView(){

        btnLogin = (Button) findViewById(R.id.bt_login);
        tvNickname = (TextView) findViewById(R.id.tv_nickname);
        tvToken = (TextView) findViewById(R.id.tv_openid);
        ivFigure = (ImageView) findViewById(R.id.iv_figure);

        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(!isLogined) {
                    isLogined = true;

                    authInfo = new AuthInfo(MainActivity.this, Constants.APP_KEY,Constants.REDIRECT_URL,Constants.SCOPE);
                    mssoHandler = new SsoHandler(MainActivity.this,authInfo);
                    mssoHandler.authorize(new AuthListener());
                }else{
                    Toast.makeText(MainActivity.this,"已登录",Toast.LENGTH_SHORT).show();
                }

            }
        });

    }

    class AuthListener implements WeiboAuthListener {


        @Override
        public void onComplete(Bundle bundle) {

            mAccessToken = Oauth2AccessToken.parseAccessToken(bundle);
            String phonenum = mAccessToken.getPhoneNum();

            if(mAccessToken.isSessionValid()){
                AccessTokenKeeper.writeAccessToken(MainActivity.this,mAccessToken);
                Toast.makeText(MainActivity.this,"登录成功",Toast.LENGTH_SHORT).show();
            }else{
                String code = bundle.getString("code");
                String message = "登录失败";
                message = message + "code :"+ code;
                Toast.makeText(MainActivity.this,message,Toast.LENGTH_SHORT).show();

            }

            new Thread(new Runnable() {
                @Override
                public void run() {
                    UsersAPI mUsersApi = new UsersAPI(MainActivity.this,Constants.APP_KEY,mAccessToken);
                    Long uid = Long.parseLong(mAccessToken.getUid());
                    mUsersApi.show(uid, new mRequestListener());

                }
            }).start();
        }

        @Override
        public void onWeiboException(WeiboException e) {
            Toast.makeText(MainActivity.this,"exception:"+e.getMessage(),Toast.LENGTH_SHORT).show();

        }

        @Override
        public void onCancel() {
            Toast.makeText(MainActivity.this,"登录取消",Toast.LENGTH_SHORT).show();

        }

    }

    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if(msg.what==1){
                tvNickname.setText(user.getScreen_name());
                tvToken.setText(user.getId());
            }

        }
    };

    public class mRequestListener implements RequestListener {
        @Override
        public void onComplete(String s) {

            try{
                JSONObject jsonObject = new JSONObject(s);
                String id = jsonObject.getString("id");
                String nickname = jsonObject.getString("nickname");
                String figureUrl = jsonObject.getString("figureUrl");

                user = new User(id,nickname,figureUrl);
                Message message = Message.obtain();
                message.what = 1;
                handler.sendMessage(message);

            }catch (JSONException e){
                e.printStackTrace();
            }
        }

        @Override
        public void onWeiboException(WeiboException e) {

        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(mssoHandler !=null){
            mssoHandler.authorizeCallBack(requestCode,resultCode,data);
        }

    }

}
    //logcat
Could not find class 'android.os.PersistableBundle', referenced from method com.mmt.weibologin2.MainActivity.access$super
Could not find class 'android.media.session.MediaController', referenced from method com.mmt.weibologin2.MainActivity.access$super
Could not find class 'android.widget.Toolbar', referenced from method com.mmt.weibologin2.MainActivity.access$super
......
E/ActivityThread: Failed to find provider info for com.sina.weibo.sdkProvider
E/AndroidRuntime: FATAL EXCEPTION: Thread-93
E/libEGL: load_driver(/system/lib/egl/libGLES_emulation.so): dlopen failed: library "/system/lib/egl/libGLES_emulation.so" not found
E/PowerManagerService-JNI: Couldn't load power module (No such file or directory)
E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
E/ConsumerIrService: Can't open consumer IR HW Module, error: -2
.....
E/SoundPool: error loading /system/media/audio/ui/Lock.ogg
E/SoundPool: error loading /system/media/audio/ui/Unlock.ogg
E/FlpHardwareProvider: Error hw_get_module 'flp': -2
E/BluetoothAdapter: Bluetooth binder is null
E/dalvikvm: Could not find class 'hlo', referenced from method hln.a
E/SoundPool: error loading /system/media/audio/ui/Effect_Tick.ogg
E/SoundPool: error loading /system/media/audio/ui/KeypressStandard.ogg
....
E/StrictMode: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
                                                                  java.lang.Throwable: Explicit termination method 'close' not called
                                                                      at dalvik.system.CloseGuard.open(CloseGuard.java:184)
                                                                      at dalvik.system.DexFile.<init>(DexFile.java:113)
                                                                      at dalvik.system.DexFile.loadDex(DexFile.java:151)
                                                                      at dalvik.system.DexPathList.loadDexFile(DexPathList.java:266)
                                                                      at dalvik.system.DexPathList.makeDexElements(DexPathList.java:230)
                                                                      at dalvik.system.DexPathList.<init>(DexPathList.java:112)
                                                                      at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:48)
                                                                      at dalvik.system.DexClassLoader.<init>(DexClassLoader.java:57)
                                                                      at com.google.android.chimera.container.DexOptUtils.optimizeModule(:com.google.android.gms:86)
                                                                      at bcs.run(:com.google.android.gms:1726)
                                                                      at com.google.android.chimera.container.FileApkUtils.stageFileApksLocked(:com.google.android.gms:605)
                                                                      at com.google.android.chimera.container.FileApkUtils.stageFileApks(:com.google.android.gms:532)
                                                                      at com.google.android.gms.chimera.container.FileApkService.onHandleIntent(:com.google.android.gms:94)
                                                                      at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                      at android.os.Looper.loop(Looper.java:136)
                                                                      at android.os.HandlerThread.run(HandlerThread.java:61)
E/dalvikvm: Dex cache directory isn't writable: /data/dalvik-cache
E/ChimeraModuleLdr: Initialization failed for module com.google.android.play.games
                                                                        java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.chimera.GmsModuleInitializer" on path: DexPathList[[zip file "/system/app/PlayGames.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
                                                                            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                            at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
                                                                            at com.google.android.chimera.container.internal.DelegateLastPathClassLoader.loadClass(:com.google.android.gms:34)
                                                                            at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
                                                                            at com.google.android.gms.chimera.container.GmsModuleApi.onApkLoaded(:com.google.android.gms:86)
                                                                            at com.google.android.chimera.container.internal.ModuleLoader.loadModuleIntoContext(:com.google.android.gms:125)
                                                                            at com.google.android.chimera.container.ConfigurationManager.loadModule(:com.google.android.gms:613)
                                                                            at com.google.android.chimera.container.ConfigurationManager.loadModule(:com.google.android.gms:488)
                                                                            at com.google.android.chimera.container.BroadcastReceiverProxy.onReceive(:com.google.android.gms:71)
                                                                            at android.app.ActivityThread.handleReceiver(ActivityThread.java:2419)
                                                                            at android.app.ActivityThread.access$1700(ActivityThread.java:135)
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1272)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                            at android.os.Looper.loop(Looper.java:136)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:5017)
                                                                            at java.lang.reflect.Method.invokeNative(Native Method)
                                                                            at java.lang.reflect.Method.invoke(Method.java:515)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
                                                                            at dalvik.system.NativeStart.main(Native Method)
                                                                            Suppressed: java.io.IOException: unable to open DEX file
                                                                            at dalvik.system.DexFile.openDexFileNative(Native Method)
                                                                            at dalvik.system.DexFile.openDexFile(DexFile.java:296)
                                                                            at dalvik.system.DexFile.<init>(DexFile.java:80)
                                                                            at dalvik.system.DexFile.<init>(DexFile.java:59)
                                                                            at dalvik.system.DexPathList.loadDexFile(DexPathList.java:263)
                                                                            at dalvik.system.DexPathList.makeDexElements(DexPathList.java:230)
                                                                            at dalvik.system.DexPathList.<init>(DexPathList.java:112)
                                                                            at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:48)
                                                                            at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:65)
                                                                            at com.google.android.chimera.container.internal.DelegateLastPathClassLoader.<init>(:com.google.android.gms:16)
                                                                            at com.google.android.chimera.container.InstalledApk.getCode(:com.google.android.gms:79)
                                                                            at com.google.android.chimera.container.internal.ModuleLoader.loadModuleIntoContext(:com.google.android.gms:103)
                                                                                    ... 14 more
                                                                                    E/CheckinTask: Checkin failed: https://android.clients.google.com/checkin (request #0): java.net.SocketTimeoutException: failed to connect to android.clients.google.com/74.125.204.101 (port 443) after 120000ms
                                                                                   E/ActivityThread: Failed to find provider info for com.google.android.wearable.settings
                                                                                    E/GCM: Missing checkin config file
                                                                                    E/GCM: Missing checkin config file
                                                                                    .....
                                                                                    

Manifest

大家讲道理大家讲道理2807 hari yang lalu840

membalas semua(1)saya akan balas

  • 巴扎黑

    巴扎黑2017-04-18 09:37:42

    Siarkan AndroidManifest.xml anda?


     <activity  
                android:name="com.sina.weibo.sdk.component.WeiboSdkBrowser"  
                android:configChanges="keyboardHidden|orientation"  
                android:exported="false"  
                android:windowSoftInputMode="adjustResize" >  
            </activity>  

    Adakah okey jika anda tidak menambah ini?


    Klik kanan fail balang Sina dan pilih tambah sebagai pustaka

    balas
    0
  • Batalbalas