我已成功实现了reflectionEquals方法,其中包含一个排除字段列表.
return EqualsBuilder.reflectionEquals(this, obj, new String[] {"files", "notes", "status"});
Run Code Online (Sandbox Code Playgroud)
但是,我最近在Java 1.5上编译了我的程序,现在当程序遇到上述行时出现以下错误:
java.lang.NoSuchMethodError:org.apache.commons.lang.builder.EqualsBuilder.= reflectionEquals(Ljava/lang/Object; Ljava/lang/Object; [Ljava/lang/String;)Z
如果有人了解该方法在运行时不存在的原因,我将不胜感激
我有一个自定义视图,使用这些构造函数扩展LinearLayout:
public class CustomView extends LinearLayout {
public CustomView(Context context) {
this(context, null);
}
public CustomView(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.customViewStyle);
}
public CustomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
/* set custom attributes with TypedArray */
}
/* other methods */
}
Run Code Online (Sandbox Code Playgroud)
在我的/res/values/attrs.xml中:
<attr name="customViewStyle" format="reference" />
<declare-styleable name="CustomeView">
<attr name="value" format="integer" />
<attr name="android:imeOptions" />
<attr name="android:imeActionId" />
<attr name="android:imeActionLabel" />
</declare-styleable>
Run Code Online (Sandbox Code Playgroud)
在我的/res/values/styles.xml中:
<style name="AppTheme" parent="@android:style/Theme.Black">
<item name="android:windowBackground">@drawable/bg_dark_fiber</item>
<item name="customViewStyle">@style/CustomViewStyle</item>
</style>
<style name="CustomViewStyle"> …Run Code Online (Sandbox Code Playgroud) android custom-controls nosuchmethoderror android-linearlayout inflate-exception
任何人都可以帮助我为什么NOSuchMethodError在运行时来自java.my错误是.Java.lang.NoSuchMethodError:com.Person.setCompanyList(Ljava/util/ArrayList;)V
我在尝试获取SD卡ID时面临服务onCreate()的问题.使用来自src-external/android-core的android.os包的FileUtils类.
mCardId = FileUtils.getFatVolumeId(Environment.getExternalStorageDirectory().getPath());
崩溃日志:
12-31 19:55:25.804: E/AndroidRuntime(1235): java.lang.NoSuchMethodError: android.os.FileUtils.getFatVolumeId 12-31 19:55:25.804: E/AndroidRuntime(1235): at cloudtv.android.cs.service.MediaPlaybackService.onCreate(MediaPlaybackService.java:198) 12-31 19:55:25.804: E/AndroidRuntime(1235): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2572) 12-31 19:55:25.804: E/AndroidRuntime(1235): at android.app.ActivityThread.access$1800(ActivityThread.java:135) 12-31 19:55:25.804: E/AndroidRuntime(1235): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) 12-31 19:55:25.804: E/AndroidRuntime(1235): at android.os.Handler.dispatchMessage(Handler.java:102) 12-31 19:55:25.804: E/AndroidRuntime(1235): at android.os.Looper.loop(Looper.java:136) 12-31 19:55:25.804: E/AndroidRuntime(1235): at android.app.ActivityThread.main(ActivityThread.java:5017) 12-31 19:55:25.804: E/AndroidRuntime(1235): at java.lang.reflect.Method.invokeNative(Native Method) 12-31 19:55:25.804: E/AndroidRuntime(1235): at java.lang.reflect.Method.invoke(Method.java:515) 12-31 19:55:25.804: E/AndroidRuntime(1235): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 12-31 19:55:25.804: E/AndroidRuntime(1235): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 12-31 19:55:25.804: E/AndroidRuntime(1235): at dalvik.system.NativeStart.main(Native Method)
提前致谢!
经过一段时间的研究后,我仍然没有发现为什么这个事情发生在我的Android代码中.这只是标准的简单单元测试代码,实际上还没有多少.我以前在我的工作机器上尝试过此代码并成功运行单元测试.我不知道为什么这会发生在我家里的其他电脑上.也许这可能是由一些不正确的robolectric 3设置造成的,我不太确定.我附上了完整的日志报告,也许你们能够更好地理解它.谢谢.
Gradle命令运行单元测试:
gradlew test
Run Code Online (Sandbox Code Playgroud)
错误:
com.sample.bigger.MainActivityTest > sampleTest FAILED
java.lang.RuntimeException
Caused by: java.lang.RuntimeException
Caused by: java.lang.NoSuchMethodException
Run Code Online (Sandbox Code Playgroud)
完整日志:
java.lang.RuntimeException: java.lang.NoSuchMethodException: android.os.Looper.<init>(boolean)
at org.robolectric.util.ReflectionHelpers.callConstructor(ReflectionHelpers.java:297)
at org.robolectric.shadows.ShadowLooper.createLooper(ShadowLooper.java:43)
at org.robolectric.shadows.ShadowLooper.access$000(ShadowLooper.java:25)
at org.robolectric.shadows.ShadowLooper$1.create(ShadowLooper.java:37)
at org.robolectric.shadows.ShadowLooper$1.create(ShadowLooper.java:35)
at org.robolectric.util.SoftThreadLocal$1.initialValue(SoftThreadLocal.java:13)
at org.robolectric.util.SoftThreadLocal$1.initialValue(SoftThreadLocal.java:11)
at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:160)
at java.lang.ThreadLocal.get(ThreadLocal.java:150)
at org.robolectric.util.SoftThreadLocal.get(SoftThreadLocal.java:18)
at org.robolectric.shadows.ShadowLooper.resetThreadLoopers(ShadowLooper.java:55)
at org.robolectric.Shadows.reset(Shadows.java:1612)
at org.robolectric.Robolectric.reset(Robolectric.java:22)
at org.robolectric.internal.ParallelUniverse.resetStaticState(ParallelUniverse.java:43)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:233)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:188)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:152)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) …Run Code Online (Sandbox Code Playgroud) android unit-testing nosuchmethoderror runtimeexception robolectric
我正在我的应用程序中录制音频,我正在努力处理 MediaRecorder 类
import android.media.MediaRecorder;
Run Code Online (Sandbox Code Playgroud)
问题是代码可以编译但似乎无法在 API 级别 < 26 的设备上运行,因为MediaRecorder.setOutputFormat()根据 Android Studio 中的内联错误消息,该函数显然在API 26 之前不存在。同样,当我在带有 API 24 的模拟器上运行代码时,我会因运行时错误而崩溃:
java.lang.NoSuchMethodError: No virtual method setOutputFile(Ljava/io/File;)V in class Landroid/media/MediaRecorder; or its super classes (declaration of 'android.media.MediaRecorder' appears in /system/framework/framework.jar)
Run Code Online (Sandbox Code Playgroud)
作为快速修复,我只是将 gradle 文件中的最小 SDK 级别增加到 26,并且一切正常。但是,我不希望我的应用仅限于 Android 8.0 及更高版本,因为 7.x 仍然如此受欢迎。
所以我的第一个问题是:怎么可能整个MediaRecorder库只有一个功能不可用,人们如何使用MediaRecorder之前的API 26?我在网上找不到任何关于它的信息。
第二个问题:如何解决问题,以便为 API 级别 24+ 录制音频?我必须使用另一个图书馆吗?
这是我的活动的一部分,我正在设置录音机并开始录音。同样,当最小 SDK 为 26 时,这可以正常工作......
private MediaRecorder recorder;
private void startRecording(){
if(!recordingActive) {
recorder = new …Run Code Online (Sandbox Code Playgroud) 我有一个我启动的 gRPC 服务,一切都很好,没有错误。但是,当我尝试使用grpcui( ./grpcui -plaintext localhost:9900) 将读取和服务时,我得到以下信息:
Exception in thread "grpc-default-executor-0" java.lang.NoSuchMethodError: com.google.protobuf.Descriptors$FileDescriptor.internalBuildGeneratedFileFrom([Ljava/lang/String;[Lcom/google/protobuf/Descriptors$FileDescriptor;)Lcom/google/protobuf/Descriptors$FileDescriptor;
at io.grpc.reflection.v1alpha.ServerReflectionProto.<clinit>(ServerReflectionProto.java:103)
at io.grpc.reflection.v1alpha.ServerReflectionGrpc$ServerReflectionBaseDescriptorSupplier.getFileDescriptor(ServerReflectionGrpc.java:234)
at io.grpc.protobuf.services.ProtoReflectionService$FileDescriptorIndex.<init>(ProtoReflectionService.java:418)
at io.grpc.protobuf.services.ProtoReflectionService$ServerReflectionIndex.<init>(ProtoReflectionService.java:339)
at io.grpc.protobuf.services.ProtoReflectionService.updateIndexIfNecessary(ProtoReflectionService.java:97)
at io.grpc.protobuf.services.ProtoReflectionService.serverReflectionInfo(ProtoReflectionService.java:136)
at io.grpc.reflection.v1alpha.ServerReflectionGrpc$MethodHandlers.invoke(ServerReflectionGrpc.java:220)
at io.grpc.stub.ServerCalls$StreamingServerCallHandler.startCall(ServerCalls.java:224)
at io.grpc.internal.ServerImpl$ServerTransportListenerImpl.startWrappedCall(ServerImpl.java:648)
at io.grpc.internal.ServerImpl$ServerTransportListenerImpl.startCall(ServerImpl.java:626)
at io.grpc.internal.ServerImpl$ServerTransportListenerImpl.access$1900(ServerImpl.java:417)
at io.grpc.internal.ServerImpl$ServerTransportListenerImpl$1StreamCreated.runInternal(ServerImpl.java:556)
at io.grpc.internal.ServerImpl$ServerTransportListenerImpl$1StreamCreated.runInContext(ServerImpl.java:531)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Run Code Online (Sandbox Code Playgroud)
和
Exception in thread "grpc-default-executor-1" java.lang.NoClassDefFoundError: Could not initialize class io.grpc.reflection.v1alpha.ServerReflectionProto
at io.grpc.reflection.v1alpha.ServerReflectionGrpc$ServerReflectionBaseDescriptorSupplier.getFileDescriptor(ServerReflectionGrpc.java:234)
at io.grpc.protobuf.services.ProtoReflectionService$FileDescriptorIndex.<init>(ProtoReflectionService.java:418)
at io.grpc.protobuf.services.ProtoReflectionService$ServerReflectionIndex.<init>(ProtoReflectionService.java:339)
at io.grpc.protobuf.services.ProtoReflectionService.updateIndexIfNecessary(ProtoReflectionService.java:97)
at io.grpc.protobuf.services.ProtoReflectionService.serverReflectionInfo(ProtoReflectionService.java:136)
at io.grpc.reflection.v1alpha.ServerReflectionGrpc$MethodHandlers.invoke(ServerReflectionGrpc.java:220)
at io.grpc.stub.ServerCalls$StreamingServerCallHandler.startCall(ServerCalls.java:224)
at io.grpc.internal.ServerImpl$ServerTransportListenerImpl.startWrappedCall(ServerImpl.java:648)
at …Run Code Online (Sandbox Code Playgroud) java noclassdeffounderror protocol-buffers nosuchmethoderror grpc
我试图逐行将file.txt读入java,然后当一行是"foo"时,我将它后面的行设置为"lineAfterFoo",然后将其输出给用户.
我的Java代码....
public void main(String[] args) throws IOException {
try {
FileReader someFile = new FileReader("file.txt");
BufferedReader input = new BufferedReader(someFile);
int i = 0;
String[] line;
line = new String[10];
line[i] = input.readLine();
while(line[i] != null) {
line[i] = input.readLine();
if (line[i] == "foo") {
i = i + 1;
line[i] = "lineAfterFoo";
}
i = i + 1;
}
for (int number = 1; number < i; number++) {
System.out.println(line[number]);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} …Run Code Online (Sandbox Code Playgroud) 使用此功能时出现奇怪的错误.在新设备和模拟器上运行良好,但在旧设备上测试应用程序时崩溃..任何线索发生了什么?
public boolean bind(ContentValues values ) throws DatabaseException {
if (values == null) throw new DatabaseException("Values is null");
ArrayList<String> columnNames = this.getColumnNamesArray(AppController.getDBO().getDatabase());
String currentKey = null;
try {
for (String key : values.keySet()) {
currentKey = key;
if (columnNames.contains(key)) {
if (values.get(key ) == null ) {
this._properties.putNull(key);
} else if (values.get(key) instanceof String) {
this._properties.put(key, values.getAsString(key));
} else if (values.get(key) instanceof Integer) {
this._properties.put(key, values.getAsInteger(key));
} else if (values.get(key) instanceof Boolean) {
this._properties.put(key, values.getAsBoolean(key));
} else if (values.get(key) instanceof …Run Code Online (Sandbox Code Playgroud) 我有一个可以在Eclipse中正常运行的项目,但是运行独立的jar将在运行时为类提供java.lang.NoSuchMethodError。
我解压缩了jar文件,可以在jar中的一个库文件中看到类文件,并且确实看到了在类中定义的方法。唯一的例外不是找不到类,而是在类中找不到方法。
在互联网上找不到任何有用的信息来解决该问题。