74行出错 ,nullpointException,帮我解答感激不尽,我想把这个数据传给service
public class pdrActivity extends Activity implements View.OnClickListener{
private Button wifi_btn,pdr_btn,photo_btn,other_btn;
EditText ed1,ed2,ed3;
TextView txt1,txt2,txt3,txt4,txt5;
Button startBtn,stopBtn;
Spinner spinner;
pdrService myservice;
pdrService.myBind mybind;
float[] sendmessage=new float[3];
Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pdr);
ed1=(EditText)findViewById(R.id.ed1_pdr);
ed2=(EditText)findViewById(R.id.ed2_pdr);
ed3=(EditText)findViewById(R.id.ed3_pdr);
txt1=(TextView)findViewById(R.id.txt1_pdr);
txt2=(TextView)findViewById(R.id.txt2_pdr);
txt3=(TextView)findViewById(R.id.txt3_pdr);
txt4=(TextView)findViewById(R.id.txt4_pdr);
txt5=(TextView)findViewById(R.id.txt5_pdr);
spinner=(Spinner)findViewById(R.id.spin_pdr);
startBtn=(Button)findViewById(R.id.start_pdr);
stopBtn=(Button)findViewById(R.id.stop_pdr);
wifi_btn=(Button)findViewById(R.id.btn1_main);
photo_btn=(Button)findViewById(R.id.btn3_main);
other_btn=(Button)findViewById(R.id.btn4_main);
startBtn.setOnClickListener(this);
stopBtn.setOnClickListener(this);
handler=new Handler();
setData();
// wifi_btn.setOnClickListener(this);
// photo_btn.setOnClickListener(this);
// other_btn.setOnClickListener(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.start_pdr:
Intent intent=new Intent(this,pdrService.class);
bindService(intent,conn,BIND_AUTO_CREATE);
handler.postDelayed(runnable,20000);
mybind.setData(sendmessage); //error line
break;
case R.id.stop_pdr:
if (myservice.serviceState=="onBind"){
Toast.makeText(this,"service关闭关闭关闭关闭",Toast.LENGTH_SHORT).show();
unbindService(conn);
}
}
}
private ServiceConnection conn=new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
System.out.print("service 连接");
mybind=(pdrService.myBind)service;
myservice=mybind.getService();
}
@Override
public void onServiceDisconnected(ComponentName name) {
}
};
public void setData(){
sendmessage[0]=1;
sendmessage[1]=1;
sendmessage[2]=1;
}
Runnable runnable=new Runnable() {
@Override
public void run() {
float[] inf=mybind.getInf();
if(inf==null){
Toast.makeText(pdrActivity.this,"空数据",Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(pdrActivity.this,"非空数据",Toast.LENGTH_SHORT).show();
}
txt1.setText(String.valueOf(inf[0]));
txt2.setText(String.valueOf(inf[1]));
txt3.setText(String.valueOf(inf[2]));
txt4.setText(String.valueOf(inf[3]));
txt5.setText(String.valueOf(inf[4]));
handler.postDelayed(this,20000);
}
};
}
下面的是我的service
public class pdrService extends Service implements SensorEventListener{
float[] inf=new float[5];
float[] infmation={0,0,0};
dataExchange dataexchange;
private myBind mybind=new myBind();
public static String serviceState="";
proceedThread thread;
@Override
public void onCreate() {
super.onCreate();
if (infmation!=null){
inf[0]=1;
inf[1]=1;
inf[2]=1;
}
else{
inf[0]=2;
inf[1]=2;
inf[2]=2;
}
thread=new proceedThread();
thread.start();
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
serviceState="onBind";
return mybind;
}
public class myBind extends Binder {
public float[] getInf(){
return inf;
}
public pdrService getService(){
return pdrService.this;
}
public void setData(float[] data){
pdrService.this.infmation=data;
}
}
private class proceedThread extends Thread{
public Handler myHandler;
public void run(){
Looper.prepare();
myHandler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what==1){
inf[0]+=1;
inf[1]+=1;
inf[2]+=1;
inf[3]+=1;
inf[4]+=1;
}
}
};
Looper.loop();
}
}
@Override
public void onSensorChanged(SensorEvent event) {
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
public void dataListener(dataExchange listener){
this.dataexchange=listener;
}
}
http://m.blog.csdn.net/article/details?id=8701621
没有行号,要人一行行数……