I have include a jar file in my android project. Inside the jar file there is a class OverlayView in a package name android.widget. I can import the class into my Test.java file by import android.widget.OverlayView; and call the method init(). After these I can compile successfully. But while running the app it throws an exception
java.lang.NoSuchMethodError: android.widget.OverlayView.init
I didnt get class definition error
Your library contains android.widget? There is already a package with android.widget as its name. My guess is that it's conflicting with your library. Try deleting the import statements, by this time you should get an error because you deleted the import. Place your cursor in the method that has error then wait for the import suggestion to pop out, then alt+enter to import package. See if it is conflicting with the default android.widget package.
Related
In MainAcitivity i am using Tools.systemBarLolipop() it is function from Tools.java file
in Tools.java there is window.setStatusBarColor(global.getIntDarkColor());
comes from window.java
in window.java all android.annotation import are error
How can import util.Constants in
Android Studio 3.0.1
Error:cannot find symbol variable Constants
Alt+enter said me android.provider.SyncStateContract.Constants? But I need to import like
Import mypackage name.until.Constants
delete the Constant usage in the program.
Go to your imports section and enter
import android.provider.SyncStateContract.Constants.ConstantName
This works out.
We are trying to use the Robolectric testing framework in Android Studio in order to test the Facebook API. The Facebook Login button works so the Facebook API is working. However, the following test fails:
package com.airportapp.test.Models;
import android.app.Activity;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import org.robolectric.Robolectric;
import com.airportapp.test.MyRobolectricTestRunner;
import com.airportapp.LoginActivity;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
#RunWith(MyRobolectricTestRunner.class)
public class LoginActivityTest {
#Before
public void setup() {
//do whatever is necessary before every test
}
#Test
public void testActivityFound() {
Activity activity = Robolectric.buildActivity(LoginActivity.class).create().get();
Assert.assertNotNull(activity);
}
}
And the error is that Android Studio could not find the android.support file when we run the tests. You can see the error here:
The other error that shows up is:
android.view.InflateException: XML file app/src/main/res/layout/activity_login.xml line #-1 (sorry, not yet implemented): Error inflating class com.facebook.widget.LoginButton
So Android Studio is not happy with the facebook login button as well :( But it works... We think that we need to import something, but we don't know where to put it.
The InflateException is because Robolectric cannot find the resources from the Facebook SDK. To solve this, the project.properties file has to be updated to point to the Facebook SDK project. Do this by adding the following line to it:
android.library.reference.1={Path}
{Path} should be a relative path, from the project.properties file to the folder containing the AndroidManifest.xml of the Facebook SDK project. In my case that is ../../build/intermediates/exploded-aar/com.facebook.android/facebook/3.21.0.
Note that this works for all Android Library Projects which contain resources that aren't found by Robolectric. Further reading: here and here. Also, more documentation about project.properties can be found here. Note that in my project the Robolectric tests are located in the Android app project itself. So you could also try placing the project.properties file in the same directory as the AndroidManifest.xml used for testing.
As for your first problem; I have no personal experience with it. But it appears to be because Gradle cannot find the support libraries when compiling the unit tests. The answer from this question should fix it.
i'm triing to use this directory picker: Android-DirectoryChooser
if i import it in eclipse like: file -> import -> existing and. proj. -> directory picker -> library and sample project
it gives this errors:
what am i doing wrong?or how to implement it in the right way?
errors:
The declared package "net.rdrei.android.dirchooser" does not match the expected package "main.java.net.rdrei.android.dirchooser"
Change the package name at top of the class ,It is the starting statement of your class and your own package ,where your getting the error right click on that you will have your own package...
I had to explicitly add my "import R" to my main activity's source.
However, when I run the app nothing displays in the Emulator to let me know my app is running. I'm wondering if the "import" I added is wrong.
Assuming my package is named com.goSitOnAPotatoPanOtis.This.
should it be this:
import com.goSitOnAPotatoPanOtis.R;
or this:
import com.goSitOnAPotatoPanOtis.This.R;
?
From my experience you should not have to add an import *.R class, and it will actually cause problems when building. That class should be available to your activities already.
The R.java class is generated in the application package as defined by the manifest package attribute:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.goSitOnAPotatoPanOtis" android:versionCode="1"
android:versionName="1.00">
If your activity is in that package you do not need to import R.java because of Java package visibility. If your activity is in another package you need to import it with
import com.goSitOnAPotatoPanOtis.R;
Even if you import the R class when it is not necessary it should not cause your application to stop running.
It should be import com.goSitOnAPotatoPanOtis.R; you can then reference that R using just the R.id.some_id or whatever you are trying to reference from the generated R class.