Problem with listing 35.7


#1

Two problems:

  1. It tells me I need API 11 at least

  2. I get an error on the onCreateLoader method:

		public Loader<Run> onCreateLoader(int id, Bundle args) {
			return new RunLoader(getActivity(), args.getLong(ARG_RUN_ID));
		}

Comparing my solution to the one in the download, I see that the difference is in the imports. I had:

The download has:

Which leads to a question:

Can I tell Eclipse to favor the support.v4 (or v13, now that it’s available) over the standard library when they have the same class names?


#2

I have noticed that when I cut/paste code from another project that Eclipse automatically inserts the imports without asking. I just found that if you open the Preferences window, and go to

[color=#800000]Java -> Editor -> Typing [/color]

there is a checkbox under [color=#0000FF]When Pasting[/color] that says [color=#0000FF]Update imports[/color]. I am going to uncheck this and see what happens…


#3

I think you’ve actually got this well in hand, it seems like. Everything you’ve said is spot on.

Let me know if I can provide any additional help.


#4

Did you ever solve this problem? I am getting the exact same issue.

@Override public Loader<Run> onCreateLoader(int id, Bundle args) { return new RunLoader(getActivity(), args.getLong(ARG_RUN_ID)); }

…gives an error that says “cannot convert from RunLoader to Loader”

I get the same thing a few lines later when trying to implement the LocationLoaderCallbacks. “cannot convert from LastLocationLoader to Loader”

I’ve checked my imports and tried a few small things. Maybe I’ve just been staring at it too long.


#5

I’have the same issue that elliott has. What can be the solution for this ?


#6
@Override
	public Loader<Cursor> onCreateLoader(int id, Bundle args) {
		// TODO Auto-generated method stub
		long runId=args.getLong(ARG_RUN_ID,-1);
		return new LocationListCursorLoader(getActivity(),runId);
	}

also in this line it says: “Type mismatch: cannot convert from LocationListCursorLoader to Loader” what can be done for this ? any ideas…


#7

Just make sure and verify that your imports are correct: they should always have the support library Loader imported, not android.app.Loader. Check all the classes in your project, too, not just the one where you’re seeing the error.


#8

I’m sorry but I don’t think it’s just the imports. I’ve gone through all of the classes in my application and am still getting the above error.

It’s worth noting that I’m using this as a textbook for a university course and all of my students are getting the same error.

I’m at the point where I am going to start copying and pasting my code into the provided solution (which works) to try to track down the difference(s) that is causing this issue. I won’t be able to do that for a few days, but I wanted to report back.


#9

I had the same problem and tracked it down to an different import mistake.

In DataLoader.java, Eclipse imported:
import android.content.AsyncTaskLoader;
should be:
import android.support.v4.content.AsyncTaskLoader;


#10

@Stever: I had the same issue, and your solution resolved it. Thank you.

@Elliot: Although I assume you’ve resolved this issue in the intervening year since this thread was last active… Should you find yourself in a similar situation in the future, and need to compare two files, Eclipse will do this automatically. Select two files (ctrl+click in Linux, something else in MacOS), right click, and in the resulting menu select “compare->to each other”… That’s not really a direct solution to your problem, but maybe an easy shortcut for next time.

-AB