4

当我按下一个按钮来启动 MainActivity 中的一个方法时,我得到一个“java.lang.IllegalAccessError class ref in preverified class resolve to unexpected implementation”错误,该方法应该启动一个新的 Activity。我能做些什么来解决这个问题?这是我第一次尝试制作安卓应用程序,所以需要一步一步的说明:)

此外,我还无法测试它是否有效,但如果您发现我的 AugiActivity 服务实现或本地广播实现有任何问题,请随时告诉我。

谢谢!

fyi:MainActivity 启动 Navigation Activity,它启动 Service AugiActivity

Augi 活动向 Navigation 发送本地广播消息

日志猫:

03-24 20:01:56.632: E/AndroidRuntime(11183): FATAL EXCEPTION: main
03-24 20:01:56.632: E/AndroidRuntime(11183): java.lang.IllegalStateException: Could not     
execute method of the activity
03-24 20:01:56.632: E/AndroidRuntime(11183): at 
android.view.View$1.onClick(View.java:2154)
03-24 20:01:56.632: E/AndroidRuntime(11183):    at 
android.view.View.performClick(View.java:2537)
03-24 20:01:56.632: E/AndroidRuntime(11183):    at 
android.view.View$PerformClick.run(View.java:9157)
03-24 20:01:56.632: E/AndroidRuntime(11183):    at 
android.os.Handler.handleCallback(Handler.java:587)
03-24 20:01:56.632: E/AndroidRuntime(11183):    at 
android.os.Handler.dispatchMessage(Handler.java:92)
03-24 20:01:56.632: E/AndroidRuntime(11183):    at 
android.os.Looper.loop(Looper.java:130)
03-24 20:01:56.632: E/AndroidRuntime(11183):    at   
android.app.ActivityThread.main(ActivityThread.java:3687)
03-24 20:01:56.632: E/AndroidRuntime(11183):    at   
java.lang.reflect.Method.invokeNative(Native Method)
03-24 20:01:56.632: E/AndroidRuntime(11183):    at   
java.lang.reflect.Method.invoke(Method.java:507)
03-24 20:01:56.632: E/AndroidRuntime(11183):    at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
03-24 20:01:56.632: E/AndroidRuntime(11183):    at   
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-24 20:01:56.632: E/AndroidRuntime(11183):    at   
dalvik.system.NativeStart.main(Native Method)
03-24 20:01:56.632: E/AndroidRuntime(11183): Caused by:   
java.lang.reflect.InvocationTargetException
03-24 20:01:56.632: E/AndroidRuntime(11183):    at 
java.lang.reflect.Method.invokeNative(Native Method)
03-24 20:01:56.632: E/AndroidRuntime(11183):    at 
java.lang.reflect.Method.invoke(Method.java:507)
03-24 20:01:56.632: E/AndroidRuntime(11183):    at 
android.view.View$1.onClick(View.java:2149)
03-24 20:01:56.632: E/AndroidRuntime(11183):    ... 11 more
03-24 20:01:56.632: E/AndroidRuntime(11183): Caused by: java.lang.NoClassDefFoundError: 
com.example.augi_practice.Navigation
03-24 20:01:56.632: E/AndroidRuntime(11183):    at 
com.example.augi_practice.MainActivity.navigation(MainActivity.java:33)
03-24 20:01:56.632: E/AndroidRuntime(11183):    ... 14 more
03-24 20:01:56.632: E/AndroidRuntime(11183): Caused by: java.lang.IllegalAccessError: 
Class ref in pre-verified class resolved to unexpected implementation
03-24 20:01:56.632: E/AndroidRuntime(11183):    at 
dalvik.system.DexFile.defineClass(Native Method)
03-24 20:01:56.632: E/AndroidRuntime(11183):    at 
dalvik.system.DexFile.loadClassBinaryName(DexFile.java:207)
03-24 20:01:56.632: E/AndroidRuntime(11183):    at 
dalvik.system.PathClassLoader.findClass(PathClassLoader.java:200)
03-24 20:01:56.632: E/AndroidRuntime(11183):    at 
java.lang.ClassLoader.loadClass(ClassLoader.java:551)
03-24 20:01:56.632: E/AndroidRuntime(11183):    at 
java.lang.ClassLoader.loadClass(ClassLoader.java:511)
03-24 20:01:56.632: E/AndroidRuntime(11183):    ... 15 more

XML 文件:

<?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" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 


<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:label="@string/app_name"
        android:screenOrientation="landscape" >
        <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.Navigation"
        android:label="@string/title_activity_navigation" 
        android:screenOrientation="landscape" >
    </activity>
    <service
        android:name="com.example.augi_practice.AugiActivity"
        android:label="@string/title_activity_augi"
        android:parentActivityName="com.example.augi_practice.Navigation"
        android:screenOrientation="landscape" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.augi_practice.Navigation" />            
    </service>       
    <uses-library android:name="com.google.android.maps" />    
</application>

</manifest>

主要活动:

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

public void navigation(View v)
{   
    Intent intent = new Intent(this, Navigation.class);
    startActivity(intent);
}

}

导航活动:

package com.example.augi_practice;

// Lots of imports here


public class Navigation extends MapActivity implements Runnable,   
SurfaceHolder.Callback{

String LED = null;
String MAG = null;
String BAR = null;
String GYRO = null;
String EULER = null;    
String GGA = null;

private BroadcastReceiver MessageReceiver = new BroadcastReceiver()
{
    @Override
    public void onReceive(Context context, Intent intent)
    {
        LED = intent.getStringExtra("LED");
        MAG = intent.getStringExtra("MAG");
        BAR = intent.getStringExtra("BAR");
        GYRO = intent.getStringExtra("GYRO");
        EULER = intent.getStringExtra("EULER");
        GGA = intent.getStringExtra("GGA");         
    }
};

// More global variables

// Lots of gui variables here

// More global variables

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation);
    MapView mapview = (MapView) findViewById(R.id.mapview);
    mapview.setBuiltInZoomControls(true);   

    getWindow().setFormat(PixelFormat.UNKNOWN);

    // Camera configuration settings

    LocalBroadcastManager.getInstance(this).registerReceiver(MessageReceiver, 
new IntentFilter("IOIOData"));

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

            // Lots of links from acivity to gui 

    startService( new Intent(this, AugiActivity.class));        
}

@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_navigation, menu);
    return true;
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {
    // 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

}

public void sensorLayer(View v)
{
    // Executes some code
}

public void mapLayer(View v)
{
    // Executes some code
}

public void cameraLayer(View v)
{
    // Executes some code
}   

@Override
public void run() {
    //Executes some code
}   
}

AugiActivity 的一部分:

package com.example.augi_practice;

//lots of imports here


public class AugiActivity extends Service { 

public Activity activity_name;

class IOIO extends IOIOActivity {   


// Lots of global variables

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); 
    activity_name = this.getParent();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.        
    return true;
}

class Looper extends BaseIOIOLooper {
    /** The on-board LED. */
    // Class variables

    public Activity activity_name;

    Looper(Activity x)
    {
        this.activity_name = x;
    }       

    // More class variables

    /**
    * 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 
        {
            // establish various connections here

            bar_calibration();      
            mag_setup();
            imu_setup();    
            try {
                gps_setup();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        // Various setup methods here

    /**
    * 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);   

            sendMessage();
        }

        // Various methodes to get data

        private void sendMessage()
        {
            Intent intent = new Intent("IOIOData");     

            intent.putExtra("LED", get_LED());

LocalBroadcastManager.getInstance(activity_name).sendBroadcast(intent);

            intent.putExtra("MAG", get_MAG());

LocalBroadcastManager.getInstance(activity_name).sendBroadcast(intent);

            intent.putExtra("BAR", get_BAR());

LocalBroadcastManager.getInstance(activity_name).sendBroadcast(intent);

            intent.putExtra("GYRO", get_GYRO());

LocalBroadcastManager.getInstance(activity_name).sendBroadcast(intent);

            intent.putExtra("EULER", get_EULER());

LocalBroadcastManager.getInstance(activity_name).sendBroadcast(intent);

            intent.putExtra("GGA", gps_GGA);

LocalBroadcastManager.getInstance(activity_name).sendBroadcast(intent);
        }
    }
4

3 回答 3

11

就我而言,我更改了 Intelij Idea 中的项目设置。转到模块-> 依赖项,然后将库的范围设置为“已提供”。

于 2013-08-20T12:31:18.943 回答
1

在打开模块设置-> 依赖项

设置行的范围

{include=[*.jar], dir=libs}

提供

为我工作

于 2015-10-23T15:31:10.190 回答
-1

我解决了。似乎在 libs 文件夹中包含 maps.jar 文件是个坏主意。删除它纠正了问题。谢谢大家。

于 2013-03-25T04:30:46.510 回答