0

I am having trouble with developing my Android application, I am currently using Eclipse and a Phidget RFID. My aim is to display the ID of the RFID in a piece of text on the Android device.

I have managed to display the ID through a println in the following pieces of code.

   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;
}

}

and then.

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;
}
}

However I want the ID to be displayed in a piece of text so I tried to develop the second piece of code into 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);


    }


    });
}

}

And this just generates a force close. I am a bit of a novice at this and will appreciate all the advice I get.


LogCat Report;

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
user1128488
  • 87
  • 1
  • 2
  • 5

1 Answers1

0

You need to get myText from 'view' parameter. Try this:

TextView mytext=(TextView)**view**.findViewById(R.id.widget96);
kosa
  • 65,990
  • 13
  • 130
  • 167
  • I have already included that: TextView mytext=(TextView)findViewById(R.id.widget96); mytext.setText((CharSequence) x); its in the 3rd part of the coding about last piece of code. – user1128488 Jan 03 '12 at 19:20
  • please see my response properly, you need to get from view. I will edit my answer to bold the part I am stressing. – kosa Jan 03 '12 at 19:22
  • TextView mytext=(TextView)view.findViewById(R.id.widget96); Even with that it still initiates a Force Close. – user1128488 Jan 03 '12 at 20:01
  • can you check the logcat and post stacktrace? – kosa Jan 03 '12 at 20:02
  • Im sorry but I have not done that before and am unsure how to access Logcat. Looking in the Stack Trace console in Eclipse it only says; Paste stack traces into this console and follow hyperlinks to source code. – user1128488 Jan 03 '12 at 20:21
  • Change your view to ddms from java. You will see a tab with name logcat. – kosa Jan 03 '12 at 20:24
  • Added to original Question. Thanks for continuing help – user1128488 Jan 03 '12 at 20:44
  • java.lang.ExceptionInInitializerError: Library phidget21 not found, I don't whether you referred some other tutorial for this, but the reason is, your code missing required library, phidget21.so. Here is link on how to add .SO file to your project. http://stackoverflow.com/questions/4882167/creating-a-product-sdk-how-do-i-add-a-native-lib-so-and-a-jar-with-the-sdk-i – kosa Jan 03 '12 at 20:56