• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
jellomaj

errors trying to use loaders in android

7 posts in this topic

So I'm trying to make AOuth work in android for twitter. Here's the code I'm having errors with in my activity:

@Override
public Loader<OAuthConsumer> onCreateLoader(int id, Bundle arg1) {

    consumerLoader = new getCommonsHttpOAuthConsumer(); //consumerLoader is declared in the activity as "private Loader<OAuthConsumer> consumerLoader;"
    return consumerLoader;
        // After this method you're going in loadInBackground()
}

Here's the code for my asyncTaskLoader:

class getCommonsHttpOAuthConsumer extends AsyncTaskLoader<OAuthConsumer>{

	public getCommonsHttpOAuthConsumer(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	@Override
	public OAuthConsumer loadInBackground() {
		// TODO Auto-generated method stub
		
		return new CommonsHttpOAuthConsumer(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET);
	}
	
}

This is a 2 part question. 1st question: I get an error when I use import android.support.v4.app.LoaderManager The error is on Loader<OAuthConsumer>. It says "The return type is incompatible with LoaderManager.LoaderCallbacks.onCreateLoader(int, Bundle)". But the error goes away if I use import android.app.LoaderManager instead. My question is: Should I try to fix the error with using the support library, so that more devices will be compatible with my app? If yes, how can I fix that error?

 

2nd question: No matter what import I use, I get an error on new getCommonsHttpOAuthConsumer(); The error says: "Type mismatch: cannot convert from getCommonsHttpOAuthConsumer to Loader". What am I doing wrong?

Edited by jellomaj
0

Share this post


Link to post
Share on other sites

But the error goes away if I use import android.app.LoaderManager instead. My question is: Should I try to fix the error with using the support library, so that more devices will be compatible with my app?

The sad-but-true fact is that if you want broad support you really should build against 2.3.  It represents almost 40% of all current users.  So use the older version.

 

For your errors, you need to return the right type.  Make sure your class extends the Loader class that matches the same interface (android.support.v4.content.Loader).  

1

Share this post


Link to post
Share on other sites

For your errors, you need to return the right type.  Make sure your class extends the Loader class that matches the same interface (android.support.v4.content.Loader).  

I'm already doing that: public class MainActivity extends Activity implements LoaderManager.LoaderCallbacks

 

is that what you mean?

0

Share this post


Link to post
Share on other sites

For your errors, you need to return the right type.  Make sure your class extends the Loader class that matches the same interface (android.support.v4.content.Loader).  

I'm already doing that: public class MainActivity extends Activity implements LoaderManager.LoaderCallbacks

 

is that what you mean?

 

That is one of the lines, yes.  Which interface is it?

 

The android SDK people made a mistake when they reused the names.  (It is a common enough mistake, but still very annoying and far too frequent.)

 

So which LoaderManager is it?  Is that supposed to be android.support.v4.app.LoaderManager or android.app.LoaderManager ?  Both of them are LoaderManager classes, but the two types are not compatible.

 

When in doubt give the full path.

Edited by frob
1

Share this post


Link to post
Share on other sites

I use the full path Activity implements android.support.v4.app.LoaderManager.LoaderCallbacks. I still get the errors

 

thx for the help btw

Edited by jellomaj
1

Share this post


Link to post
Share on other sites

I still get the errors

Then something is still pointing to the other type.
 
Double-check that import android.app.LoaderManager does not appear in any of your files.  After verifying that it isn't present, rebuild the files.

 

 

If the problem still persists, post the relevant updated code.

Edited by frob
1

Share this post


Link to post
Share on other sites

Double-check that import android.app.LoaderManager does not appear in any of your files.  After verifying that it isn't present, rebuild the files.

 

 

If the problem still persists, post the relevant updated code.

MainActivity is the only activity present in my app, so import android.app.LoaderManager is not written anywhere else.

Could it be because my target sdk version is 16? My minimum sdk version is 10. I doubt it, since changing those values doesn't fix the errors.

 

Here's the code for my main activity. I removed anything that didn't have to do with the problem. Tell me if you want the whole thing:

import oauth.signpost.OAuth;
import oauth.signpost.OAuthConsumer;
import oauth.signpost.OAuthProvider;
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
import oauth.signpost.commonshttp.CommonsHttpOAuthProvider;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.auth.AccessToken;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.Loader;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.content.AsyncTaskLoader;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.support.v4.app.LoaderManager;
//import android.app.LoaderManager;

public class MainActivity extends Activity implements android.support.v4.app.LoaderManager.LoaderCallbacks{

	final String TAG = getClass().getName();
	
	private OAuthConsumer consumer;
        private OAuthProvider provider;
        private String token;
        private String secret;
        private Loader<OAuthConsumer> consumerLoader;
    
        Activity context;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.activity_main);
		
	    Button signInButton = (Button) findViewById(R.id.signInButton);
        
            signInButton.setOnClickListener(new View.OnClickListener() {
			
	        public void onClick(View v) {
	        	// TODO Auto-generated method stub
	    	    sign_in();
	        }
	    });		
	}

	public void sign_in()
        {
    	    try {
    	        this.consumer = (OAuthConsumer) new getCommonsHttpOAuthConsumer(context);    	    
    	    } catch (Exception e) {
    	        Log.e(TAG, "Error creating consumer / provider",e);
    	    }    	
        }
    
    
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    // Inflate the menu; this adds items to the action bar if it is present.
	    getMenuInflater().inflate(R.menu.activity_main, menu);
	    return true;
	}
	
	
	@Override
        public Loader<OAuthConsumer> onCreateLoader(int id, Bundle arg1) {
            consumerLoader = new getCommonsHttpOAuthConsumer();
            return consumerLoader;
        }
	
	
}


class getCommonsHttpOAuthConsumer extends AsyncTaskLoader<OAuthConsumer>{

	public getCommonsHttpOAuthConsumer(Context context) {
	    super(context);
	    // TODO Auto-generated constructor stub
	}

	@Override
	public OAuthConsumer loadInBackground() {
	    // TODO Auto-generated method stub
		
	    return new CommonsHttpOAuthConsumer(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET);
	}
	
}
Edited by jellomaj
0

Share this post


Link to post
Share on other sites

Well, I fixed the error on public Loader<OAuthConsumer> onCreateLoader by replacing it with public android.support.v4.content.Loader onCreateLoader.

 

I also fixed the error on new getCommonsHttpOAuthConsumer(); by replacing private Loader<OAuthConsumer> consumerLoader; with private getCommonsHttpOAuthConsumer consumerLoader;

 

I don't know if it's right tho

Edited by jellomaj
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0