Eclipse → AndroidStudio: Where can I see my errors? - java

I'm trying to migrate from Eclipse to Android Studio. There are a few things that bug me, but one stands out:
Q1: Is there no way to do automatic builds and have a list of problems displayed immediately like in Eclipse?
I know, there are many refactoring tools, but my often-used practise is to just insert a character into the name of a method and variable and check problems-view to see where it's being used.
Q2: How can replace or replicate this workflow in Android Studio?

One thing you can do is deactivate the external build. To do so click on "compiler settings icon" in the "Messages Make" panel that appears when you have an error. You can also open the compiler settings by going to File -> Settings -> Compiler. (Thanx to #maxgalbu for this tip).
enter image description here
Uncheck "Use External build"
enter image description here
And you will see the errors in the console
EDIT: After returning to "internal build" again you may get some errors, you can solve them this way: Android Studio: disabling "External build" to display error output create duplicate class errors

Related

Source code does not match the bytecode message whiile debugging [duplicate]

I have an app which I am compiling against API level 21:
and then debug it on a real device with API level 23:
The problem is when I try debugging through the Android OS's own classes, I get 'Source code does not match the bytecode'. Why is this happening? The test device the app is running on is API level 23, and the source file being debugged is level 23 as well.
I am really confused. Can anyone explain why I am seeing this message and how I can fix it?
There's an open issue for this in Google's IssueTracker.
The potential solutions given in the issue (as of the date of this post) are:
Click Build -> Clean
Disable Instant Run, in Settings -> Build, Execution, Deployment
Here is my solution:
If you got more than one library version, this may help.
set a breakpoint on the lib source code
let the code run to the breakpoint
you will got these tips
click the arrow icon
you will get this
double click to select the correct lib (normally the highest version of the lib is correct)
I have clicked the "disable" button by mistake, you can enable it in the debugger setting
If you do not have the tips in the step 3, maybe you can check whether you have checked the setting options
You should use an Android emulator with the same api level as the compileSdkVersion.
In your case you should use Android emulator with api level 21.
If you use Gradle, it is probably a problem with Gradle caches. (Reference). Alas, even if you run
gradle --refresh-dependencies
, it is not refreshing really all dependencies. Some rubbish remains. (Reference).
So, the most sure (but drastic and long) variant is to clear all inside from the [user]/.gradle/caches. Or to find your problem project there and clear only its caches.
My app is compiled on API LEVEL 29, but debugging on real device on API LEVEL 28.I got the warning source code does not match the bytecode in AndroidStudio.I fixed it thought these steps:
Go to Preferences>Instant Run: uncheck the instant run
Go to Build>Clean Build
Re-RUN the app
Now, the debug runs normal.
These are the steps that worked for me (For both Mac and Windows):
Click on "File"
Click on "Invalidate Caches / Restart ..."
Choose: "Invalidate and Restart"
Note: It will take less than a minute for small projects, but since my project was big (approximately one million lines of code), it took 20 minutes.
I tried all the solution given here and none of them worked for me. In version 2019.1.3 I just clean & rebuild artifact and it worked; first do Build -> Build Artifacts... -> <select your artifact> -> Clean then click Build or Rebuild from same place.
Go to Project Settings > Artifacts. Select the artifact which has the problem. There is an option "Include in project build". This needs to be checked(enabled). For older versions of IntelliJ this option is "Make on build".
Probably this error message can have more than one cause, my case was not like the one from the OP, in my case this was due to a 3rd party library that required additional libraries.
For example: you manually add X.jar to your LIB, but this X.jar requires Z.jar to work.
It took me sometime to figure out, the message was not helping at all. I had to debug the app until I reached the crashing class, and in that class make sure that all imports were satisfied.
(Particualry: I added MercadoLibre-0.3.4.jar, which required commons-httpclient.jar)
Hope this helps!
This can also happen in case you have enabled ProGuard. In buildTypes set minifyEnabled false, shrinkResources false, useProguard false
I tried the solutions given here while working on an application that used Bluetooth Low Energy(BLE). I tried,
Clean Build
Disabled Instant Run
Invalidate Caches / Restart
all of these failed.
What I did was debug the points where I thought I was getting the warning, I still got the warning but the application was working fine. You can disregard the warning.
You can created AVD, select API Level equal your tagetApi andr compileApi, it works for me.
So I created an account just so I could help fix this problem that is plaguing a lot of people and where the fixes above aren't working.
If you get this error and nothing here helps. Try clicking the "Resume program play button" until the program finishes past the error. Then click in the console tab next to debug and read the red text.
I was getting that source code error even though my issue was trying to insert a value into a null Array.
Step 1 Click the resume button
Step 2 Click the console tab and read the red text
here is cause of why I got this error "source code does not match bytecode". My cause doesn't have anything to do with any API, compiler version..... It is caused by when inflate a layout view into a root view while I mistakenly initiate the inflator in else where (a chuck of "result handler" code that put on top of onCreate function of android app code). Somehow the debugger doesn't give me right hint of this (ex, inflator is not initialized or has instance) when breakpoint is set and stop here.
This happened to me when accidentally I have added the same library multiple times.
implementation 'androidx.appcompat:appcompat:1.1.0'
The above library was added multiple times.
If clean, rebuild, invalidate cache and restart etc. techniques are not working, then try deleting the previous APK and reinstalling the new APK.
Android Studio takes source version equal to Target Version in your application. Compilation performed with source version equal to above mentioned Compile Version. So, take care that in your project Compile Version == Target Version (adjust module's build.gradle file).
I had the same issue and found a solution. If you have a line flagged in red, it will give you this error, but if you un-flag all of the lines it will work normally.
by flagged I mean when you click on the left side where the line numbers are and it highlights the line.
If that is not clear here are pictures.
go from:
flagged line
to:
not flagged line

'Source code does not match the bytecode' when debugging on a device

I have an app which I am compiling against API level 21:
and then debug it on a real device with API level 23:
The problem is when I try debugging through the Android OS's own classes, I get 'Source code does not match the bytecode'. Why is this happening? The test device the app is running on is API level 23, and the source file being debugged is level 23 as well.
I am really confused. Can anyone explain why I am seeing this message and how I can fix it?
There's an open issue for this in Google's IssueTracker.
The potential solutions given in the issue (as of the date of this post) are:
Click Build -> Clean
Disable Instant Run, in Settings -> Build, Execution, Deployment
Here is my solution:
If you got more than one library version, this may help.
set a breakpoint on the lib source code
let the code run to the breakpoint
you will got these tips
click the arrow icon
you will get this
double click to select the correct lib (normally the highest version of the lib is correct)
I have clicked the "disable" button by mistake, you can enable it in the debugger setting
If you do not have the tips in the step 3, maybe you can check whether you have checked the setting options
You should use an Android emulator with the same api level as the compileSdkVersion.
In your case you should use Android emulator with api level 21.
If you use Gradle, it is probably a problem with Gradle caches. (Reference). Alas, even if you run
gradle --refresh-dependencies
, it is not refreshing really all dependencies. Some rubbish remains. (Reference).
So, the most sure (but drastic and long) variant is to clear all inside from the [user]/.gradle/caches. Or to find your problem project there and clear only its caches.
My app is compiled on API LEVEL 29, but debugging on real device on API LEVEL 28.I got the warning source code does not match the bytecode in AndroidStudio.I fixed it thought these steps:
Go to Preferences>Instant Run: uncheck the instant run
Go to Build>Clean Build
Re-RUN the app
Now, the debug runs normal.
These are the steps that worked for me (For both Mac and Windows):
Click on "File"
Click on "Invalidate Caches / Restart ..."
Choose: "Invalidate and Restart"
Note: It will take less than a minute for small projects, but since my project was big (approximately one million lines of code), it took 20 minutes.
I tried all the solution given here and none of them worked for me. In version 2019.1.3 I just clean & rebuild artifact and it worked; first do Build -> Build Artifacts... -> <select your artifact> -> Clean then click Build or Rebuild from same place.
Go to Project Settings > Artifacts. Select the artifact which has the problem. There is an option "Include in project build". This needs to be checked(enabled). For older versions of IntelliJ this option is "Make on build".
Probably this error message can have more than one cause, my case was not like the one from the OP, in my case this was due to a 3rd party library that required additional libraries.
For example: you manually add X.jar to your LIB, but this X.jar requires Z.jar to work.
It took me sometime to figure out, the message was not helping at all. I had to debug the app until I reached the crashing class, and in that class make sure that all imports were satisfied.
(Particualry: I added MercadoLibre-0.3.4.jar, which required commons-httpclient.jar)
Hope this helps!
This can also happen in case you have enabled ProGuard. In buildTypes set minifyEnabled false, shrinkResources false, useProguard false
I tried the solutions given here while working on an application that used Bluetooth Low Energy(BLE). I tried,
Clean Build
Disabled Instant Run
Invalidate Caches / Restart
all of these failed.
What I did was debug the points where I thought I was getting the warning, I still got the warning but the application was working fine. You can disregard the warning.
You can created AVD, select API Level equal your tagetApi andr compileApi, it works for me.
So I created an account just so I could help fix this problem that is plaguing a lot of people and where the fixes above aren't working.
If you get this error and nothing here helps. Try clicking the "Resume program play button" until the program finishes past the error. Then click in the console tab next to debug and read the red text.
I was getting that source code error even though my issue was trying to insert a value into a null Array.
Step 1 Click the resume button
Step 2 Click the console tab and read the red text
here is cause of why I got this error "source code does not match bytecode". My cause doesn't have anything to do with any API, compiler version..... It is caused by when inflate a layout view into a root view while I mistakenly initiate the inflator in else where (a chuck of "result handler" code that put on top of onCreate function of android app code). Somehow the debugger doesn't give me right hint of this (ex, inflator is not initialized or has instance) when breakpoint is set and stop here.
This happened to me when accidentally I have added the same library multiple times.
implementation 'androidx.appcompat:appcompat:1.1.0'
The above library was added multiple times.
If clean, rebuild, invalidate cache and restart etc. techniques are not working, then try deleting the previous APK and reinstalling the new APK.
Android Studio takes source version equal to Target Version in your application. Compilation performed with source version equal to above mentioned Compile Version. So, take care that in your project Compile Version == Target Version (adjust module's build.gradle file).
I had the same issue and found a solution. If you have a line flagged in red, it will give you this error, but if you un-flag all of the lines it will work normally.
by flagged I mean when you click on the left side where the line numbers are and it highlights the line.
If that is not clear here are pictures.
go from:
flagged line
to:
not flagged line

Use the package matlabcontrol in my Java application to control Matlab?

I need to connect to Matlab from Java using matlabcontrol.
I tried their demos and those are working fine but when I tried to connect to Matlab using my application in Java RCP e4 I get this error (to be clear, my code succeeds in opening an instance of Matlab but afterwards the following appears in the Matlab window):
??? Undefined variable "matlabcontrol" or class "matlabcontrol.MatlabClassLoaderHelper.configureClassLoading".
And this appears in the eclipse server window:
matlabcontrol.MatlabConnectionException: MATLAB proxy could not be created in 180000 milliseconds
I tried searching for the answer and this came up: http://code.google.com/p/matlabcontrol/wiki/Compatibility
They say here that if this error comes, to run this command in Matab: java.lang.System.getProperty('java.class.version')
And if the answer is 50 or greater then matlabcontrol should work, but it doesn't for me.
I can't understand what's wrong (demo works, my code doesn't) and I'm desperately in need of an answer. This is for a project due soon and I would appreciate all the help I can get.
I faced a similar problem. This is what I did to solve the problem.
Go to the properties of your project in Eclipse. You can do this by selecting your project in "Package Explorer" and pressing Alt+Enter or by simply selecting properties on right click context menu.
In properties window, select "Java Compiler" and uncheck "Use compliance from execution.... 'JavaSE-1.8' on....". After that select "1.7" from drop down menu in "Compiler compliance level"
I hope this solves the problem for you!

IntelliJ IDEA: ClassNotFoundException if run Debug, execution/run does work

I have a Java Maven Project started in Eclipse, worked on it a few days, then imported it in IntelliJ IDEA, again working on it a few days.
The normal Run/Execution in IDEA and via shell does work, but not the Debug.
When I click the Bug Icon for Debug, it opens up URLClassLoader.java file and points on the Line "throw new ClassNotFoundException(name)" and pauses the Debug, if I click Resume Debug, it shows several Classes that do not belong to my project. I can click the Resume Button endless, it shows the same classes, also ClassNotFoundException over and over again in a continuously loop and does not debug my source.
If I click Build -> Rebuild Project it says at the Debug icon
"Hot Swap failed
myClassname: schema change not implemented;
myClassname: Operation not supported by VM"
In the Debug window under Variables it says: "Frame is not available"
The Debug of this project in IntelliJ IDEA did work previously, whats wrong now?
Looks like you have an exception breakpoint on ClassNotFoundException. Please try to open Run | View Breakpoints... and uncheck the breakpoint under "Java Exception Breakpoints".
in my situation, just neglect the evaluate language drop down.
This is really helpful. Go to your breakpoints in debug mode and make sure to deselect all the breakpoints first and then select only the ones in your class.

Why do I see a red cross over index.jsp?

I have set the jdk compliance level to 1.7 and the JRE version I am using is also set to 1.7.
But I am getting a red cross on index.jsp. What could be the reason for this ?
Though I can see the file running in the browser, eclipse's console doesn't show any error.
First make sure there really are no errors: Window -> Show View -> Other... -> Markers.
If there are none, sometimes Eclipse gets stuck thinking there are errors when there aren't. Close all editors, clean the project, close then reopen it in the project explorer (right-click on it), and see if the error clears.
I've also noticed that Eclipse has weird issues parsing JSP; sometimes it's confused and you just have to ignore it, but you could try opening the JSP file, selecting all, cutting, then pasting to force a recheck (or sometimes cut -> clean build -> paste).
I don't know why it does this, and I've been reading / filing bug reports for literally years, but it really seems to choke on JSP (something about the mix of HTML, Java, and JSP tags doesn't sit right with its parser).
Eclipse marks with this sign any file containing syntax errors (not compiling). If you don't have any syntax errors, then you should try cleaning up all your projects, as sometimes it may look inside old metadata files to determine whether there are errors in a given file.

Categories