package cn.com.zj.usbdemo;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.sql.Date;
import java.text.SimpleDateFormat;
import zj.com.customize.sdk.Other;
import com.zj.command.sdk.Command;
import com.zj.command.sdk.PrintPicture;
import com.zj.command.sdk.PrinterCommand;
import cn.com.zj.usbdemo.R;
import com.zj.usbsdk.UsbController;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.hardware.usb.UsbDevice;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.Toast;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.DependsOn;
@ShortName("printdemo")
@DependsOn(values={"usbsdk"})
public class PrintDemo extends Activity implements OnClickListener{
import com.zj.usbsdk.UsbController;
static UsbController usbCtrl = null;
usbCtrl = new UsbController(this,mHandler);
public void connectusb (){
usbCtrl.close();
int i = 0;
for( i = 0 ; i < 8 ; i++ ){
dev = usbCtrl.getDev(u_infor[i][0],u_infor[i][1]);
if(dev != null)
break;
}
if( dev != null ){
if( !(usbCtrl.isHasPermission(dev))){
usbCtrl.getPermission(dev);
}else{
}
}
}
@SuppressLint("HandlerLeak") private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case UsbController.USB_CONNECTED:
Toast.makeText(getApplicationContext(), getString(R.string.msg_getpermission),
Toast.LENGTH_SHORT).show();
btnSend.setEnabled(true);
btn_test.setEnabled(true);
btnClose.setEnabled(true);
btn_printA.setEnabled(true);
btn_BMP.setEnabled(true);
btn_ChoseCommand.setEnabled(true);
btn_prtcodeButton.setEnabled(true);
btn_prtsma.setEnabled(true);
btn_prttableButton.setEnabled(true);
Simplified.setEnabled(true);
Korean.setEnabled(true);
big5.setEnabled(true);
thai.setEnabled(true);
btn_conn.setEnabled(false);
break;
default:
break;
}
}
};
Can you post the full error message?java.lang.NullPointerException
why ?
Don't wrap full activities. It will make things more complicated.
Can you post the full error message?
BA myba;
public void initialize(BA ba) // ba is a hidden parameter
{
myba = ba; //save it if you need to
Activity a = myba.activity; // get the Activity
h = new Handler(); // get a handler for the current thread
}
public void connectusb (){
// onCreate(null, null);
// usbCtrl.close();
usbCtrl = new UsbController(this,h);
u_infor = new int[8][2];
u_infor[0][0] = 0x1CBE;
u_infor[0][1] = 0x0003;
u_infor[1][0] = 0x1CB0;
u_infor[1][1] = 0x0003;
u_infor[2][0] = 0x0483;
u_infor[2][1] = 0x5740;
u_infor[3][0] = 0x0493;
u_infor[3][1] = 0x8760;
u_infor[4][0] = 0x0416;
u_infor[4][1] = 0x5011;
u_infor[5][0] = 0x0416;
u_infor[5][1] = 0xAABB;
u_infor[6][0] = 0x1659;
u_infor[6][1] = 0x8965;
u_infor[7][0] = 0x0483;
u_infor[7][1] = 0x5741;
// int i = 0;
// for( i = 0 ; i < 8 ; i++ ){
// dev = usbCtrl.getDev(u_infor[i][0],u_infor[i][1]);
// if(dev != null)
// break;
// }
//
// if( dev != null ){
// if( !(usbCtrl.isHasPermission(dev))){
//
// usbCtrl.getPermission(dev);
// }else{
//
//
//
// }
//}
}
The problem is that you wrapped the code as an activity. The only way to create activities is by starting them with StartActivity.
It will be simple to wrap a regular class instead.
BA myba;
public void initialize(BA ba) // ba is a hidden parameter
{
myba = ba; //save it if you need to
Activity a = myba.activity; // get the Activity
h = new Handler(); // get a handler for the current thread
}