我不知道如何打开这个 DigitalOutput。错误在第 31 行 ->led = ioio.openDigitalOutput(IOIO.LED_PIN);
这有什么问题?
import ioio.lib.api.DigitalOutput;
import ioio.lib.api.IOIO;
import ioio.lib.api.IOIOFactory;
import ioio.lib.api.exception.ConnectionLostException;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView text = (TextView) findViewById(R.id.textView1);
text.setText("---");
IOIO ioio = null;
try{
ioio = IOIOFactory.create();
} catch(Exception e) {
text.setText(e.toString());
}
DigitalOutput led = null;
try {
led = ioio.openDigitalOutput(IOIO.LED_PIN);
led.write(true);
} catch (ConnectionLostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
led.write(true);
} catch (ConnectionLostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
日志猫:
07-29 16:14:03.027: E/AndroidRuntime(18831): FATAL EXCEPTION: main
07-29 16:14:03.027: E/AndroidRuntime(18831): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.ho.simon.testioio/net.ho.simon.testioio.MainActivity}: java.lang.IllegalStateException: Connection has not yet been established
07-29 16:14:03.027: E/AndroidRuntime(18831): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-29 16:14:03.027: E/AndroidRuntime(18831): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-29 16:14:03.027: E/AndroidRuntime(18831): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-29 16:14:03.027: E/AndroidRuntime(18831): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-29 16:14:03.027: E/AndroidRuntime(18831): at android.os.Handler.dispatchMessage(Handler.java:99)
07-29 16:14:03.027: E/AndroidRuntime(18831): at android.os.Looper.loop(Looper.java:137)
07-29 16:14:03.027: E/AndroidRuntime(18831): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-29 16:14:03.027: E/AndroidRuntime(18831): at java.lang.reflect.Method.invokeNative(Native Method)
07-29 16:14:03.027: E/AndroidRuntime(18831): at java.lang.reflect.Method.invoke(Method.java:511)
07-29 16:14:03.027: E/AndroidRuntime(18831): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-29 16:14:03.027: E/AndroidRuntime(18831): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-29 16:14:03.027: E/AndroidRuntime(18831): at dalvik.system.NativeStart.main(Native Method)
07-29 16:14:03.027: E/AndroidRuntime(18831): Caused by: java.lang.IllegalStateException: Connection has not yet been established
07-29 16:14:03.027: E/AndroidRuntime(18831): at ioio.lib.impl.IOIOImpl.checkState(IOIOImpl.java:650)
07-29 16:14:03.027: E/AndroidRuntime(18831): at ioio.lib.impl.IOIOImpl.openDigitalOutput(IOIOImpl.java:332)
07-29 16:14:03.027: E/AndroidRuntime(18831): at ioio.lib.impl.IOIOImpl.openDigitalOutput(IOIOImpl.java:356)
07-29 16:14:03.027: E/AndroidRuntime(18831): at net.ho.simon.testioio.MainActivity.onCreate(MainActivity.java:31)
07-29 16:14:03.027: E/AndroidRuntime(18831): at android.app.Activity.performCreate(Activity.java:5104)
07-29 16:14:03.027: E/AndroidRuntime(18831): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-29 16:14:03.027: E/AndroidRuntime(18831): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-29 16:14:03.027: E/AndroidRuntime(18831): ... 11 more