RoboActionBarActivity for RoboGuice - java

I use Gradle to add the dependency org.roboguice:roboguice:3.0b-experimental to my project.
I found a post on the issue tracker, saying that there should be a RoboActionBarActivity class (to replace the ActionBarActivity I use for drawer navigation) in the latest beta. I can find the code on Github, but the class isn't in the jar. I found several implementations of the RoboActionBarActivity on the web, but those have other dependencies, and I don't want to resolve them all manually. Is there a way to get this class via Gradle?

Until the RoboActionBarActivity class is provided with the RoboGuice library you can make your own descendant class for ActionBar support. Or you can get the ActionBar4RoboGuice library, which contains the original RoboActionBarActivity, and use it with the latest stable release of RoboGuice.

Related

Runtime Error using ViewModelProvider(this) in AppCompatActivity

I am trying to use a ViewModelProvider for an android dynamic-feature library, which is being added to an existing project. I have the following code in my AppCompatActivity class.
MyModel model = new ViewModelProvider(this).get(MyModel.class);
The project is using the 2.2.0 version of the androidx lifecycle libraries. From my gradle file:
implementation 'androidx.appcompat:appcompat:1.1.0'
def lifecycle_version = "2.2.0"
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
I am getting the following error at runtime.
java.lang.NoSuchMethodError: No direct method <init>(Landroidx/lifecycle/ViewModelStoreOwner;)V in class Landroidx/lifecycle/ViewModelProvider; or its super classes (declaration of 'androidx.lifecycle.ViewModelProvider' appears in.....apk
Is this a bug? Do I have some dependency issue with something already in the larger app? How would I track down the dependency issue if it is somehow using an older version of ViewModelProvider from the existing app? I would have thought by naming the explicit version of the dependency in my gradle file, it would avoid such conflicts.
I had a similar problem. I don't know why but it works well when I use the deprecated class ViewModelProviders.
MyModel model = new ViewModelProviders.of(this).get(MyModel.class);

Why do I have java.lang.ClassnotFoundException while implementing location listener? (using ECLIPSE)

I know that similar questions have been on SO and I have read through and tried to implement the solutions mentioned but nothing is working. The specific problem is like this (using ECLIPSE):
I am trying to implement location awareness in one of the activities (triggered through menu selection) in my app. As long as my code looks like,
"public class MealHistoryActivity extends Activity {...}",
I don't get any error. As soon as I modify it to
public class MealHistoryActivity extends Activity implements ConnectionCallbacks, OnConnectionFailedListener, LocationListener {..",
it throws in the following error:
E/AndroidRuntime(5027): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.package.activities.MealHistoryActivity" on path: DexPathList[[zip file "/data/app/com.package.activities-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
What I have tried:
Adding up the library projects (support library as well as google play services) and cleaning all the projects.
Including Android Private Libraries for the application as well as the library projects.
Double-checking the API key in android manifest as well as the SHA-1 fingerprint key associated to it.
Using all the internet and network permissions in the manifest that are needed for location services.
Would greatly appreciate any ideas on how to solve this since I am stuck on it for the last few days!
The error suggests that the classes from the google-play-service project are not loading.
Make sure you are referencing a copy of the project in your workspace, and not the copy that is in the sdk directory. Try doing that or deleting the google service project from your workspace and redoing the steps in this guide.
Another possible cause for this is version mismatch. If your device's version is less than the version specified in the above mentioned guide than the google services project will not install on your device at all.

What is com.android.support:appcompat-v7?

I am not familiar with using Android Studio. Earlier I used Eclipse. Could you explain me what is gradle in Android studio. I have problem with Android Studio. What confused me is that it uses the same android sdk as eclipse but when I create a new project weird things happens:
There is required :com.android.support:appcompat-v7:+ (what it is ? eclipse does not require it)
My MainActivity extends ActionBarActivity instead of Activity why is that ?
Its a support library called appcompat. You need to reference that if you need actionbar below api level 11 (Whether its android studio or eclipse).
If you need actionbar below api level 11 your Activity needs to extend ActionBarActivity.
If you are targetting api level 11 and above then you don't need to extend ActionBarActivity and reference AppCompat. You can simply extend Activity and you will have actionabr by default.
Check Adding the Action Bar in the below link.
http://developer.android.com/guide/topics/ui/actionbar.html
Check for Adding libraries with resources using Android Studio #
https://developer.android.com/tools/support-library/setup.html
Actiobbar is introduced in api level 11. com.android.support:appcompat-v7:+ is a support library which allows you to have an ActionBar in your app for devices running on Android 3.0 or below.
Android Studio default project includes it automatically in dependencies and extends ActionbarActivity instead of Activity in order to use it.
You can check the same in your module's build.gradle file, you will find something like this under your dependencies block.
compile 'com.android.support:appcompat-v7:+'
There are two possible solutions to get rid of this
Remove above line from dependencies block and extend Activity instead of ActionBarActivity in your Activity classes.
Download support repository from Android SDK Manager.
Support Repository and Google Repository shown in SDK manager are not required for Eclipse but in order use Google Play Services and Support libraries in Android Stodio you have to download them.
EDIT(android plugin not found error, asked in comments below ) :
Make sure you have this either in your root level build.gradle file or at the top of module's build.gradle file to let build system know where your gradle pguin is and what is the version :
(before apply plugin: 'android')
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}

Android: Implementing SlidingMenu and ABS

I am trying to implement the SlidingMenu from https://github.com/jfeinstein10/SlidingMenu together with http://actionbarsherlock.com/ and I came across a problem that I could not fix myself that's why I turned to the issues page on SlidingMenu's GitHub. But 2 days and I got no reply so I am gonna ask it here.
Basically on the example project provided by jfeinstein10, I copied the SampleListFragment.java file and I've named it MenuListFragment.java on my project. I've made a couple of changes but those should not be an issue.
I also copied the menu.xml from the layout directory but changed its name attribute to the previous file including the package.
Project builds properly and no errors are encountered. Time to run the project.
Now on my project's main activity, when I call the setMenu(R.layout.menu); statement during runtime, it gives me an error which tells me something about ClassCastException (cannot cast com.dokgu.dota2stats.MenuListFragment to android.app.Fragment).
I've tried a couple of things like change the MenuListFragment.java to extend the android.app.Fragment instead of ListFragment but it didn't solve the problem and more issues came up because of that.
So please, can anyone help me with this please? I really want to make this work.
You can find the issue here as well: https://github.com/jfeinstein10/SlidingMenu/issues/546
Actionbarsherlork supports the lower lever version since android 2.x while the slidingmenu needs android 3.0+.Maybe you can add the android-support-v4.jar ,with some fragment and activity in slidingmenu project extending to.

NoClassDefFoundError Android with ActionBarActivity

I currently have an ActionBarActivity which always returns a NoClassDefFoundError. I've read that it might be a problem with the ADT but I cannot be sure, hence my question. I've imported the ActionBar sample from the Android samples under
android-sdk\samples\android-14\ActionBarCompat
I've labelled the ActionBarCompat project as a library under Project -> Properties but I'm still getting the error.
To reiterator:
public class SearchActivity extends ActionBarActivity { // Doesn't work, yields exception
public class SearchActivity extends Activity { // Works perfectly
Has anyone else experienced a similar error and perhaps found a solution?
Thanks in advance.
http://developer.android.com/tools/support-library/setup.html
The "Adding libraries with resources" section may help
since this is not in the most common v4 support library
include only android-support-v4.jar is not enough
Ended up using ActionBarSherlock instead and added a project reference under Project Properties as well as in the Build Path. Seems to have fixed all errors relating to my question.
Just this morning, Google released Android 4.3. They also updated its support library that allows ActionBar to be implemented on lower versions. Just have to extend ActionBarActivity. See guidelines here and tutorial here.
I've got the same problem. I solved it getting the android-support-v7-appcompat.jar library.
See here http://developer.android.com/tools/support-library/setup.html#using-apis how to install it.
I recommend focus on "Adding libraries without resources" instead "Adding libraries with resources" for the sake of simplicity.
When you do it, don't forget to import the this library into your Activity Java source. You can do it declaring import android.support.v7.app.ActionBarActivity;
I solved this problem like so, when you add the library make sure it does not have the android-support-v4 along with it (in libs folder of the library un-check android dependencies and android-support-v4), that's in the case where your project already have the android-support-v4, that's why you can't find class ActionBarActivity
This Link
may help you.
This library is located in the /extras/android/support/v7/appcompat/ directory.
Include in eclipse and add as library. This will solve your problem.

Categories

Resources