package android.serialport.sample;import android.serialport.sample.VMC_Comm_Package_Class;import java.nio.Buffer;
/**
* Created by kdx on 2018/1/30.
*/public class VMC_Comm_Tx_Class {// public class LineUp{
// byte[] Buffer;/*发送数据缓冲区*/
// byte Index;/*发送数据计数器*/
// }
byte[] Buffer;
byte Index;
public void VMC_Comm_Tx_Class(){
byte inc,data=0;
this.RepeatNum = 0;
this.WaitResponse =0;
this.WaitResponseTimeout =0;
byte[] Buffer = new byte[1024];
Index =0;
// lineUps[0].Buffer = new byte[1024];
//
// lineUps[0].Index = 0;
// lineUps[1].Buffer = new byte[1024];
// lineUps[1].Index = 0;
// for(int i=0;i<1024;i++) {
// lineUps[0].Buffer[i] =0x33;
// lineUps[1].Buffer[i] =0x33;
// }
}
public void VMC_Comm_Package_Pack(byte inc,byte data){ Buffer[inc] = data;
//lineUps[0].Buffer[inc] = data;
}
public byte[] VMC_Comm_Package_Data(){
return Buffer;
}
/*
**设置消息包的长度
*/
public void VMC_Comm_Package_set_Index(byte num,byte len){
switch (num){
case 0:
{
Index = len;
}break;
case 1:
{
Index = len;
}
}
}
/*
**获取消息包的长度
*/
public byte VMC_Comm_Package_get_Index(byte num){
byte i =0;
switch (num){
case 0:
{
//i = lineUps[0].Index;
i=Index;
}
break;
case 1:{
//i= lineUps[1].Index ;
i=Index;
}
break;
}
return i;
} byte RepeatNum;/*重发的次数*/
byte WaitResponse;/* 等待PC机应答标志*/
int WaitResponseTimeout;/*等待应答的超时时间*/
//LineUp[] lineUps = new LineUp[2];
}
代码如上,小弟刚开始搞java 学的不太扎实,找了一天没找到哪错了,求大神
编译成功,但是运行时闪退 logcat 提示如下信息。Caused by: java.lang.NullPointerException
at android.serialport.sample.VMC_Comm_Tx_Class.VMC_Comm_Package_Pack(VMC_Comm_Tx_Class.java:41)
at android.serialport.sample.MainMenu.onCreate(MainMenu.java:52)
Buffer[inc] = data 这句话就是第41行,不知道这句话有什么错吗?谢谢。
/**
* Created by kdx on 2018/1/30.
*/public class VMC_Comm_Tx_Class {// public class LineUp{
// byte[] Buffer;/*发送数据缓冲区*/
// byte Index;/*发送数据计数器*/
// }
byte[] Buffer;
byte Index;
public void VMC_Comm_Tx_Class(){
byte inc,data=0;
this.RepeatNum = 0;
this.WaitResponse =0;
this.WaitResponseTimeout =0;
byte[] Buffer = new byte[1024];
Index =0;
// lineUps[0].Buffer = new byte[1024];
//
// lineUps[0].Index = 0;
// lineUps[1].Buffer = new byte[1024];
// lineUps[1].Index = 0;
// for(int i=0;i<1024;i++) {
// lineUps[0].Buffer[i] =0x33;
// lineUps[1].Buffer[i] =0x33;
// }
}
public void VMC_Comm_Package_Pack(byte inc,byte data){ Buffer[inc] = data;
//lineUps[0].Buffer[inc] = data;
}
public byte[] VMC_Comm_Package_Data(){
return Buffer;
}
/*
**设置消息包的长度
*/
public void VMC_Comm_Package_set_Index(byte num,byte len){
switch (num){
case 0:
{
Index = len;
}break;
case 1:
{
Index = len;
}
}
}
/*
**获取消息包的长度
*/
public byte VMC_Comm_Package_get_Index(byte num){
byte i =0;
switch (num){
case 0:
{
//i = lineUps[0].Index;
i=Index;
}
break;
case 1:{
//i= lineUps[1].Index ;
i=Index;
}
break;
}
return i;
} byte RepeatNum;/*重发的次数*/
byte WaitResponse;/* 等待PC机应答标志*/
int WaitResponseTimeout;/*等待应答的超时时间*/
//LineUp[] lineUps = new LineUp[2];
}
代码如上,小弟刚开始搞java 学的不太扎实,找了一天没找到哪错了,求大神
编译成功,但是运行时闪退 logcat 提示如下信息。Caused by: java.lang.NullPointerException
at android.serialport.sample.VMC_Comm_Tx_Class.VMC_Comm_Package_Pack(VMC_Comm_Tx_Class.java:41)
at android.serialport.sample.MainMenu.onCreate(MainMenu.java:52)
Buffer[inc] = data 这句话就是第41行,不知道这句话有什么错吗?谢谢。
解决方案 »
- Oracle VM VirtualBox 安装android-x86-2.2出错
- 弱弱地问一下,android下有声读物和电子书的开发工具是什么?
- 怎么计算代码运行所需的时间?
- Build Windows版的Android SDK 问题
- 混淆编译怎么编写proguard.flags文件
- 新手求大神!关于TextView问题
- 动态的RelativeLayout对象如何显示出来?
- android启动页实现
- 请问full Init JPEG decoder failed -10这个错误怎么解决?
- RatingBar的父类@android:style/Widget.RatingBar.Small找不到
- 安卓自定义View问题 思路
- RxJava2用Observable.fromIterable时可以设置线程调度吗?
VMC_Comm_Tx_Class(){
...
//byte[] Buffer = new byte[1024]; 这句相当于重新定义了变量
Buffer = new byte[1024];
...
}