wendykierp / JTransforms

JTransforms is the first, open source, multithreaded FFT library written in pure Java.
Other
370 stars 89 forks source link

java.lang.NoClassDefFoundError #6

Closed kevinashaw closed 7 years ago

kevinashaw commented 8 years ago

I'm not sure if this is the right venue to post this question, but though I would start here before going to StackOverflow. I am attempting to use JTransforms to compute a DoubleFFT_1D.
The full error message is this:

09-07 17:30:11.369 E/JavaBinder: *** Uncaught remote exception!  (Exceptions are not yet supported across processes.)
                                 java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jtransforms/fft/DoubleFFT_1D;
                                     at com.algoint.libzante.AutoCorrelation.compute(AutoCorrelation.java:66)
                                     at com.algoint.libzante.EstimateACF.estimateInSamplePeriods(EstimateACF.java:104)
                                     at <snip>
com.algoint.zante.BluetoothLeService.broadcastUpdate(BluetoothLeService.java:348)
                                     at com.algoint.zante.BluetoothLeService.access$700(BluetoothLeService.java:50)
                                     at com.algoint.zante.BluetoothLeService$1.onCharacteristicChanged(BluetoothLeService.java:243)
                                     at android.bluetooth.BluetoothGatt$1.onNotify(BluetoothGatt.java:438)
                                     at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:399)
                                     at android.os.Binder.execTransact(Binder.java:453)
                                  Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jtransforms.fft.DoubleFFT_1D" on path: DexPathList[[dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-json_simple-1.1_9ec115b071c72fb6edf2028f7a57e4ae60bb5a65-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-dropbox-android-sdk-1.5.4_74a0c4010a6328c8c6443241412fa9c5c398a9ab-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-achartengine-1.1.0_0238cc7eb0f70b6065b267fb6df8a8f6b48a5319-classes.dex"],nativeLibraryDirectories=[/data/app/com.algoint.zante-2/lib/arm64, /vendor/lib64, /system/lib64]]
                                     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                     at com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader.findClass(IncrementalClassLoader.java:90)
                                     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                                     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                                     at com.algoint.libzante.AutoCorrelation.compute(AutoCorrelation.java:66) 
                                     at com.algoint.libzante.EstimateACF.estimateInSamplePeriods(EstimateACF.java:104) 
                                     at <snip>
com.algoint.zante.BluetoothLeService.broadcastUpdate(BluetoothLeService.java:348) 
                                     at com.algoint.zante.BluetoothLeService.access$700(BluetoothLeService.java:50) 
                                     at com.algoint.zante.BluetoothLeService$1.onCharacteristicChanged(BluetoothLeService.java:243) 
                                     at android.bluetooth.BluetoothGatt$1.onNotify(BluetoothGatt.java:438) 
                                     at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:399) 
                                     at android.os.Binder.execTransact(Binder.java:453) 
                                    Suppressed: java.lang.ClassNotFoundException: Didn't find class "org.jtransforms.fft.DoubleFFT_1D" on path: DexPathList[[zip file "/data/app/com.algoint.zante-2/base.apk"],nativeLibraryDirectories=[/data/app/com.algoint.zante-2/lib/arm64, /vendor/lib64, /system/lib64]]
                                     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                                     at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                                            ... 12 more
                                        Suppressed: java.lang.ClassNotFoundException: Didn't find class "org.jtransforms.fft.DoubleFFT_1D" on path: DexPathList[[dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.

I have imported jtransforms as follows in the source file: import org.jtransforms.fft.DoubleFFT_1D; with the proper gradle entry:

apply plugin: 'java'
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile files('libs/JTransforms-3.1-with-dependencies.jar')
}

And corresponding Android Studio dependency setting: image

The project compiles without an error and throws and error at the following line:

       // An array of length 4 will yield n = 8.
        // This is necessary for the computation to be correct.
        int n = 2 * nextPow2(x.length);
        // Twice the number of elements are required: real and imaginary parts of the FFT are stored consecutively
        double[] f = new double[2 * n];   
        System.arraycopy(x, 0, f, 0, x.length);
        // FFT
        DoubleFFT_1D fft = new DoubleFFT_1D((long) n);  // ERROR ON THIS LINE
        // Use "full" to avoid more machinations with symmetry
        fft.realForwardFull(f);

The value of n when the error is thrown is 1024 and the length of x is 500. I have found this error with both: "JTransforms-2.4.jar" and "JTransforms-3.1-with-dependencies.jar". Can you recommend any solutions? Thank you.

theoknock commented 8 years ago

Surround the code that appears to be generating an exception in a try-catch-finally block, and then report the error back here...

James 408-685-4049

On Wed, Sep 7, 2016 at 5:50 PM -0700, "kevinashaw" notifications@github.com wrote:

I'm not sure if this is the right venue to post this question, but though I would start here before going to StackOverflow.

I am attempting to use JTransforms to compute a DoubleFFT_1D.

The full error message is this:

09-07 17:30:11.369 E/JavaBinder: *\ Uncaught remote exception! (Exceptions are not yet supported across processes.) java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jtransforms/fft/DoubleFFT_1D; at com.algoint.libzante.AutoCorrelation.compute(AutoCorrelation.java:66) at com.algoint.libzante.EstimateACF.estimateInSamplePeriods(EstimateACF.java:104) at com.algoint.zante.BluetoothLeService.broadcastUpdate(BluetoothLeService.java:348) at com.algoint.zante.BluetoothLeService.access$700(BluetoothLeService.java:50) at com.algoint.zante.BluetoothLeService$1.onCharacteristicChanged(BluetoothLeService.java:243) at android.bluetooth.BluetoothGatt$1.onNotify(BluetoothGatt.java:438) at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:399) at android.os.Binder.execTransact(Binder.java:453) Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jtransforms.fft.DoubleFFT_1D" on path: DexPathList[[dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-json_simple-1.1_9ec115b071c72fb6edf2028f7a57e4ae60bb5a65-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-dropbox-android-sdk-1.5.4_74a0c4010a6328c8c6443241412fa9c5c398a9ab-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-achartengine-1.1.0_0238cc7eb0f70b6065b267fb6df8a8f6b48a5319-classes.dex"],nativeLibraryDirectories=[/data/app/com.algoint.zante-2/lib/arm64, /vendor/lib64, /system/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader.findClass(IncrementalClassLoader.java:90) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:469) at com.algoint.libzante.AutoCorrelation.compute(AutoCorrelation.java:66)  at com.algoint.libzante.EstimateACF.estimateInSamplePeriods(EstimateACF.java:104)  at com.algoint.zante.BluetoothLeService.broadcastUpdate(BluetoothLeService.java:348)  at com.algoint.zante.BluetoothLeService.access$700(BluetoothLeService.java:50)  at com.algoint.zante.BluetoothLeService$1.onCharacteristicChanged(BluetoothLeService.java:243)  at android.bluetooth.BluetoothGatt$1.onNotify(BluetoothGatt.java:438)  at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:399)  at android.os.Binder.execTransact(Binder.java:453)  Suppressed: java.lang.ClassNotFoundException: Didn't find class "org.jtransforms.fft.DoubleFFT_1D" on path: DexPathList[[zip file "/data/app/com.algoint.zante-2/base.apk"],nativeLibraryDirectories=[/data/app/com.algoint.zante-2/lib/arm64, /vendor/lib64, /system/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:504) ... 12 more Suppressed: java.lang.ClassNotFoundException: Didn't find class "org.jtransforms.fft.DoubleFFT_1D" on path: DexPathList[[dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.

I have imported jtransforms as follows in the source file:

import org.jtransforms.fft.DoubleFFT_1D;

with the proper gradle entry:

apply plugin: 'java' dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile files('libs/JTransforms-3.1-with-dependencies.jar') }

And corresponding Android Studio dependency setting:

The project compiles without an error and throws and error at the following line:

   // An array of length 4 will yield n = 8.
    // This is necessary for the computation to be correct.
    int n = 2 * nextPow2(x.length);
    // Twice the number of elements are required: real and imaginary parts of the FFT are stored consecutively
    double[] f = new double[2 * n];   
    System.arraycopy(x, 0, f, 0, x.length);
    // FFT
    DoubleFFT_1D fft = new DoubleFFT_1D((long) n);  // ERROR ON THIS LINE
    // Use "full" to avoid more machinations with symmetry
    fft.realForwardFull(f);

The value of n when the error is thrown is 1024 and the length of x is 500.

I have found this error with both: "JTransforms-2.4.jar" and "JTransforms-3.1-with-dependencies.jar".

Can you recommend any solutions?

Thank you.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

kevinashaw commented 8 years ago

Hi James, Thank you for replying. Interestingly, when I add the try-catch statements, the compiler throws and error:

Error:Execution failed for task ':app:transformClassesWithInstantRunForDebug'.
> java.lang.ClassNotFoundException: org.jtransforms.fft.DoubleFFT_1D

The relevant code block is:

        double[] fr = new double[2 * n];
        try {
            // FFT
            DoubleFFT_1D fft = new DoubleFFT_1D((long) n);
            // Use "full" to avoid more machinations with symmetry
            fft.realForwardFull(f);

            // Power spectrum
            for (int i = 0; i < n; i++) {
                fr[i] = Math.pow(f[2 * i], 2) + Math.pow(f[2 * i + 1], 2);
            }

            // IFFT
            fft.realInverseFull(fr, true);
        }
        catch (Exception e){
            Logger logger = Logger.getAnonymousLogger();
            logger.info(e.toString());
        }

I tried uploading the whole file, but importer does not like the file type.
Let me know if you want me to insert the whole file (123 lines).

kevinashaw commented 8 years ago

Here is the full file:

package com.algoint.libzante;

import org.jtransforms.fft.DoubleFFT_1D;

import java.util.logging.Logger;

/**
 * Computes autocorrelation for real sequences using FFT.
 * 
 */
public class AutoCorrelation {

    // Singleton pattern. Fine to use in this case, should be thread safe just like Math.cos.
    private static final AutoCorrelation INSTANCE = new AutoCorrelation();
    // To find next power of 2
    private static final double LOG_2 = Math.log(2);

    /**
     * Returns an {@linkplain AutoCorrelation} instance.
     * 
     * @return an {@linkplain AutoCorrelation} instance.
     */
    public static AutoCorrelation getInstance() {
        return INSTANCE;
    }

    /**
     * Private constructor: not meant for sub-classing.
     */
    private AutoCorrelation() {
    }

    /**
     * Computes autocorrelation for a real valued sequence given as an array of {@code double}s. Will not accept
     * {@code null}. Will not accept an empty array. Computes "one-sided" autocorrelation, that is:
     * <p>
     * <ul>
     * <li>The first element of the returned array is the "central" peak corresponding to zero lag.
     * <li>The values for negative lags are not computed owing to symmetry.
     * <li>The returned array has length equal to the next greater or equal power of two than the input array length. In
     * other words, an input of length 4 will return an array of length 4.
     * </ul>
     * 
     * @param x
     *            the given input sequence.
     * @return one symmetric half of the auto-correlation sequence, starting with the central zero-lag element.
     */
    public double[] compute(double[] x) {
        if (x == null) {
            throw new NullPointerException("x is null");
        } else if (x.length == 0) {
            throw new IllegalArgumentException("x is empty");
        } else if (x.length == 1) {
            return new double[] { x[0] * x[0] };
        }
        // TODO: why 2 * nextPow2?
        // An array of length 4 will yield n = 8.
        // This is necessary for the computation to be correct.
        int n = 2 * nextPow2(x.length);
        // Twice the number of elements are required: real and imaginary parts of the FFT are stored consecutively
        double[] f = new double[2 * n];
        System.arraycopy(x, 0, f, 0, x.length);

        double[] fr = new double[2 * n];
        try {
            // FFT
            DoubleFFT_1D fft = new DoubleFFT_1D((long) n);
            // Use "full" to avoid more machinations with symmetry
            fft.realForwardFull(f);

            // Power spectrum
            for (int i = 0; i < n; i++) {
                fr[i] = Math.pow(f[2 * i], 2) + Math.pow(f[2 * i + 1], 2);
            }

            // IFFT
            fft.realInverseFull(fr, true);
        }
        catch (Exception e){
            Logger logger = Logger.getAnonymousLogger();
            logger.info(e.toString());
        }

        // This is real, but zero imaginary parts are also included. So strip those out.
        double[] c = new double[x.length];
        // And only return one half of the auto-correlation corresponding to positive lags.
        for (int i = 0; i < x.length; i++) {
            c[i] = fr[2 * i];
        }
        return c;
    }

    /**
     * Computes the next higher power of two, given an integer.
     * 
     * @param n
     *            the given integer.
     * @return an integer strictly greater than {@code n} that is a power of 2.
     */
    int nextPow2(int n) {
        if (n < 1) {
            throw new IllegalArgumentException("n must be positive, given " + n);
        } else if (n == 1) {
            return 2;
        }
        // Special handling for powers of 2 to avoid dubious floating-point math
        int m = n;
        while ((m % 2) == 0 && m > 1) {
            m /= 2;
        }
        if (m == 1) {
            return 2 * n;
        }
        // For integers that are not powers of two...
        double log2base2 = Math.log(n) / LOG_2;
        return (int) Math.round(Math.pow(2, Math.ceil(log2base2)));
    }

}
kevinashaw commented 8 years ago

I would be grateful if anyone could let me know if they have seen this issue before.

kevinashaw commented 8 years ago

Question posted to StackOverflow.
http://stackoverflow.com/questions/39498690/android-java-lang-noclassdeffounderror

wendykierp commented 7 years ago

This is a problem with Android Studio, not JTransforms.

999Yy999 commented 4 years ago

Did you find a solution? I have the same question, could you let me kown if you solved it? Thanks. I already solved it. My solution is importing JTransfroms in pom.xml. Thank you for your attention