我正在创建一个应用程序,它从 IOIO 微控制器板上读取数据并在我按下按钮后将其显示到屏幕上。我有两个类,MainActivity,它有要点击的按钮,AugiActivity,它有所有的 IOIO 代码,并显示信息。
当我点击按钮开始新活动时,应用程序崩溃了。有任何想法吗?
日志猫
38.496: E/AndroidRuntime(22105): FATAL EXCEPTION: main
38.496: E/AndroidRuntime(22105): java.lang.IllegalStateException: Could not execute method of the activity
38.496: E/AndroidRuntime(22105): at android.view.View$1.onClick(View.java:2154)
38.496: E/AndroidRuntime(22105): at android.view.View.performClick(View.java:2537)
38.496: E/AndroidRuntime(22105): at android.view.View$PerformClick.run(View.java:9157)
38.496: E/AndroidRuntime(22105): at android.os.Handler.handleCallback(Handler.java:587)
38.496: E/AndroidRuntime(22105): at android.os.Handler.dispatchMessage(Handler.java:92)
38.496: E/AndroidRuntime(22105): at android.os.Looper.loop(Looper.java:130)
38.496: E/AndroidRuntime(22105): at
android.app.ActivityThread.main(ActivityThread.java:3687)
38.496: E/AndroidRuntime(22105): at java.lang.reflect.Method.invokeNative(Native
Method)
38.496: E/AndroidRuntime(22105): at java.lang.reflect.Method.invoke(Method.java:507)
38.496: E/AndroidRuntime(22105): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
38.496: E/AndroidRuntime(22105): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
38.496: E/AndroidRuntime(22105): at dalvik.system.NativeStart.main(Native Method)
38.496: E/AndroidRuntime(22105): Caused by: java.lang.reflect.InvocationTargetException
38.496: E/AndroidRuntime(22105): at java.lang.reflect.Method.invokeNative(Native
Method)
38.496: E/AndroidRuntime(22105): at java.lang.reflect.Method.invoke(Method.java:507)
38.496: E/AndroidRuntime(22105): at android.view.View$1.onClick(View.java:2149)
38.496: E/AndroidRuntime(22105): ... 11 more
38.496: E/AndroidRuntime(22105): Caused by: java.lang.NoClassDefFoundError:
com.example.augi_practice.AugiActivity
38.496: E/AndroidRuntime(22105): at
com.example.augi_practice.MainActivity.call_ioio(MainActivity.java:27)
38.496: E/AndroidRuntime(22105): ... 14 more
MainActivity java 文件:
package com.example.augi_practice;
import ioio.lib.util.android.IOIOActivity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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;
}
public void call_ioio(View v)
{
Intent intent = new Intent(this, AugiActivity.class);
startActivity(intent);
}
}
主活动 XML 文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginRight="31dp"
android:layout_marginTop="62dp"
android:onClick="call_ioio"
android:text="Call IOIO" />
</RelativeLayout>
AugiActivity java文件
package com.example.augi_practice;
//imports here
public class AugiActivity extends IOIOActivity implements SurfaceHolder.Callback{
// Some global variables here
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_augi);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
light_voltage_TV = (TextView) findViewById(R.id.LED_View);
bar_data_TV = (TextView) findViewById(R.id.BAR_View);
mag_TV = (TextView) findViewById(R.id.MAG_View);
gyro_rate_TV = (TextView) findViewById(R.id.GYRO_RATE_View);
acel_euler_TV = (TextView) findViewById(R.id.ACEL_EULER_View);
gga_TV = (TextView) findViewById(R.id.GGA_View);
gsa_TV = (TextView) findViewById(R.id.GSA_View);
gsv_TV = (TextView) findViewById(R.id.GSV_View);
rmc_TV = (TextView) findViewById(R.id.RMC_View);
vtg_TV = (TextView) findViewById(R.id.VTG_View);
getWindow().setFormat(PixelFormat.UNKNOWN);
cam_TV = (SurfaceView) findViewById(R.id.CAMERA_View);
holder = cam_TV.getHolder();
holder.addCallback((Callback) this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
@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_augi, menu);
return true;
}
class Looper extends BaseIOIOLooper {
/** The on-board LED. */
private AnalogInput in;
private DigitalOutput led_;
TwiMaster i2c;
// GPS UART COMMUNICATION
private Uart uart;
private InputStream gps_in;
private OutputStream gps_out;
// variables for class
/**
* Called every time a connection with IOIO has been established.
* Typically used to open pins.
*
* @throws ConnectionLostException
* When IOIO connection is lost.
* @throws InterruptedException
*
* @see ioio.lib.util.AbstractIOIOActivity.IOIOThread#setup()
*/
@Override
protected void setup() throws ConnectionLostException, InterruptedException
{
various methods called here to setup hardware
}
/**
* Called repetitively while the IOIO is connected.
*
* @throws ConnectionLostException
* When IOIO connection is lost.
* @throws InterruptedException
*
* @see ioio.lib.util.AbstractIOIOActivity.IOIOThread#loop()
*/
@Override
public void loop() throws ConnectionLostException, InterruptedException
{
get_light();
get_temp();
get_pressure();
get_north();
get_imu();
try {
get_gps();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
led_.write(true);
light_voltage_TV.post(new UpdateReadings());
}
// Methods listed above goes here
}
/**
* A method to create our IOIO thread.
*
* @see ioio.lib.util.AbstractIOIOActivity#createIOIOThread()
*/
@Override
protected IOIOLooper createIOIOLooper() {
return new Looper();
}
private class UpdateReadings implements Runnable {
@Override
public void run()
{
// data posted to text views here
}
}
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int)
{ // TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
}
奥吉活动 XML 文件
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/FrameLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<SurfaceView
android:id="@+id/CAMERA_View"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/LED_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/BAR_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/MAG_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/GYRO_RATE_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/ACEL_EULER_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/GGA_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="10sp" />
<TextView
android:id="@+id/GSA_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="10sp" />
<TextView
android:id="@+id/GSV_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="10sp" />
<TextView
android:id="@+id/RMC_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="10sp" />
<TextView
android:id="@+id/VTG_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="10sp" />
</LinearLayout>
</FrameLayout>
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.augi_practice"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="3"
android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.augi_practice.MainActivity"
android:screenOrientation="landscape"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
</activity>
<activity
android:name="com.example.augi_practice.AugiActivity"
android:screenOrientation="landscape"
android:label="@string/title_activity_augi"
android:parentActivityName="com.example.augi_practice.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.augi_practice.MainActivity" />
<intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
</activity>
</application>
</manifest>