我有一个课程,它创建了对NFC和两个活动的连接.它们都创建了该类的对象,因此可以连接到NFC.早些时候它以某种方式工作但现在我遇到了问题 - 我的应用程序在NewIntent上没有做任何事情,即使在第一个活动上也是如此.而不是它,我可以从内置应用程序"标签"(Nexus S)中看到"收集新标签".
我该怎么办?
类:
public NFCForegroundUtil(Activity activity)
{
super();
this.activity = activity;
mAdapter = NfcAdapter.getDefaultAdapter(activity
.getApplicationContext());
mPendingIntent = PendingIntent.getActivity(activity, 0, new Intent(
activity, activity.getClass())
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
IntentFilter ndef2 = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
IntentFilter ndef3 = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
try
{
ndef2.addDataType("*/*");
}
catch (MalformedMimeTypeException e)
{
throw new RuntimeException("fail", e);
}
mFilters = new IntentFilter[] {ndef, ndef2, ndef3 };
mTechLists = new String[][] { new String[] {
// android.nfc.tech.NfcV.class.getName(),
android.nfc.tech.NfcA.class.getName(),
android.nfc.tech.IsoDep.class.getName() } };
mAdapter.enableForegroundDispatch(this, mPendingIntent, …Run Code Online (Sandbox Code Playgroud) 我这里有一些不工作的代码:
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series);
JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, true, true, true);
ChartPanel chartpanel = new ChartPanel(chart);
chartpanel.setDomainZoomable(true);
jPanel4.setLayout(new BorderLayout());
jPanel4.add(chartpanel, BorderLayout.NORTH);
Run Code Online (Sandbox Code Playgroud)
所以问题是带有图表的jPanel4是不可见的.当我将图表面板添加到框架并使其可见时,它可以正常工作.
谁知道我的错误是什么?
我有字符串:
String str = "KITTEN";
Run Code Online (Sandbox Code Playgroud)
我想从它做一个byte [],但只是:
byte[] mybyte = new byte[] { 'K', 'I', 'T', 'T', 'E', 'N'}
Run Code Online (Sandbox Code Playgroud)
任何人都知道如何将String更改为该字节[]?我能找到的所有东西都是关于实际的转换 - 请注意我不希望有字符串的十六进制表示.
PS.问题的标题可能是错的 - 我很抱歉,不知道怎么写.
编辑:
byte[] myBytes = str.getBytes();
Run Code Online (Sandbox Code Playgroud)
显示:
byte[] display = new byte[] { 0x00, 0, 0, 'K', 'I', 'T'};
Run Code Online (Sandbox Code Playgroud)
工作,并显示:
byte[] display = new byte[] { 0x00, 0, 0, myBytes[0], myBytes[1], myBytes[2] };
Run Code Online (Sandbox Code Playgroud)
不起作用.我尝试通过NFC将其显示在连接到Android手机的设备屏幕上.你知道是什么原因造成的吗?
java.lang.ClassCastException:android.app.Application无法强制转换为com.example.project.DataDevice
我的代码:
public class Project extends Activity{
private boolean connection = false;
public Tag tagFromIntent = null;
private Button textRead;
private NFCForegroundUtil nfcForegroundUtil;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.project);
nfcForegroundUtil = new NFCForegroundUtil(this);
this.textRead= (Button) findViewById(R.id.button2);
initListeners();
}
private void initListeners() {
textRead.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
if (connection == true)
{
DataDevice dataDevice = (DataDevice) getApplication();
dataDevice.setCurrentTag(tagFromIntent);
IsoDep nfca = IsoDep.get(dataDevice.getCurrentTag());
try
{
byte[] read= new byte[] { 0x00};
byte[] ans = null;
nfca.setTimeout(2000); …Run Code Online (Sandbox Code Playgroud) 问题:有没有一种简单的方法可以使用jFrame上的向上/向下按钮对jList进行排序?我的JList存储图像文件的路径,并显示带有文件名的字符串.我想通过单击向上/向上按钮向下/向上移动元素.
这就是我所做的 - 效果是移动选择(蓝色区域),而不是元素.Button2是按钮"向上".
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
int indexOfSelected = jList1.getSelectedIndex();
File selectedFile = (File) jList1.getSelectedValue();
indexOfSelected = indexOfSelected - 1;
jList1.setSelectedIndex(indexOfSelected );
jList1.updateUI();
}
Run Code Online (Sandbox Code Playgroud)
这就是JList的创建方式:
public void openButtonActionPerformed() {
fc.setMultiSelectionEnabled(true);
int returnVal = fc.showDialog(null, "Open");
if (returnVal == JFileChooser.APPROVE_OPTION) {
file = fc.getSelectedFiles();
len = file.length;
System.out.println(len);
}
for (i=0; i<len; i++){
listModel.add(i, file[i]);
}
jList1.setModel(listModel);
jList1.updateUI();
}
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助和耐心 - 提前.我是个傻瓜:)