I have a class set up as an EViewGroup. In it, I'm trying to reference another Activity set up as an EActivity. For some reason, the import isn't resolving, but it resolves fine if I reference the Activity in question from another EActivity.
The code compiles fine using ant on our Jenkins server, but doesn't compile within Ecipse.
Any ideas?
Here's some code for ViewGroup:
import android.app.Activity;
import android.content.Intent;
import com.googlecode.androidannotations.annotations.Click;
import com.googlecode.androidannotations.annotations.EViewGroup;
#EViewGroup
public class MainMenu extends SlidingMenu
{
public void navigate(Class<? extends Activity> klass)
{
getContext().startActivity(new Intent(getContext(), klass));
toggle();
}
#Click(R.id.textView_bring_it)
public void bringItClick()
{
navigate(ActivityBringIt_.class);
}
}
The compile errors I'm seeing:
The import com.beachbody.p90x.bringit.ActivityBringIt_ cannot be
resolved
The method navigate(Class) in the type MainMenu
is not applicable for the arguments (Class)
ActivityBringIt_ cannot be resolved to a type
Here is my .factorypath file:
<factorypath>
<factorypathentry kind="WKSPJAR" id="/common/compile-libs/androidannotations-2.7.1.jar" enabled="true" runInBatchMode="false"/>
</factorypath>
It seems that ActivityBringIt_ isn't generated. Your compiling errors are just noises because of that.
Mostly AA can't generate subclasses if you have errors in you Android's xml files.
You should take a look on this.
Also, could you copy/paste your .factory file ?
Thanks DayS for pointing me in the right direction. There is a bug in Eclipse causing this issue. The workaround is to import the entire package in question. In my case it is:
import com.beachbody.p90x.bringit.*;
Here is the bug report w/ Eclipse:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=387956
Related
Getting cannot resolve symbol nullable error for my program.
#androidx.annotations.Nullable - nullable has redline under it.
package com.singularity.birdjumper;
import android.app.Activity;
import android.os.Bundle;
public class GameActivity extends Activity
{
#Override
protected void onCreate(#androidx.annotation.Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
just add this import statement
import android.support.annotation.Nullable;
For androidx, the import statement should be:
import androidx.annotation.Nullable;
Are you using the AndroidX library?
It would be worth adding them into the app gradle file,
//set the version to latest version
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
There is also a great answer over here for more information on AndroidX and migrating your projects over to it.
Android Studio adds both #androidx.annotation and #android.support.annotation problem
i hava the same problem,
sync project with gradle files or update gradle plug
So when i create a new android application project with ANDROID 6.0 library i instantly get the a lot of errors in the MainActivity code.
Starting with The import android.support.v7.app cannot be resolved
To The method onCreate(Bundle) of type MainActivity must override or implement a supertype method
When i add the appcompat.v7 library obviously Some of the errors related are gone but other are coming instead. Like:
The type android.support.v4.widget.DrawerLayout$DrawerListener cannot be resolved. It is indirectly referenced from required .class files on the package line.
And still The method onCreateOptionsMenu(Menu) of type MainActivity must override or implement a supertype method.
Ok. So add the v4 jar too. Ok. I added it too to the project properties and no errors!
Wait,but when i run the app now I get a ClassNotFoundException.
So what the hell android 6.0???
Thanks for the help.
EDIT
MainActivity.java:
package com.minyan.get.dl;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
The main reason is that Android Studio is the main IDE now.
Eclipse is no longer supported.
I suggest switching to Android Studio.
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.
In thefollowing Code, I get a problem when following the Android beginners tutorial at http://developer.android.com/training/basics/firstapp/starting-activity.html#StartActivity
Eclipse is saying: supressLint cannot be resolved to a type error with a small x next to that line #SuppressLint("NewApi").
I cannot save and run the application.
package com.example.myfirstapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
import android.annotation.TargetApi;
import android.os.Build;
public class DisplayMessageActivity extends Activity {
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
// Make sure we're running on Honeycomb or higher to use ActionBar APIs
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}
Try this:
import android.annotation.SuppressLint;
The issue is that you need to organize your imports. This is frequently a cause for the "cannot resolve to a type" error. You haven't imported the code package which contains the definition of SuppressLint, so the compiler doesn't know what it means yet.
In Eclipse, a quick way to organize imports is Ctrl+Shift+O on Windows or Cmd+Shift+O on Mac. This automatically checks for packages you need and adds them to your import statements.
To use #SuppressLint you will want to make sure that you have the android.annotation.SuppressLint package.
While the OP's question is for Eclipse, I faced similar issue on Android Studio and the issue was because of the "CSV plugin"
Uninstalling this plugin, resolved the issue for me.
(Might be useful for those who're having similar scenario and are landing on this question because of this plugin issue)
I think this helps you because supresslint annotation was added in API level 16
set your build SDK to 16 or higher
Copy tools/support/annotations.jar from your Android SDK to the project
Try this.
I am trying to inflate a layout containing a Fragment using the backwards compatibility package and SDK level 10. I took the jar file and placed it in the libs folder of my project. I extended FragmentActivity.
It all works perfectly when I run at API level 11 on an XLarge screen device.
When I drop back to compiling against level 10, and running on a normal sized screen, I get failure at the point where it create a new Activity and inflate the fragment in it.
Caused by:
java.lang.ClassNotFoundException:
android.view.fragment in loader
dalvik.system.PathClassLoader[/data/app/com.motoappsummitagenda-1.apk]
04-01 01:07:14.311 2870 2870 E
AndroidRuntime: at
dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
So it looks like something, somewhere is looking for android.view.fragment, and not the compatibility version, android.support.v4.app.Fragment. Of course, android.view.fragment won't be found on API level 10. But where is that android.view.fragment coming from?
The XML that is being inflated is
<?xml version="1.0" encoding="utf-8"?>
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.motorapp.SessionFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/sessionfragment">
</fragment>
The code for it starts:
package com.motorapp;
import java.util.List;
import java.util.ListIterator;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.support.v4.app.*;
import android.support.v4.util.*;
import android.support.v4.*;
import android.support.v4.widget.*;
public class SessionFragment extends android.support.v4.app.Fragment {
The symptoms are similar to this problem, but I don't have those mistakes
inflating fragments with compatibility package android
The android.compatibility.v4.android-support-v4 jar file is on my build path in Eclipse
under Project > Properties > Java build path
I have in the manifest (and I have tried different variations of the name).
In getting started with fragments, I first used API 11 on a honeycomb device, and that all works perfectly. It is in getting the same code (modified to use the slightly different compatibility API) working with the compatibility library that I have this problem. Any ideas would be very welcome. Thanks,
Peter
I just solved this problem in Android API 8 machine (Samsung Galaxy S).
Please change Activity class to FragmentActivity.
public class FragmentLayout extends Activity {}
-->
public class FragmentLayout extends FragmentActivity {}
public static class DetailsActivity extends Activity {}
-->
public static class DetailsActivity extends FragmentActivity {}
finally
getFragmentManager() --> getSupportFragmentManager()
register android-support-v4.jar to Eclipse's referenced Libraries
put android-support-v4.jar to {root directory of your project}/libs directory
change to API 10 enum (ex:simple_list_item_1) from simple_list_item_activated_1
import android.support.v4.app.Fragment;
I had the same wrong class problem with the compatibility library and tried everything mentioned above with no luck. I finally figured it out: I was using the incorrect XML element Fragment rather than correct one fragment. Capitalization seems to matter.
I bet you are trying to call setConetentView before super.onCreate in your FragmentActivity
I had exactly this problem with an app running on pre-Honeycomb devices. I based my Fragment coding on the example given in Dianne Hackborn's February 2011 blog post and other standard Fragment reference material. The solution to the problems is contained in the SDK reference link, http://developer.android.com/sdk/compatibility-library.html#Using. There are minor differences in class and method names that must be used in apps with Fragments, when those apps are to be deployed with the Compatibility library. The link explains this.
The compatibility library, as downloaded and installed, includes example code using Fragments. Ref: Android Developers > Resources > Sample Code > API 4+ Support Demos
The imports that you have provided all look correct. Do double check any other classes to make sure Eclipse didn't auto import the wrong Fragment some where. The other thing that is key is you need to add the compatibility library to a lib\ that you must create at your project's root to make sure it gets bundled with your app. I don't know if it is required, but I always have my project build path refer to it's copy.
Your layout seems to be missing the class parameter. I think you meant to use class where you have used name in your layout.
<fragment class="com.example.<class to path to your fragment>" android:id="#+id/items"
android:layout_weight="1" android:layout_width="0px"
android:layout_height="fill_parent" />
In Eclipse you should see android-support-v4.jar under both Referenced Libraries and libs.
I think you should delete android-support-v4.jar from build path. This will remove it from referenced libraries in Eclipse. Than creace folder libs and put the jar in there. Clean your project and Eclipse will add the jar to Android dependencies. This did the trick for me as I was struggling with class not found exception.
I got the
java.lang.NoClassDefFoundError: com.android.example.SupportFragment
at com.android.example.SupportFragmentActivity.onCreate()
on
SupportFragment extends SherlockFragment implements PopupMenu.OnMenuItemClickListener
...
#Override
public boolean onMenuItemClick(android.view.MenuItem item) {
return onOptionsItemSelected(item);
}
when trying to make a api 17 app compatible with api 8, the only indication was the logcat error above, so check that all your imported classes are supported if you get this error.