setOnLongClickListener causes UNEXPECTED TOP-LEVEL EXCEPTION - android

When I add this line of code in my Activity
findViewById(R.id.btFilter).setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View view) {
ResultadoBuscaMapa.this.finish();
return true;
}
});
I cannot compile, and get this error
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.util.ExceptionWithContext
at com.android.dx.util.ExceptionWithContext.withContext(ExceptionWithContext.java:46)
...
in both Intellij IDEA and Android Studio (latest versions)
Funny thing is that it's an old code and worked just fine until yesterday.
Is it possible that Android Studio broke something in my project structure?

Where do you declare this listener ? It's better to do ContextView.findViewById(R.id.btFilter);
And i usually declare my widget before setting a listener:
Button filter = (Button) findViewById(R.id.btFilter);
filter.setOnLongClickListener(....
Another way, do you try without ResultadoBuscaMapa.this.finish(); cause error seems to be link to your context.
Hope it helps

Strange as it my seem, after the last update of Android Studio, the error just vanished in BOTH IDE's. Now it runs fine also in Intellij IDEA

Related

Problem Onclick + "v" does not recognize the methods in android studio code

I am fairly new to programming, I was writing an application code in Android Studio but had a problem
It turns out that when I put this line in my code (In image)
it does not detect it and an error occurs both with "onClick" and with "(v)" I reached this point and I don't know how to solve it
Attached images:
[1]: https://i.stack.imgur.com/huZLu.png Error Code
[2]: https://i.stack.imgur.com/hCJYJ.png All Code
I would really appreciate the answer
This problem is eating my head!
Thank you
it's not a big problem, you can write like this, it will solve your issue
mOpicon2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});

Exception raised during rendering: Unable to find the layout for Action Bar

While using Android Studio just now I was editing an XML file in the editor and I got this error in the Preview and Design windows:
Exception raised during rendering: Unable to find the layout for Action Bar.
I've tried restarting Android Studio, my Laptop and Googling for the answer but I can't find anything. Has anybody experienced anything similar?
I had this kind of error. On My Mac, there is API 22. If I choose it this error will appear. So clicking on API 21 or below would solve your problem
You probably need to update your tools
Those using Eclipse might try to choose Theme.DeviceDefault to eliminate the exception.
Update: as per comments this works for Android Studio also.
You can solve this problem by two ways
Change API from the tab, Try one of them from the available or Select PICK UP BEST or change your minimum sdk
Change the Theme if first solution not work
Click on Theme in Editor and change the theme:
MY issue is solved after this
I had this error on eclipse-3.8, adt-23.07, sdk-tools-23.1, appcompat_v7_r19.1.
After analyzing the error I found the problem is in
android-sdk-linux/platforms/android-23/data/layoutlib.jar:com/android/layoutlib/bridge/impl/Layout.class on method createActionBar at line if (this.mBuilder.isThemeAppCompat())
My solution:
(don't have the source, so) decompile Layout.class -> Layout.java
edit Layout.java, add method:
private boolean hasWindowDecorActionBar(SessionParams params) {
LayoutlibCallback callback = params.getLayoutlibCallback();
try {
callback.findClass("android.support.v7.app.WindowDecorActionBar");
} catch (ClassNotFoundException ei) {
try {
callback.findClass("android.support.v7.internal.app.WindowDecorActionBar");
} catch (ClassNotFoundException e) {
return false;
}
}
return true;
}
Locate the line if (this.mBuilder.isThemeAppCompat()) then change to :
if (this.mBuilder.isThemeAppCompat() && hasWindowDecorActionBar(params))
recompile Layout.java -> Layout.class and Layout$Builder.class
update layoutlib.jar with the new classes
restart eclipse
That's all. Now, I can render using API-23 all of my old app layouts that links against appcompat_v7_r19.1.
You suppose to do clean project.
i think it is a bug and there is no ultimate solution until this moment,
changing to API less than API-22 is a temp solution not more.

BubblePopupHelper filling Android Debug Log

So I noticed when I was debugging that there seems to be a tag that's repeating through my app entitled "BubblePopupHelper" with text: "isShowingBubblePopup : false"
Screenshot of the log
To my knowledge, I'm not using or causing it. Does anyone have an idea of what's going on? The application is the one I'm writing.
Upon further inspection, I did notice that every time I'm updating text (via a TextView) it displays onscreen. If there's a better way of doing so, please let me know.
Thanks!
The message seems to be logged by some SDK libraries whenever setText is called in a TextView. I get it in Android Studio developing with min API 14.
One interim solution till Google removes it would be using the filtering feature of Android Studio by writing a RegEx that only includes your log messages. For example if I have all my tags start with 'Braim' then 'Braim.*' can be used
If you want to filter this annoying logs away you can use the following regex:
by Log Tag: (?!^BubblePopupHelper)(^.*$)
Have you added "OnGlobalLayoutListener"?
I've encountered same problem and finally I found that getViewTreeObserver().addOnGlobalLayoutListener caused the problem.
Here is my solution:
textView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
...
textCategory.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});

Eclipse duplicate Android code error

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.

Eclipse Shift+Ctrl+O stopped functioning (Android 4.0.3)

Using Eclipse's Shift+Ctrl+O to organize imports has been working fine until it stopped working.
For some reason, it is now taking away my necessary imports and causing classes to be unresolved. Example below, Button, onClick, Toast are not resolved due to when Shift-Ctrl-O was pressed, it cleaned out the needed file.
It was working before and I don't know what I did to cause it to not work anymore. Any help would be greatly appreciated. I cleaned project, restart eclipse...to no avail.
final Button button=(Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Perform action on clicks
Toast.makeText(HelloFormStuffActivity.this, "Beep Bop", Toast.LENGTH_SHORT).show();
}
});
Thanks very much in advance.
I have/had the same problem. Best I could figure out is that eclipse need to have a 'source' item on the main tool bar which has has 'options' like format and 'Organize Imports'. Clicking on a project in the "Package Explorer" causes the 'source' menu item to appear between 'refactor' and 'run'.
I had this happen when I created a file without a .java extension and renamed it with Refactor. Not until I noticed there was no syntax highlighting did I realize I still had it open in the text editor, so I closed it and reopened and Ctrl+Shift+O started working again.

Categories

Resources