当前位置: 代码迷 >> Android >> android AIDL 调用空指针,求好手解答
  详细解决方案

android AIDL 调用空指针,求好手解答

热度:415   发布时间:2016-05-01 13:28:02.0
android AIDL 调用空指针,求高手解答
今天写了一个AIDL的需求,但是调用AIDL文件方法异常,请哪位高手,帮忙看一下,谢谢!!!

①taobaoLoginClientA

com.taobao.platformservice
---ITBPlatformService.aidl
com.taobao.taobaologinclient
---LoginContext.java
---MainActivity.java

Java code
interface ITBPlatformService {    boolean isLogin();        boolean executeLogin();        void Logout();    }


Java code
public class LoginContext {        public static String packageName ="com.taobao.taobaologinclient";}


Java code
public class MainActivity extends Activity {    private EditText usernameET, passwordET;    private TextView textView;    private Button loginB, logoutB;    private ITBPlatformService itbPlatformService;    private ServiceConnection connection = new ServiceConnection() {        public void onServiceDisconnected(ComponentName name) {            // TODO Auto-generated method stub            itbPlatformService = null;        }        public void onServiceConnected(ComponentName name, IBinder service) {            // TODO Auto-generated method stub            itbPlatformService = ITBPlatformService.Stub.asInterface(service);        }    };    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);                usernameET = (EditText) this.findViewById(R.id.editText1);        passwordET = (EditText) this.findViewById(R.id.editText2);        textView = (TextView) this.findViewById(R.id.textView1);        loginB = (Button) this.findViewById(R.id.button1);        logoutB = (Button) this.findViewById(R.id.button2);        Intent intent = new Intent();        intent.setAction("com.taobao.platformservice.TBPlatformService");        bindService(intent, connection, Service.BIND_AUTO_CREATE);                        try {                        //空指针地方            if(itbPlatformService.isLogin()){                textView.setText("已登陆");            }else{                textView.setText("未登陆");            }        } catch (RemoteException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }                        loginB.setOnClickListener(new OnClickListener() {            public void onClick(View arg0) {                // TODO Auto-generated method stub                String username = usernameET.getText().toString().trim();                String password = passwordET.getText().toString().trim();                if (username == null || password == null) {                    Toast.makeText(getApplicationContext(), "请重新输入账号与密码",                            Toast.LENGTH_SHORT).show();                    usernameET.setText("");                    passwordET.setText("");                }                                                try {                    itbPlatformService.executeLogin();                } catch (RemoteException e) {                    // TODO Auto-generated catch block                    e.printStackTrace();                }            }        });        logoutB.setOnClickListener(new OnClickListener() {            public void onClick(View arg0) {                // TODO Auto-generated method stub                try {                    itbPlatformService.Logout();                } catch (RemoteException e) {                    // TODO Auto-generated catch block                    e.printStackTrace();                }            }        });    }    @Override    protected void onDestroy() {        // TODO Auto-generated method stub        super.onDestroy();        this.unbindService(connection);        try {            itbPlatformService.Logout();        } catch (RemoteException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }    }
  相关解决方案