ActionBarActivity and FragmentActivity... "Inconvertible types"? - android

I'm currently having a curious problem, trying to use simultaneously v4 and v7 (actionbar) compatibility libs.
Let's say I've got my own Activity class, that extends ActionBarActivity on one hand and, on the other hand a Fragment, inside of which I call "(MyActivity)getActivity()".
I checked the imports and my Fragment is a v4 Fragment.
In a v4 Fragment, calling "getActivity()" returns a FragmentActivity.
I also checked: ActionBarActivity extends FragmentActivity.
Now here is my problem:
I don't have any error in the editor (no red line).
I'm using Android Studio.
When I try to "Make" the project, the compiler returns an error for each time I call "getActivity" inside my Fragment.
It tells me he has a FragmentActivity but a ActionBarActivity is expected and tells me those classes are incompatible.
It interrupts and I can't even test my app.
It may be a problem with the gradle configuration, but I added "compile "compile "com.android.support:appcompat-v7:18.0.+"" in the "dependencies" part of my build.gradle file, as said on this page:"http://developer.android.com/tools/support-library/setup.html", and it doesn't change anything...
Any idea?
EDIT :
As an adddition to my yesterday's post, even if everything is explain before, here are some code parts and the error message Android-Studio gives me:
First of all, my activity:
...
import android.support.v7.app.ActionBarActivity;
...
public abstract class MyAbstractActivity extends ActionBarActivity{
//Do some stuff here
}
Every activity of my application extends this class.
Now here is my fragment:
...
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
...
public class MyFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//Do some stuff...
((MyAbstractActivity)getActivity()).getSupportActionBar().setTitle(R.string.app_name);
}
//Do some stuff...
}
No error is shown in the editor.
But when I "Make" the project, I get this message in the "Event Log":
Compilation completed with 5 errors and 0 warnings in 4 sec
In the "Messages Make" part, I can see this for each time I try to cast "getActvity()" in "MyAbstractActivity":
java: inconvertible types
required: com.myapps.abstracts.MyAbstractActivity
found: android.support.v4.app.FragmentActivity

Well, I'm sad to say that, but I finally downloaded Eclipse, imported my project, and solved my problem, using the error messages of Eclipse.
It told me to "Fix Project Properties", I clicked, it did everything on his side, I tryed to launch the app, it worked.
Now that the problem is fixed, when I come back to Android Studio, it works too... But, for the moment, I think I'm gonna stay with Eclipse... Too much time lost for nothing. :(

Android Eclipse plugin gets flaky. Try to clean your project, then rebuild. Also, try restarting Eclipse. Also verify your project build path library order. Also, try to rebuild from the command line in the project with 'ant clean; ant debug', but do it while Eclipse is closed.

Related

Trying to use code from another project by including it in my build path

I'm trying to figure out a way to share code across projets. this is what i did
created a project called sharecode and made the following class
package codelib.com;
public class cShape {
}
made a android project called testsharecode
whent to properties->java build path and clicked on projects at the top.
clicked add, and added sharecode
created a class to try include the cShape class from the sharecode project
package com.example.testsharecode;
import codelib.com
public class parent {
cShape test;
}
On my import i get a error saying
"only a type can be imported, cadelib resolves to a package"
on cShape i get a error saying the def does not exist.
How can project testsharecode use the code in projetc sharecode?
have you tried the following method :
right click on the distination projet, Build Path -> configure build path
chose project then select testsharecode
back in your distiation project now you should be able to use your public classes.
hope this helps

What is the minimum number of steps to get full javadoc support with the new default project options?

With the new SDK Tools and ADT versions 22.6.2, the default options for creating a new project with a blank activity produces a project which uses Fragments and refers to a library project (a new one for each project) named appcompat_v7_x.
The relevant parts of the stub code for the main activity are:
package com.myname.miniandroid;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
.....
.....
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
....
}
public static class PlaceholderFragment extends Fragment {
......
......
}
}
.
We can see that it uses a Fragment and an ActionBarActivity. The automatically created library project has both the v4 and the v7 jars in its libs folder, the main project has just the v4 jar. As built by default, hovering over either of these classes gives no javadoc information.
To get such support I've had to :
1) insert a file android-support-v7-appcompat.jar.properties into the libs folder of my automatically created appcompat_v7_4 library project. It contains the lines:
doc=c:\\dev\\tools\\android-sdk-windows4.4\\docs\\reference
src=C:\\dev\\tools\\android-sdk-windows4.4\\extras\\android\\support\\v7\\appcompat\\src
(Both lines seem to be necessary)
2) insert a file anndroid-support-v4.jar.properties into the libs folder of the main project. It contains the line:
src=C:\\dev\\tools\\android-sdk-windows4.4\\extras\\android\\support\\v4\\src
3) Close and reopen both projects and clean all projects.
I've got a brand new installation of Eclipse Kepler and an up to date installation of the SDK.
I feel that there must be a quicker way of getting set up to start a new project with the recommended default options. If anyone can tell me what it is, I would be most grateful.
You have use the "New" button in the upper left corner, select Android Application Project, choose the name, icon...
When you have done, you should have a working "Hello world" app.
If you want to add external libraries this is the answer: https://stackoverflow.com/a/3643015/3203988

Upgrading from Cordova 2.5 to Cordova 3.0 , facing issue while using CordovaInterface

I am migrating my project to Cordova 3 from Cordova 2.5. Followed the migration process mentioned in
http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html
But, unfortunately getting the following error
Preparing android project [Error: No Java files found which extend
CordovaActivity.]
In our app, we have a class which extends activity and implements CordovaInterface. And moreover this class is in the location mentioned in config.xml.
Yet, I am facing the following error. Is it mandatory to substitute CordovaInterface with CordovaActivity? I am pretty sure that will not be the mandatory case.
This is causes by a bonehead, broken, Cordova build system.
If you simply add any old class in your source tree, next to your activity, that extends CordovaActivity, the build will work.
You don't even have to use the class, just make one.
It's like they are having an internal debate about how it should work, and one side screwed over the other by making the build fail if they didn't get their way.
Example:
import org.apache.cordova.CordovaActivity;
/**
* This class is simply here to make sure Cordova will build. Without it, even
* though it's not used or otherwise referenced, you will get a build error that
* looks like "Error: No Java files found which extend CordovaActivity".
*
* This applies as of Cordova 3.5.0. It should be re-tested when upgrading to
* Cordova 4.x.
*
*/
public class FakeCordovaActivityForBuild extends CordovaActivity {
}
With luck, someone on the dev team will notice this little conflict and fix it, I suppose it should be listed as a bug in their system, but I have not added it.
Interestingly, replacing CordovaInterface with the CordovaActivty (and appropriate changes) resolved the issue. There is no mention of mandatory usage of CordovaActivity in release notes documentation.
However, need to refine code inside the Java file which extends CordovaActivity.

Android: Can't get logs with SLF4J-Android

I'm building a really simple Android project in ADT and using Maven. I have included both the slf4j-api and slf4j-android dependencies and I can see that everything is compiling properly. However, when I run or debug the application on my Nexus One, I don't see any log output. Is there a specific place I should be looking for these logs or should they be coming out in the Eclipse console?
For reference, here's my main activity:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.app.ListActivity;
import android.os.Bundle;
public class HomeActivity extends ListActivity {
private static Logger logger = LoggerFactory.getLogger(HomeActivity.class);
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
logger.debug("onCreate");
}
}
Android by default tells slf4j-android to not to log debug messages, and log4j is polite enough to honor that. Use the impolite https://github.com/mvysny/slf4j-handroid instead :)
I use slf4j as well for logging. The log output shows up on the LogCat window. I'm not sure if there's a way to see it in the Eclipse console. In the Eclipse top-level menu, navigate to: Window -> Show View -> Other. When the dialog appears, expand "Android", and select "LogCat". It doesn't show up by default, unfortunately.
HTH,
Kevin
You may want to have a look at using slf4j together with android-logging-log4j. Also see log4j support in Android.

Problems importing an Android project into Eclipse

I reinstalled my computer and tried now to import my Android project into the workspace.
(File -> Import -> General -> Existing Project into Workspace)
But now I have got a strange error.
bNormal.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
gotoNextQuestion();
}
});
In the second line (#Override) eclipse always tells me there is an error:
/* Multiple markers at this line
- implements android.view.View.OnClickListener.onClick
- The method onClick(View) of type new View.OnClickListener(){} must override a superclass Method */
This happens everywhere, where #Override is used.
I already tried to Android-Tools -> Fix Project Settings and Project -> Clean.
I hope somebody can help me with this strange problem.
Thanks, Mark
It is because the language level is set to 5.0. Change it to 6, and all will work fine. Don't know where to set it eclipse, but in Idea it's File - Project Structure - Project Language level
It happens because OnClickListener is an interface and in 5th Java #Override can not be applied to a method implementation.
Your android SDK is probably not in the same path. Fix that in your eclipse settings.

Categories

Resources