Closed kevinashaw closed 7 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
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.
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).
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)));
}
}
I would be grateful if anyone could let me know if they have seen this issue before.
Question posted to StackOverflow.
http://stackoverflow.com/questions/39498690/android-java-lang-noclassdeffounderror
This is a problem with Android Studio, not JTransforms.
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
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:
I have imported jtransforms as follows in the source file:
import org.jtransforms.fft.DoubleFFT_1D;
with the proper gradle entry:And corresponding Android Studio dependency setting:
The project compiles without an error and throws and error at the following line:
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.