Android no such method

Android app- No such method exception

I am trying to create an android app that involves pressing a button that takes a picture. My code is clean without any warnings or errors but when I run it on the emulator, and as soon as I press the photo button in the app, it says that your app has stopped.When I check the log file for the explanation it gives me the following

Any help would be appreciated. Thank you in advance.

Here is my code

3 Answers 3

the error says: could not find a method dispatchTakePhotoIntent(View)

You a calling dispatchTakePhotoIntent with a View object as an argument to it whereas in your code you have defined:

which takes an integer as an argument.

There is a problem in the way you are calling your method inside your code.

create a constant in the class which calls the method

and call the method as

and inside your method test for the request code:

and the problem is that you are calling the method by passing to it the view in which the image is being rendered/displayed rather than the action which you want to carry. So the compiler found a call to the method of type dispatchTakePhotoIntent(View) which it could not find in your code since you have defined dispatchTakePhotoIntent(int).

if you are developing in eclipse you should be getting an error in your code (a red cross on the line where the error is).

Источник

NoSuchMethodError android

I have a serious problem. after making a test using espresso when I ran the test this complex error appears

java.lang.NoSuchMethodError: No static method setFactory2(Landroid/view/LayoutInflater;Landroid/view/LayoutInflater$Factory2;)V in class Landroid/support/v4/view/LayoutInflaterCompat; or its super classes (declaration of ‘android.support.v4.view.LayoutInflaterCompat’ appears in /data/app/com.example.master.bakingapp.test-ZVHwTuzx1ipxW0iPyBZKBw==/base.apk) at android.support.v7.app.AppCompatDelegateImpl.installViewFactory(AppCompatDelegateImpl.java:1299) at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:72) at com.example.master.bakingapp.MainActivity.onCreate(MainActivity.java:61) at android.app.Activity.performCreate(Activity.java:7136) at android.app.Activity.performCreate(Activity.java:7127) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) at android.support.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:667) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Test running failed: Instrumentation run failed due to ‘Process crashed.’

Читайте также:  Тест попугаев для андроид

it’s Pointed to onCreate on my MainActivity

at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:72) at com.example.master.bakingapp.MainActivity.onCreate(MainActivity.java:61)

I tried to debug my test. and it’s stuck in onCreate

and this is my whole test code

and gradle module

and my Fragment hosted by MainActivity

NOTE: when I change my MainActivity to extends Activity instead of AppCompatActivity it’s worked but I have too many support version

I did not solve this problem in 3 days. I really need help

Источник

No such method error org.json.JSONObject.putOnce — Android 4.4.2 #122

Comments

alexandruMihalcea commented Mar 27, 2014

We are using the library in an Android application. Besides having to use a custom apache httpclietandroidlib (the one built into android is an older version) we found an issue when calling RedmineManager.update(issue) :
No such method error org.json.JSONObject.putOnce
What is strange is that the method is defined in org.json.JSONObject
public JSONObject putOnce(String key, Object value) throws JSONException @ line 1160.
Also, JSONObject is on the imports list.

The text was updated successfully, but these errors were encountered:

maxkar commented Mar 27, 2014

Looks like a classpath problem. There are two probable causes:

  1. Android have one or more of org.json.* classes as a built-in class.
  2. You build tool fails to properly handle library versions. Usually this leads to several versions of the same library on the runtime classpath. For example, maven cannot manage library versions properly.

We cannot test our library on android because we have no androids at all (and supporting android will require to add on-device tests). Feel free to investigate this problem yourself and provide us patches if necessary.

Please note that putOnce is not used in our code. So it will be handful to see a full stacktrace. This may provide some insights on the classpath elements.

alexandruMihalcea commented Mar 28, 2014

Does this help?
03-28 13:48:55.418: W/asset(15126): Copying FileAsset 0x726fffa8 (zip:/data/app/com.example.redmineimageuploader-2.apk:/resources.arsc) to buffer size 4148 to make it aligned.
03-28 13:48:55.769: I/Adreno-EGL(15126): : EGL 1.4 QUALCOMM build: (CL4169980)
03-28 13:48:55.769: I/Adreno-EGL(15126): OpenGL ES Shader Compiler Version: 17.01.10.SPL
03-28 13:48:55.769: I/Adreno-EGL(15126): Build Date: 12/25/13 Wed
03-28 13:48:55.769: I/Adreno-EGL(15126): Local Branch:
03-28 13:48:55.769: I/Adreno-EGL(15126): Remote Branch:
03-28 13:48:55.769: I/Adreno-EGL(15126): Local Patches:
03-28 13:48:55.769: I/Adreno-EGL(15126): Reconstruct Branch:
03-28 13:48:57.981: D/libc(15126): [NET] getaddrinfo+,hn 22(0x6d616e6167656d),sn(),family 0,flags 4
03-28 13:48:57.981: D/libc(15126): [NET] getaddrinfo-,err=8
03-28 13:48:57.981: D/libc(15126): [NET] getaddrinfo+,hn 22(0x6d616e6167656d),sn(),family 0,flags 1024
03-28 13:48:57.981: D/libc(15126): [NET] getaddrinfo-, 1
03-28 13:48:57.981: D/libc(15126): [NET] getaddrinfo_proxy+
03-28 13:48:58.501: D/libc(15126): [NET] getaddrinfo_proxy-, success
03-28 13:49:00.564: W/dalvikvm(15126): VFY: unable to resolve direct method 13061: Lorg/json/JSONException;. (Ljava/lang/Throwable;)V
03-28 13:49:00.564: W/dalvikvm(15126): VFY: unable to resolve direct method 13061: Lorg/json/JSONException;. (Ljava/lang/Throwable;)V
03-28 13:49:00.564: W/dalvikvm(15126): VFY: unable to resolve virtual method 13128: Lorg/json/JSONObject;.putOnce (Ljava/lang/String;Ljava/lang/Object;)Lorg/json/JSONObject;
03-28 13:49:00.564: W/dalvikvm(15126): VFY: unable to resolve direct method 13061: Lorg/json/JSONException;. (Ljava/lang/Throwable;)V
03-28 13:49:00.564: W/dalvikvm(15126): VFY: unable to resolve static method 13138: Lorg/json/JSONObject;.valueToString (Ljava/lang/Object;)Ljava/lang/String;
03-28 13:49:00.564: W/System.err(15126): java.util.concurrent.ExecutionException: java.lang.NoSuchMethodError: org.json.JSONObject.putOnce
03-28 13:49:00.564: W/System.err(15126): at java.util.concurrent.FutureTask.report(FutureTask.java:93)
03-28 13:49:00.564: W/System.err(15126): at java.util.concurrent.FutureTask.get(FutureTask.java:163)
03-28 13:49:00.564: W/System.err(15126): at android.os.AsyncTask.get(AsyncTask.java:483)
03-28 13:49:00.564: W/System.err(15126): at com.example.redmineimageuploader.ShowRedmineProjectsActivity.onCreate(ShowRedmineProjectsActivity.java:41)
03-28 13:49:00.564: W/System.err(15126): at android.app.Activity.performCreate(Activity.java:5312)
03-28 13:49:00.564: W/System.err(15126): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
03-28 13:49:00.564: W/System.err(15126): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2552)
03-28 13:49:00.574: W/System.err(15126): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2653)
03-28 13:49:00.574: W/System.err(15126): at android.app.ActivityThread.access$800(ActivityThread.java:156)
03-28 13:49:00.574: W/System.err(15126): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
03-28 13:49:00.574: W/System.err(15126): at android.os.Handler.dispatchMessage(Handler.java:102)
03-28 13:49:00.574: W/System.err(15126): at android.os.Looper.loop(Looper.java:157)
03-28 13:49:00.574: W/System.err(15126): at android.app.ActivityThread.main(ActivityThread.java:5872)
03-28 13:49:00.574: W/System.err(15126): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 13:49:00.574: W/System.err(15126): at java.lang.reflect.Method.invoke(Method.java:515)
03-28 13:49:00.574: W/System.err(15126): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1069)
03-28 13:49:00.574: W/System.err(15126): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)
03-28 13:49:00.574: W/System.err(15126): at dalvik.system.NativeStart.main(Native Method)
03-28 13:49:00.574: W/System.err(15126): Caused by: java.lang.NoSuchMethodError: org.json.JSONObject.putOnce
03-28 13:49:00.574: W/dalvikvm(15126): threadid=12: thread exiting with uncaught exception (group=0x41608e18)
03-28 13:49:00.574: W/System.err(15126): at org.json.JSONWriter.key(JSONWriter.java:208)
03-28 13:49:00.574: W/System.err(15126): at com.taskadapter.redmineapi.internal.RedmineJSONBuilder.toSimpleJSON(RedmineJSONBuilder.java:218)
03-28 13:49:00.574: W/System.err(15126): at com.taskadapter.redmineapi.internal.Transport.updateObject(Transport.java:241)
03-28 13:49:00.574: W/System.err(15126): at com.taskadapter.redmineapi.RedmineManager.update(RedmineManager.java:301)
03-28 13:49:00.574: W/System.err(15126): at com.example.redmineimageuploader.models.GetProjects.doInBackground(GetProjects.java:42)
03-28 13:49:00.584: W/System.err(15126): at com.example.redmineimageuploader.models.GetProjects.doInBackground(GetProjects.java:1)
03-28 13:49:00.584: W/System.err(15126): at android.os.AsyncTask$2.call(AsyncTask.java:288)
03-28 13:49:00.584: W/System.err(15126): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-28 13:49:00.584: W/System.err(15126): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
03-28 13:49:00.584: W/System.err(15126): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
03-28 13:49:00.584: W/System.err(15126): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-28 13:49:00.584: W/System.err(15126): at java.lang.Thread.run(Thread.java:864)
03-28 13:49:00.584: W/dalvikvm(15126): threadid=1: thread exiting with uncaught exception (group=0x41608e18)
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): crash in the same process: main
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): java.lang.RuntimeException: Unable to start activity ComponentInfo: java.lang.NullPointerException
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2653)
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): at android.app.ActivityThread.access$800(ActivityThread.java:156)
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): at android.os.Handler.dispatchMessage(Handler.java:102)
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): at android.os.Looper.loop(Looper.java:157)
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): at android.app.ActivityThread.main(ActivityThread.java:5872)
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): at java.lang.reflect.Method.invoke(Method.java:515)
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1069)
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): at dalvik.system.NativeStart.main(Native Method)
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): Caused by: java.lang.NullPointerException
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): at com.example.redmineimageuploader.ShowRedmineProjectsActivity.onCreate(ShowRedmineProjectsActivity.java:49)
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): at android.app.Activity.performCreate(Activity.java:5312)
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2552)
03-28 13:49:00.594: E/AndroidRuntime_2_crash(15126): . 11 more
03-28 13:49:00.594: E/AndroidRuntime(15126): FATAL EXCEPTION: AsyncTask #1
03-28 13:49:00.594: E/AndroidRuntime(15126): Process: com.example.redmineimageuploader, PID: 15126
03-28 13:49:00.594: E/AndroidRuntime(15126): java.lang.RuntimeException: An error occured while executing doInBackground()
03-28 13:49:00.594: E/AndroidRuntime(15126): at android.os.AsyncTask$3.done(AsyncTask.java:300)
03-28 13:49:00.594: E/AndroidRuntime(15126): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
03-28 13:49:00.594: E/AndroidRuntime(15126): at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
03-28 13:49:00.594: E/AndroidRuntime(15126): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
03-28 13:49:00.594: E/AndroidRuntime(15126): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
03-28 13:49:00.594: E/AndroidRuntime(15126): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
03-28 13:49:00.594: E/AndroidRuntime(15126): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-28 13:49:00.594: E/AndroidRuntime(15126): at java.lang.Thread.run(Thread.java:864)
03-28 13:49:00.594: E/AndroidRuntime(15126): Caused by: java.lang.NoSuchMethodError: org.json.JSONObject.putOnce
03-28 13:49:00.594: E/AndroidRuntime(15126): at org.json.JSONWriter.key(JSONWriter.java:208)
03-28 13:49:00.594: E/AndroidRuntime(15126): at com.taskadapter.redmineapi.internal.RedmineJSONBuilder.toSimpleJSON(RedmineJSONBuilder.java:218)
03-28 13:49:00.594: E/AndroidRuntime(15126): at com.taskadapter.redmineapi.internal.Transport.updateObject(Transport.java:241)
03-28 13:49:00.594: E/AndroidRuntime(15126): at com.taskadapter.redmineapi.RedmineManager.update(RedmineManager.java:301)
03-28 13:49:00.594: E/AndroidRuntime(15126): at com.example.redmineimageuploader.models.GetProjects.doInBackground(GetProjects.java:42)
03-28 13:49:00.594: E/AndroidRuntime(15126): at com.example.redmineimageuploader.models.GetProjects.doInBackground(GetProjects.java:1)
03-28 13:49:00.594: E/AndroidRuntime(15126): at android.os.AsyncTask$2.call(AsyncTask.java:288)
03-28 13:49:00.594: E/AndroidRuntime(15126): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-28 13:49:00.594: E/AndroidRuntime(15126): . 4 more
03-28 13:49:02.716: D/Process(15126): killProcess, pid=15126
03-28 13:49:02.716: D/Process(15126): com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException:131 java.lang.ThreadGroup.uncaughtException:693 java.lang.ThreadGroup.uncaughtException:690

Читайте также:  Обрезать изображение android studio

alexeyOnGitHub commented Sep 11, 2014

@alexandruMihalcea , is the problem still reproducible with the latest code in «master» on the latest Android OS?

alexeyOnGitHub commented Sep 24, 2014

we can’t realistically support Android without having a complete setup of test devices/services. no response from the user — closing the issue.

lavinathong commented Oct 23, 2014

Hi, I run into this same problem.
My project build target is set to Android 4.4.2. (adt-bundle-windows-x86_64-20130917 android-19)
The application is running on Google Nexus 7 with Android 4.4.3.

It happened in jsonWriter.key() called as follows:

JSONWriter jsonWriter = new JSONWriter(stringWriter);
jsonWriter.key(«any string»);

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

Источник

Оцените статью