Android java.lang.VerifyError only on 1.5 - android

I have the following code which gets call in my main activity's onCreate method
public static ErrorReporter getInstance(){
if (instance == null){
instance = new ErrorReporter();
}
return instance;
}
Only on android 1.5 calling the above method causes java.lang.VerifyError. I am not able to figure out why this is happening. Any hints on how to solve this problem

Simply do a build on 1.5 and you'll see where is the culprit...

I got exactly the same problem when i try to set the listadatper for a listview :)
check this
private void setResultListListAdapter() {
mListAdapter_ = new ListAdapter(mContext_,
R.layout.dsg_detailed_list_row, mLstStops_);
setListAdapter(mListAdapter_);
}
gets a VerifyError before mListAdapter_ gets initialized.. so something with this...
new ListAdapter(mContext_,
R.layout.dsg_detailed_list_row, mLstStops_);
but there's nothing which is just available in 1.5 :=//
strange thing...
also in 2 other classes this code works just fine... :=)
hope someone knowes more, thanks a lot!
(everything initialized, everything checked...setListAdapter never gets called)
SOLUTION (for me)
it really was a method which wasn't supported in Android 1.5
mConvertView_.setTag(uniqueIntID, ViewHolder);
ViewHolder is a static class, instead of using normal View.gettag(),
because of different layouts i was using the above method.. so :=)
the second is supported, View.getTag()

I was using a function in ErrorReporter class which was not available in 1.5. Used reflection to take care of the unavailable function and the error is gone.

Related

How to call javascript method in react-native on Android platform?

When I click a button in native UI (probably from a fragment container) , I wanna invoke a method from JavaScript, let's call it just like 'jsMethod' or other else. However, I have never handled this situation before.
I am looking up some relative codes from Facebook's document on website and can not find out the key to the problem so far. Anyone give me some suggestions?
To call a JavaScript method from Java, do something like this:
ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
CatalystInstance catalystInstance = reactContext.getCatalystInstance();
WritableNativeArray params = new WritableNativeArray();
params.pushString("Message to show using nameOfJsMethod");
catalystInstance.callFunction("JavaScriptVisibleToJava", "nameOfJsMethod", params);
The JavaScript method you want to call must be defined and made visible to Java:
import BatchedBridge from "react-native/Libraries/BatchedBridge/BatchedBridge";
export class ExposedToJava {
nameOfJsMethod(message) {
alert(message);
}
}
const exposedToJava = new ExposedToJava();
BatchedBridge.registerCallableModule("JavaScriptVisibleToJava", exposedToJava);
This sample on Github includes a working demo.
EDIT I'm told this approach is not officially documented. If your scenario allows, consider taking the advice of #ufxmeng (in the comment to the OP) instead.

Xamarin Forms Custom Renderer for Android not displaying

I am trying to render a checkbox in a Xamarin Forms app. There is nothing rendered at runtime, as far as I can tell the renderer is not even getting called.
Does anyone understand what I am missing or doing incorrectly?
Here is my class in Forms:
public class LegalCheckbox : View
{
public LegalCheckbox ()
{
}
}
And my custom renderer class in Droid:
public class CheckBoxRenderer : ViewRenderer<LegalCheckbox, CheckBox>
{
protected override void OnElementChanged (ElementChangedEventArgs<LegalCheckbox> e)
{
base.OnElementChanged (e);
CheckBox control = new Android.Widget.CheckBox(this.Context);
control.Checked = false;
control.Text = "I agree to terms";
control.SetTextColor (Android.Graphics.Color.Rgb (60, 60, 60));
this.SetNativeControl(control);
}
}
Along with the Assembly Directive:
[assembly: ExportRenderer(typeof(demo.LegalCheckbox), typeof(demo.Droid.CheckBoxRenderer))]
Took your code and fired up a new project with it. The code appears to function fine.
Only thin I can think that might be causing you an issue is the location of you assembly attribute. I typically place them just above the namespace declaration in the same file as my renderer.
I threw what I created up on my github maybe you can spot the difference.
https://github.com/DavidStrickland0/Xamarin-Forms-Samples/tree/master/RendererDemo
#Thibault D.
Xlabs isn't a bad project but its basically just all the code the opensource community came up with during the first year or so of Xamarin.Forms life. Its not really "Their Labs projects" and considering how much of it is marked up with Alpha Beta and the number of bugs in their issues page it's probably best not to imply that the Xamarin company has anything to do with it.
I am not sure if that is the issue but it would make more sense to me if your LegalCheckbox would inherit from a InputView rather than View.
Also, even if Xamarin.Forms does not have a Checkbox control you can still have a look at their "Labs" project here:
https://github.com/XLabs/Xamarin-Forms-Labs/wiki/Checkbox-Control
(And I can actually see that they inherit from View...)

Andengine, can't find a way to work with tilting/accelerometer

I saw online this code used a lot:
public void onAccelerometerChanged(final AccelerometerData myAccelerometerData) {)
When I try to use it, eclipse will not recognize the AccelerometerData class.
I'm having a hard time:
Detecting tilt.
Using it to change the worlds physics with box2d.
It would help me if anyone could show me ways of detecting tilting and using it.
Thank you.
You can see this code used in the PhysicsExample where it is used to change the center of gravity.
You must use the same code branch as the one in the example you have found. Notice that I linked GLES2-AnchorCenter branch version of the PhysicsExample. This branch is the newest. There is no AccelerometerData class. It has been renamed to AccelerationData.
Tilting (phone orientation) can be detected in a similar fashion. You have to call the following methods in your Activity and pass the correct listener.
protected boolean enableOrientationSensor(final IOrientationListener pOrientationListener) {
return this.mEngine.enableOrientationSensor(this, pOrientationListener);
}
protected boolean enableOrientationSensor(final IOrientationListener pOrientationListener, final OrientationSensorOptions pLocationSensorOptions) {
return this.mEngine.enableOrientationSensor(this, pOrientationListener, pLocationSensorOptions);
}

notifyDatasetChanged does not work on Gridview, unless devices has been rotated

This is really an odd problem. The basic gist of it is what the title says. I have an adapter, which I am updating and calling notifyDatasetChanged() The problem however, is it does not work, unless the device has been rotated at least once. I can't for the life of me figure out why, what is being done differently after a rotation occurs?
The code in question is here:
The ASyncTask that handles it..
protected void onPostExecute(ArrayList<Records> result) {
if (ca == null)
{
ca = new CoverAdapter<Records>(c, R.layout.grid_cover_with_text_item, result);
}
if (gv.getAdapter() == null)
{
gv.setAdapter(ca);
}
else
{
new AdapterHelper().update((CoverAdapter) ca, result);
ca.notifyDataSetChanged;
}
}
With "ca" being my adapter, "gv" being my GridView and AdapterHelper().update being a method I found here to clear the adapter and add all the results of the arraylist to it, so it should be being updated properly.
Remember, this code works after the device has been rotated. Very confused right now, any insight would be appreciated. Thanks in advance.
Use the debugger and step through the code to check what is expected actually happens.
Glad you found the problem... Now you can ditch the AdapterHelperclass which is a waste.

NPE in Android WebView

I'm getting a NullPointerException on the following call in Android 2.3.4:
java.lang.NullPointerException
at android.webkit.WebView.addPackageNames(WebView.java:4063)
at com.my.company.MyClass$MyInnerClass.myMethod(MyClass.java:283)
at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
at android.webkit.BrowserFrame.loadUrl(BrowserFrame.java:246)
at android.webkit.WebViewCore.loadUrl(WebViewCore.java:1981)
at android.webkit.WebViewCore.access$1400(WebViewCore.java:53)
at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1122)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:674)
at java.lang.Thread.run(Thread.java:1019)
MyClass$MyInnerClass is added to the JavaScript interface as
class MyClass {
// ...
myWebView.addJavascriptInterface(new MyInnerClass(), "MyInnerClass");
// ...
public void myOuterMethod(int param1, int param2) {
// Notify a listener that myOuterMethod was called
}
private class MyInnerClass {
public void myMethod(int param1, int param2) {
myOuterMethod(param1, param2);
}
}
}
So, the JavaScript call MyInnerClass.myMethod(-1, -1) seems to come over the Java-JavaScript bridge fine, but fails in the addPackageNames call, which isn't my code.
I've looked at the android.webkit.WebView class in GrepCode, but I can't figure out how I could have caused this. The only line in addPackageNames is
public void addPackageNames(Set<String> packageNames) {
mWebViewCore.sendMessage(EventHub.ADD_PACKAGE_NAMES, packageNames);
}
So, I've come to the conclusion that either mWebViewCore or EventHub is null.
Can any Android experts shed some light on this? Is this a known bug? Did I cause this? If so, how? If not, how might I prevent this?
This is definitelly related to the mWebViewCore being set to null.
mWebViewCore is instantiated inside of the ViewView's constructor. And the only place where it is set to null is a public method destroy().
Do you call webView.destroy() anywhere in the code?
It seems to me that your problem is that the outer class has not been instantiated when your myMethod is called. What's a bit interesting here is that the internal code that seems to be breaking in your case is no longer there in the Android 4.0 source code - so your issue might not occur on that version of Android. To me this also indicates that there were some issues with the previous version of Android Webview and perhaps you are encountering an issue with Android. But that's just speculation, my experience usually is that I'm doing something wrong, not the Android team :)
What could be a solution would be to wrap your code in an if statement:
if(MyClass.this != null) {
myOuterMethod(param1, param2);
}
This is not a beautiful solution but if it works I think it won't break anything.

Categories

Resources