Adding a breakpoint in Eclipse, causes Dalvik to crash - android

This is an interesting bug of Eclipse. I am using:
Version: Indigo Release
Build id: 20110615-0604
Out of nowhere today, I set a breakpoint in my android app on Eclipse. When it reaches the code, debug (dalvik JVM) aborts and crashes:
Tried to execute code in unprepared class (followed by the class name)
If I don't set the break point, it will run through with no problem. I have searched through Google but found nothing so far.
Another note, where I set this breakpoint does not matter, it could simply be the 1st line of onClick() function, or anywhere else. The moment the app "pauses" due to the breakpoint, it crashes.

I run into the same issue; for me, the problem was solved by removing all of the watched expressions I had set up in the debugger (one of them was causing the problem).

I run into the same issue when used watch expression with static method of this (unprepared) class.
I solved this issue by removing this expression from expressions list.

I solved this issue by removing an unused import package.
actually the error message is saying "tried to execute code in unprepared class" (followed by the class name)
I am not using that class but it is imported.
Simply remove the import, and it works fine ....

Related

R.id not found when writing Espresso test

I tried writing a small test to try Espresso.
package com.mycompany.myapp.somemodule
import com.mycompany.myapp.R
import other.uselful.imports
#RunWith(AndroidJUnit4::class)
#LargeTest
class DemoTest {
#get:Rule
var startActivity: ActivityTestRule<StartActivity> = ActivityTestRule(StartActivity::class.java)
#Test
fun aDemoTest() {
onView(withId(R.id.theElementId))
.check(matches(isClickable()))
}
}
Android Studio doesn't show any error. if I ctrl+click on R.id.theElementID, it finds it in the appropriate layout file. However when I try to run, I get a compile error:
Unresolved reference: id
How can I solve this?
I bumped into this issue. Spent 4 hours investigating, and no luck finding anything useful on the internet.
So, I'm hoping that the information below may help someone.
Short answer:
clean the project
execute gradlew :app:build from the command line / Terminal, it may show a build error which leads to the root cause
The longer answer:
I did the following:
I hit "Invalidate caches and restart" from Android Studio
I've executed gradlew :app:build from the command line
The second step printed an error message that the BuildConfig was duplicated.
The reason for this issue was, that I had 2 modules (android-app and android-library) with slightly different package names (I made a typo when creating the second one). This led to the failed build from the command line. After modifying the 2nd module's package name to be the same as the 1st one, the issue was solved.
I didn't receive the "R.id not found" error. So, I could continue to write the UI tests, which worked :-)
Happy coding!
Short answer: Try remove any incorrect import android.R statement.
Long answer
I also have faced this issue.
In my case, in test class, I was importing android.R package due to referring some incorrect resource id previously (R.id.progress) which belonged to android.R package.
I removed that reference as well ans the import statement i.e. import android.R from the test class and the issue resolved. Then source recognized the R.id.etPassword resource id of my layout file.
guess the actual problem is, that the activity had not been started.
R.id.theElementId might be an invalid resource descriptor.
try R.id.the_element_id instead.
also, add #UiThreadTest annotation ...

Issue with projectfolder called (AndroidProjects)?

I have a wired issue. If i set up a folder called AndroidProjects and put my project in there... Android-Studio fails with gradle.
one error is:
IllegalStateException:
PsiFile not parsed for file D:/AndroidProjects/MyApplication/settings.gradle.
Wait until onPsiFileAvailable() is called.
sometimes it says that gradle has a fatal error....
if i set up my projectlocation to e.g. andropro everyting is working fine.
My thoughts:
may problems with 2 big letters in projectfoldername
may foldername is to long
may android or project are registered words in android-studio
Is there a knowen issue using foldernames like i did above?
couldn't find anything on the net.

Android: Gradle Error in Android Studio

I recently added some .gifs to my /drawable so that I can use them with buttons. This worked fine (no errors). Now, when I go to rebuild/run my application, I get the following error:
Error: Gradle: Execution failed for task ':MyProject:mergeDebugResources'. > Index: 0
I'm not sure how to fix this (and there appears to be no other similar issues that I could find online.
Edit: Now it's the same error, but it also says (at the end of the first error)
Running /Applications/Android Studio.app/sdk/build-tools/android-4.2.2/aapt failed. See output
Okay, I fixed the issue. It was quite weird.
A) I had some capital letters in my res/drawables folder. Not too weird -- I can see how that would remove the first error.
B) Then, however, a lot of values in my main activity file became undefined. I had to manually import 'com.myapp.R'. Now that was weird.
Fortunately, everything is now working.
I hope that if anyone gets the same errors as me, that this response can help them.

How can I find out what line an exception is being thrown on in Eclipse (Android)

I have a ClassCastException being thrown saying that I'm trying to cast a SeekBar as a Button but I've looked over my code 50 times and not once do I try to cast a SeekBar as a Button. How can I find out what line this apparent class mis-cast is on?
Thank you.
That information is available in the LogCat. See this link for details on how to use it.
If you are sure you are not doing such a cast, then clean the project by running ant clean (command line), or going to Project -> Build -> Clean (eclipse)
Insert a break point and simply step through until I hit the line that triggers the exception.

Error NullPointerException when running an altered version of an Android Project

I have this Android program running well, called TestePHP2 (name of main class), package com.testedeacesso.www. It is stable and runs perfectly.
I've cloned this project's folder to start developing an upgrade to it. I called it TesteTempo01, after importing it to Eclipse - option 'from existing project' (yes, I used the refractor to change the class name and I checked 'update references'). I modified this program's main class as I mentioned before and added some code to it, but I kept the package name the same, as well as other classes from the program.
Whe I try to run this program, though, I got a 'can't find main activity' error. After searching through my code, I found out that on the manifest there was a reference to the TestePHP2 that I hadn't changed before. for reference, this was the line on the Android Manifest XML:
> <activity android:name="com.testedeacesso2.www.TesteTempo01"
> android:label="#string/app_name">
After this, I keep getting a NullPointerException because the class can't find the main class! I've searched through the whole code but I found no other references to the old class. Have I forgotten something? Do I need to alter something else to change this class' name? Or the import will only work with the original class names?
You said the package was 'com.testedeacesso.www', but when you reference the class, its 'com.testedeacesso2.www'. I'm guessing you have a problem with class/package references.

Categories

Resources