In some case, when accessing an activity field from an anonymous class, I get NoSuchFieldError at runtime: java.lang.NoSuchFieldError: MyActivity.myField
EDIT: I'm now sure that it's an Android issue, because everything compiles correctly but resolved incorrectly at runtime. When changing to MyActivity.this.myField instead of plain myField, everything works perfect.
BTW, I rechecked and I don't have any other myField anywhere else, Also, when opening declaration in Eclipse, it goes to the intended field (myField).
The only problem is that I couldn't reproduce this in a sample project. I'm left only to state that it's a specific problem in my project, but I'm reluctant doing so and I can't publish this project.
I'll keep this open in case someone stumbles upon something similar.
Here's the code that I can publish that crashes my project but not the sample one:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new Runnable() {
#Override
public void run() {
Toast.makeText(MyActivity.this, myField.getName(), Toast.LENGTH_SHORT).show();
}
}.run();
}
It seems that accessing the field with the class' prefix solves it: MyActivity.this.myField
Strange. I guess it's something with Android's field resolution in runtime.
Related
I tried implementing react-native-draggable-flatlist to my project, but I'm not able to drag the elements. I am able to "pick them" (They get bigger if I press them), but I can't move them to another position.
I had this problem before and found a working soloution in a GitHub issue, but as it seems, MainActivity.java has changed in some version and I don't know how to correctly upgrade it.
The soloution I found:
When I add the #Override for the ReactActivityDelegate, my App crashes after the build.
I noticed that my MainActivity.java looks a little bit different, it seems like the ActivityDelegate is Managed through a class called MainActivityDelegate which extends ReactActivityDelegate:
public static class MainActivityDelegate extends ReactActivityDelegate {
public MainActivityDelegate(ReactActivity activity, String mainComponentName) {
super(activity, mainComponentName);
}
#Override
protected ReactRootView createRootView() {
ReactRootView reactRootView = new ReactRootView(getContext());
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
return reactRootView;
}
}
It seems like I have to change something here to achieve the same result, but I don't really know what.
EDIT:
According to the RNGH docs you shouldn't change your MainActivity.java that way anymore and wrap your whole App into a GestureHandlerRootView. Some Libaries like react-native-navigation do this by default (in my case). BEcause of that (I think) my App gets completely grey when I use a GestureHandlerRootView. If I don't addd it myself, so I use the one from neavigaion, I still can't drag the items in my list.
I fixed it by wrapping my screen component in a GestureHandlerRootView
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...)
I'm using Eclipse Indigo to develop Android application. The problem I'm experiencing is that some given error messages are duplicated many times, preventing the code to be compiled even when the errors are fixed. For example, I wrote:
private OnClickListener foo = new OnClickListener()
{
#Override
public void onClick( View v )
{
// ...
}
}
I was reported "Syntax error, insert ";" to complete FieldDeclaration" 7 times. I fixed it and 6 error messages remained.
I closed Eclipse then restarted it, nothing changed. I guess it is a file to delete or something like this. Any idea?
Thanks!
Here is how I fixed the problem, for those who may experience it someday.
1) I copied all the faulty (or reported as faulty but not really faulty) code to a text editor.
2) I deleted it from the java file and saved it. The errors disappeared.
3) I pasted back the code to the java file then saved it. The errors did not re-appear.
That's it.
I've been trying to connect to twitter through android for a while.
I'm currently using this api: http://kenai.com/projects/twitterapime/forums/forum/topics/13327-Twitter-API-ME-1-8-Now-with-OAuth-support
I used their exemple with my keys and everything connects without problem. So no problem with configuration.
But in my project which has exactly the same code I can't make it work.
I believe its related with the creation of a new Intent (also this is where the eclipse is point the error)
Im trying to use a custom layout but I don't know what do I need to change to make this specific Twitter layout to work. On main activity I have a button with this:
public void onClick(View v)
{
startActivity(new Intent(this,Twitter.class));
}
on twitter class
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//this.webView = (WebView) findViewById(R.id.webView1);
WebView myWebView = new WebView(this);
setContentView(myWebView);
authenticate();
}
private void authenticate()
{
WebViewOAuthDialogWrapper page = new WebViewOAuthDialogWrapper(webView);
page.setConsumerKey(CONSUMER_KEY);
page.setConsumerSecret(CONSUMER_SECRET);
page.setCallbackUrl(CALLBACK_URL);
page.setOAuthListener(this);
page.login();
}
what requirements/adjustments are needed to make/change to the Twitter activity?
I believe I need to change something in the intent-filter but I don't even understand the work of intents. I've been only making easy layouts.
Note that I also gave internet permissions already.
Looks like i was making 2 mistakes.
First i was trying to use "webView" variable in WebViewOAuthDialogWrapper instead
"myWebView" so it wasn't initialized...
Second looks like i forgot to put the order of which the external libraries were loaded....
So be sure to put external libraries on top in eclipse project.
Lost about 2 days with these problems... oh well
I apologise if if 'hover assist' isn't the right terminology but I'm referring to the feature in Eclipse where if the use hovers the pointer over a method, a popup box appears with javadoc type information and invites the user to press F2 for focus. I see inconsistent behaviour for different methods, in that sometimes the browser gives me a file not found error when I click on a highlighted subject in that box.
I can best illustrate this by means of a snippet of code from a test project. I have the method:
#Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
... etc
...
}
If I hover over 'getSystemService' I see:
.
and then click on 'String' it takes me to the javadocs page
file:///C:/dev/tools/android-sdk-windows4.0/docs/reference/java/lang/String.html
on my machine in the browser. (I use the Firefox external browser) and this is just what I want.
However if I hover over the onCreate, I see:
Then if I click on the 'Bundle' link, I get this in the browser:
**File not found
Firefox can't find the file at /C:/dev/projects/EclipseIndigo/AndroidWorkTwo/CompassTwo/src/reference/android/os/Bundle.html.**
I have built the project with Android 2.3.3 jar and the javadoc properties show
which validates OK. I don't understand this inconsistent behaviour. Any help will be much appreciated.
The difference in both cases is the path "/docs/reference/java/" and "/src/reference/android/os/"
Please have a look at this url:
How to generate links to the android Classes' reference in javadoc?
It may guide you to correction.
Solved: I think it's just a plain Eclipse bug.
When I hover over the (overriden) onCreate the popup's header shows it belonging to my package and activity which extends Activity (as it must do)
If I click on the link inside the popup : Overrides: onCreate(...) in Activity
The the popup changes to show the same information but in class:
void android.app.Activity.onCreate(Bundle savedInstanceState)
Then, if I click on 'Bundle' in the new popup, all is well, we get the javadocs.
It's almost as if Eclipse thinks that the class Bundle itself has been overriden too and looks for the javadocs in my source.