0

我在开发我的 Android 应用程序时遇到了麻烦,我目前正在使用 Eclipse 和 Phidg​​et RFID。我的目标是在 Android 设备上的一段文本中显示 RFID 的 ID。

我已经设法在以下代码中通过 println 显示 ID。

   package myFood.myFood;

import com.phidgets.*;
import com.phidgets.event.*;
public class RFID {
static String x ="NULL";
public static final Object main(String args[]) throws Exception {
    RFIDPhidget rfid;
    rfid = new RFIDPhidget();
    rfid.openAny();

    //Begin the TagGained event, allowing for users to read the RFID values
    rfid.addTagGainListener(new TagGainListener()
    {
        public void tagGained(TagGainEvent oe)
        {
            Object y = (oe.getValue());
            x= y.toString();
        }
    });

    long StartTime,RunTime;
    StartTime=System.currentTimeMillis();
    do{
        RunTime=System.currentTimeMillis();
        if (x.equals("NULL")) {
            //Continue waiting for input
            }
        else
        StartTime = 10000; //Overload the result so the loop ends
    }
    while (RunTime-StartTime<5000);

    rfid.close();
    return x;
}

}

进而。

package myFood.myFood;

public class RFIDresult {

public static final Object main(String args[]) throws Exception {
    System.out.println("Results");
Object x = RFID.main(args);
System.out.println(x);
return x;
}
}

但是我希望 ID 显示在一段文本中,所以我尝试将第二段代码开发到 Android 中。

package myFood.myFood;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class AddFood  extends Activity {
    /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.addfood);



    Button mybutton = (Button) findViewById(R.id.Button1);
    mybutton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {

            String[] args = null;
            Object x = null;
            try {
                x = RFID.main(args);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

    TextView mytext=(TextView)findViewById(R.id.widget96);
    mytext.setText((CharSequence) x);


    }


    });
}

}

而这只会产生关闭力。我在这方面有点新手,我会感谢我得到的所有建议。


LogCat 报告;

ERROR/AndroidRuntime(519): FATAL EXCEPTION: main
ERROR/AndroidRuntime(519): java.lang.ExceptionInInitializerError
ERROR/AndroidRuntime(519):     at myFood.myFood.RFID.main(RFID.java:9)
ERROR/AndroidRuntime(519):     at myFood.myFood.AddFood$1.onClick(AddFood.java:26)<br/>
ERROR/AndroidRuntime(519):     at android.view.View.performClick(View.java:2408)
ERROR/AndroidRuntime(519):     at android.view.View$PerformClick.run(View.java:8816)
ERROR/AndroidRuntime(519):     at android.os.Handler.handleCallback(Handler.java:587)
ERROR/AndroidRuntime(519):     at android.os.Handler.dispatchMessage(Handler.java:92)
ERROR/AndroidRuntime(519):     at android.os.Looper.loop(Looper.java:123)
ERROR/AndroidRuntime(519):    at     android.app.ActivityThread.main(ActivityThread.java:4627)
ERROR/AndroidRuntime(519):     at java.lang.reflect.Method.invokeNative(Native Method)
ERROR/AndroidRuntime(519):     at java.lang.reflect.Method.invoke(Method.java:521)
ERROR/AndroidRuntime(519):     at om.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
ERROR/AndroidRuntime(519):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
ERROR/AndroidRuntime(519):     at dalvik.system.NativeStart.main(Native Method)
ERROR/AndroidRuntime(519): Caused by: java.lang.ExceptionInInitializerError: Library phidget21 not found
ERROR/AndroidRuntime(519): Could not locate the Phidget C library (libphidget21.so).
ERROR/AndroidRuntime(519): Make sure it is installed, and add it's path to LD_LIBRARY_PATH.
ERROR/AndroidRuntime(519):     at com.phidgets.Phidget.<clinit>(Phidget.java:34)
ERROR/AndroidRuntime(519):     ... 13 more
4

1 回答 1

0

您需要从“视图”参数中获取 myText。试试这个:

TextView mytext=(TextView)**view**.findViewById(R.id.widget96);
于 2012-01-03T19:12:28.443 回答