3

I am creating an application that reads in data from a IOIO microcontroller board and displays it to the screen after I hit a button. I have two classes, MainActivity, which has the button to hit, and AugiActivity which has all of the IOIO code, and display information.

When I hit the button to start the new activity the app crashes. Any ideas?

LogCat

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 file:

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

}

MainActivity XML File

<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 file

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

    }       

}

AugiActivity XML file

<?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>

Manifest File:

<?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>
Sharath
  • 621
  • 8
  • 21
The Starfox
  • 101
  • 1
  • 1
  • 4
  • Post your onClick code. – Hoan Nguyen Mar 15 '13 at 22:19
  • ...and the stacktrace. – 323go Mar 15 '13 at 22:32
  • 1
    I had got a similar exception a few months ago. I found the the solution to my problem here: http://stackoverflow.com/questions/10741287/refering-from-one-android-project-to-another-eclipse. Could you make sure that you built your ioio library correctly? – wraith Mar 15 '13 at 23:18
  • The onclick code is in the is MainActivity.xml which I posted. It calls the "call_ioio" method in MainActivity. The ioio library is good. When I run the code in AugiActivity by itself everything works fine. – The Starfox Mar 15 '13 at 23:58
  • Ive added the stack trace to the LogCat in the original post. – The Starfox Mar 16 '13 at 00:17
  • 1
    I see you are getting java.lang.NoClassDefFoundError. Check [these](http://stackoverflow.com/questions/2456562/approach-for-fixing-noclassdeffounderror) [links](http://stackoverflow.com/questions/8678630/noclassdeffounderror-android) for some possible solutions. As I see in those problems they were using some external libraries and faced problem. – Master Chief Mar 16 '13 at 05:33
  • Master Chief was correct. Turns out there is a weird bug with Eclipse. Even though I imported the IOIO library files into the project, and it compiled with no errors, they were not properly linking together. After I physically copied the .jar files for the libraries, into the specific /lib folder for the project it ran without issue. – The Starfox Mar 17 '13 at 00:35

0 Answers0