I have set android:onclick in xml for an imageButton and put that method in my activity. In android s below 5 it works fine but in android 5 it gives me Error.
My imageButton code:
<ImageButton
android:id="#+id/photo_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/detail_icon"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/image_background"
android:onClick="photoDetailButtonMethod"/>
My method code:
public void photoDetailButtonMethod(View theButton)
{
//something
}
The error:
java.lang.IllegalStateException: Could not find a method photoDetailButtonMethod(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.widget.ImageButton with id 'photo_detail'
at android.view.View$1.onClick(View.java:3994)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19749)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NoSuchMethodException: photoDetailButtonMethod [class android.view.View]
at java.lang.Class.getMethod(Class.java:664)
at java.lang.Class.getMethod(Class.java:643)
at android.view.View$1.onClick(View.java:3987)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19749)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
By looking the error I can see it searching for my method in android.view.ContextThemeWrapper class so it endup with NoSuchMethodException.
I can't figure out how to solve this, any help?
1) I already added tools:context=".PhotoViewerActivity" in the root of my layout.
2) The activiy extends ActionBarActivity with appCompat theme.
I had a very similar problem, it happens only on Android Lollipop, whilst it works fine on the older versions. Looks like a bug or undocumented feature in 5.0.
Make sure that in the layout file where your ImageButton resides there is no android:theme set, i.e. nothing like this:
android:theme="#style/Base.Theme.AppCompat.Light"
Instead, define your application theme in AndroidManifest.xml application element:
<application
...
android:theme="#android:style/Theme.Holo.Light"
... >
i can't find what is the real problem, maybe some incompatiblity between eclipse and api 21 or something else.
for now i just set an onClickListener for that button.
finally i found the problem.
all i need is to associate the xml layout to an activity. for this in the design tab of xml layout make sure you selected the right activity.
It happens when you have declared the public void onClick(View view) method inside the fragment instead of activity
Be sure that your onClick method
public void photoDetailButtonMethod(View theButton)
{
//something
}
is written outside onCreate() method and in your Activity class.
I was doing this with a "menuItem", and had this:
public void photoDetailButtonMethod(View theButton)
{
//something
}
Which is wrong for menuItems. Then you must have this:
public void photoDetailButtonMethod(MenuItem theButton)
{
//something
}
It was throwing the same error as mentioned by the OP.
Hope this helps someone...
Its just google play services issue and nothing to do with your coding or settings blah blah...
just update your google play services of phone and add dependencies in build.gradle file like:
compile 'com.google.android.gms:play-services:7.5.0'
Related
I'm getting following exception if sometimes thought of posting it after a month. Every time I have to delete build folder and error goes away. So it is risky to stay like this condition for long run, as sometimes developer might forget to check this activity is opening or not.
So far strangely it is only happening with one file ProductListActivity.kt
This runtime error looks like common error Is there a Gradle configurations needed to fix it.
How to completely get rid of it?
java.lang.RuntimeException: Unable to start activity ComponentInfo ProductDetails.activity.ProductListActivity}: java.lang.IllegalStateException: Required view 'name_text_box' with ID 2131362920 for method 'onNearbyClicked' was not found. If this view is optional add '#Nullable' (fields) or '#Optional' (methods) annotation.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.IllegalStateException: Required view 'name_text_box' with ID 2131362920 for method 'onNearbyClicked' was not found. If this view is optional add '#Nullable' (fields) or '#Optional' (methods) annotation.
at butterknife.internal.Utils.findRequiredView(Utils.java:88)
at ProductDetails.activity.ProductListActivity_ViewBinding.<init>(ProductListActivity_ViewBinding.java:27)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at butterknife.ButterKnife.bind(ButterKnife.java:170)
at butterknife.ButterKnife.bind(ButterKnife.java:99)
at common.BaseActivity.setContentView(BaseActivity.java:51)
at ProductDetails.activity.ProductListActivity.onCreate(ProductListActivity.kt:220)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at and
What i can see from the logs that you are using kotlin, so instead of butterknife you can replace your code with view binding(area which are getting error)
https://kotlinlang.org/docs/tutorials/android-plugin.html
I am using Nexus 6 (API 22) . I want to add some more options when user long press on Edittext. Normally when we long press on Edittext, paste popup menu will appear and I want to add some more features in addtion to paste menu.
Android documentation says, when we implement setCustomInsertionActionModeCallback we can override the behaviour but in my case it is not working. But in Nexus 6P (API 23) it is working fine.Any help will be appreciated.
This is the error I've got while implementing setCustomInsertionActionModeCallback
java.lang.NoSuchMethodError: No virtual method setCustomInsertionActionModeCallback(Landroid/view/ActionMode$Callback;)V in class L/view/WriterEditText; or its super classes (declaration of 'view.WriterEditText' appears in /data/app/-1/base.apk)
at .EditorViewManager.createEditText(EditorViewManager.java:79)
at render.EditorViewManager.createViewAtIndex(EditorViewManager.java:207)
at render.Renderer.renderContent1(Renderer.java:158)
at render.Renderer.renderContent(Renderer.java:135)
at .render.Renderer.reloadDocument(Renderer.java:704)
at EditorActivity.onCreate(EditorActivity.java:89)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
That method was added in API Level 23. You cannot use it on older devices. You are welcome to wrap your call in a Build version check:
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.M) {
// call that method
}
I have imported my eclipse project to Android studio everything is working fine. I have custom Actionbar
which is like this: Oncreate of an activity I have the following
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getActionBar().setCustomView(R.layout.bartitle);
TextView textViewTitle = (TextView) findViewById(R.id.titleEDIT);
textViewTitle.setText(res.getString(R.string.title));
setContentView(R.layout.register);
and now I have added Style for v21 too.
Style.xml for version 21 has the following:
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowActionBar">true</item>
</style>
</resources>
When I run the project: I get a white Screen and force Close with the following error log:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.flm.sPar/com.flm.sPar.Register}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setCustomView(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setCustomView(int)' on a null object reference
at com.flm.sPar.Register.onCreate(Register.java:71)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
I have been trying to solve this issue. Trying out all solutions given on SO or Google but couldn't get to solve the issue. Hence thought of asking a question on SO.
Thanks!
Use getSupportActionBar() instead of getActionBar() because you are using AppCompat library. If you're using the v7 appcompat library, your activity should instead extend AppCompatActivity and not Activity.
ActionBarActivity is deprecated in revision 22.1.0 of the Support Library and so AppCompatActivity should be used instead of ActionBarActivity as suggested by a user in comments.
Hope this will solve your issue :)
I'm having a serious problem with a runtime exception when inflating an XML layout that includes the XWalkView...
Stack trace :
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Use SharedXWalkView if you want to support shared mode
at org.xwalk.core.ReflectionHelper.handleException(ReflectionHelper.java:233)
at org.xwalk.core.ReflectionHelper.handleException(ReflectionHelper.java:237)
at org.xwalk.core.ReflectionHelper.init(ReflectionHelper.java:132)
at org.xwalk.core.ReflectionHelper.loadClass(ReflectionHelper.java:199)
at org.xwalk.core.ReflectionHelper$ConstructorHelper.loadConstructor(ReflectionHelper.java:37)
at org.xwalk.core.ReflectionHelper.createInstance(ReflectionHelper.java:246)
at org.xwalk.core.XWalkView.<init>(XWalkView.java:169)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.bean.project.XWalkUIActivity.onCreate(XWalkUIActivity.java:51)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.RuntimeException: Use SharedXWalkView if you want to support shared mode
at org.xwalk.core.ReflectionHelper.handleException(ReflectionHelper.java:237)
at org.xwalk.core.ReflectionHelper.init(ReflectionHelper.java:132)
XML :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/com_bean_project_content"
android:theme="#style/com_bean_project_black" >
<!-- bottom controls -->
<RelativeLayout
android:id="#+id/com_bean_project_bottom_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<!-- some buttons, nothing to worry about -->
</RelativeLayout>
<!-- fills most of the parent view -->
<org.xwalk.core.XWalkView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/com_bean_project_webview"
android:layout_alignParentTop="true"
android:layout_above="#id/com_bean_project_bottom_layout"/>
</RelativeLayout>
Things I have done :
1) in Android Studio, I am using the armeabi-v7a folder from the library and xwalk_core_library_java_app_part.jar and xwalk_core_library_java_library_part.jar both of these are included in the dependencies. I don't know whether I should only use one of those jar's? I couldn't find anything about it in any documents.
2) the activity with XWalkView has android:hardwareAccelerated="true"
3) on the crosswalk downloads page (https://crosswalk-project.org/documentation/downloads.html) I have downloaded version 11.40.277.7 of Android webview (ARM)
4) I also merged the "res" folder from crosswalk into my project, but this makes no difference.
5) I've also tried programmatic inflation, however, it also excepts just with a new XWalkView(mParentActivity, mParentActivity); (I know, silly constructor):
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Use SharedXWalkView if you want to support shared mode
at org.xwalk.core.ReflectionHelper.handleException(ReflectionHelper.java:233)
at org.xwalk.core.ReflectionHelper.handleException(ReflectionHelper.java:237)
at org.xwalk.core.ReflectionHelper.init(ReflectionHelper.java:132)
at org.xwalk.core.ReflectionHelper.loadClass(ReflectionHelper.java:199)
at org.xwalk.core.ReflectionHelper$ConstructorHelper.loadConstructor(ReflectionHelper.java:37)
at org.xwalk.core.ReflectionHelper.createInstance(ReflectionHelper.java:246)
at org.xwalk.core.XWalkView.<init>(XWalkView.java:192)
For inspiration, I've looked at https://crosswalk-project.org/apis/embeddingapidocs/reference/org/xwalk/core/XWalkView.html however, it's no help on this issue.
Maybe this will help you:
At first i also tried to use jars in my app. That didn't work and i got the same exceptions as you.
Then i stumbled upon this sample app that shows how to use Crosswalk.
I then copied the build into my app and everything worked ok.
Here is what i added in my gradle file:
in the repositories section i added one line (below the crashlytics..)
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven'}
maven { url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'}
}
In the dependencies section i also added one line - the last one:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'org.xwalk:xwalk_core_library:10.39.235.15'
}
This is the xml for the activity:
<org.xwalk.core.XWalkView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/walk_view"
android:layout_width="fill_parent"
android:background="#000000"
android:layout_height="fill_parent"
/>
And this is how i use it in the java code:
private void setXView(){
mXview = (XWalkView)findViewById(R.id.walk_view);
mXview.load("http://www.cnn.com",null);
}
Don't forget to delete the jars in your app or you might get a compilation error if you have fileTree(dir: 'libs', include: ['*.jar']) in your dependencies.
After a day of insane experimentation, I finally gave up on trying to store a local copy of the library.
Instead, I went with Maven using these instructions: https://crosswalk-project.org/documentation/embedding_crosswalk/crosswalk_aar.html
At the bottom of that page is a link to a sample app that's set up with Maven - which is useful.
Note: to find out what versions of the library are available, go here: https://download.01.org/crosswalk/releases/crosswalk/android/maven2/org/xwalk/xwalk_core_library/
for example, instead of the "beta" dependency, you would have compile 'org.xwalk:xwalk_core_library:12.41.296.5'
After having it set up with maven, I then reverted to the XML inflation.
However, I was then faced with
04-02 16:38:31.036 14165-14165/com.bean.project W/System.err﹕ Caused by: java.lang.ClassCastException: android.view.ContextThemeWrapper cannot be cast to android.app.Activity
04-02 16:38:31.037 14165-14165/com.bean.project W/System.err﹕ at org.xwalk.core.internal.XWalkViewInternal.<init>(XWalkViewInternal.java:197)
04-02 16:38:31.037 14165-14165/com.bean.project W/System.err﹕ at org.xwalk.core.internal.XWalkViewBridge.<init>(XWalkViewBridge.java:46)
the insanity continues...
public XWalkViewInternal(Context context, AttributeSet attrs) {
super(convertContext(context), attrs);
checkThreadSafety();
mActivity = (Activity) context;
mContext = getContext();
init(mContext, attrs);
}
how can they possibly think that's a good idea ??!! /facepalm
EDIT: to get the XWalkView added to a layout programmatically I put a placeholder (empty) RelativeLayout in the XML with ID FULLSCREEN_YOUTUBE_CONTAINER_ID and then in onCreate() of the activity I did:
mYoutubeVideoViewContainer = (RelativeLayout) mLayoutView.findViewById(FULLSCREEN_YOUTUBE_CONTAINER_ID);
mYoutubeWebView = new XWalkView(mParentActivity, mParentActivity);
RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
mYoutubeVideoViewContainer.addView(mYoutubeWebView, relativeParams);
I have a project which uses two modules(libraries), I created some activity and its respective layout file in one of my library, I can't seem to add new views in that layout (Textview, Imageview etc). Here is the logcat output.
java.lang.NoSuchFieldError: No static field tv of type I in class Lcom/camera/sushant/opencamera/R$id; or its superclasses (declaration of 'com.camera.sushant.opencamera.R$id' appears in /data/app/com.streetspotr.streetspotr.staging-1/base.apk)
at com.camera.opencamera.MediaPreview.onCreate(MediaPreview.java:89)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Apparently what was happening, I had layout with same name in my app module and my library module. So when packaging the application it was always taking the layout from my app module not library module. So I had to delete the layout in my app module and everything worked fine.
Moving a resource from your project to a library can lead to this problem as well. If you did this, cleaning the project solves the problem...