problem with piece of code in android

Put your problem here if it does not fit any of the other categories.

problem with piece of code in android

Postby aglesteban » Sun Jan 11, 2009 7:49 pm

Hi, I´m having a problem with a piece of code in android, I put here the part that fails. I don´t know the reason why it fails.



/*
Attributes
*/


public Class<? extends Context> contextClass = Context.class;

private Class<? extends Graphmaster> graphmasterClass = Graphmaster.class;


This is the code that fails:


Context context = (Context) contextClass.newInstance();



/*
Accessor Section
*/

public <C extends Context> void contextClass(Class<C> contextClass)
{
this.contextClass = contextClass;
}
aglesteban
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Fri Nov 21, 2008 5:11 pm

Top

Postby ErnestoGuevara » Mon Jan 12, 2009 10:42 pm

I'm not going to be able to stare at this right now. But I suggest you make your subject a bit more descriptive - it might help you get the answer you're looking for.

Almost every post in this category is a problem with a piece of code in android.

Che
ErnestoGuevara
Experienced Developer
Experienced Developer
 
Posts: 75
Joined: Thu Jan 08, 2009 2:02 am

Postby aglesteban » Tue Jan 13, 2009 10:27 am

You are right, jeje, sorry.
I just didn´t know what subject should I put for this problem, cause I don´t know where this problem comes from.
I´m trying to find why it doesn´t work, spending a lot of time on this, but I´m not able to find any clue.
Thank you for replying my threat che!
aglesteban
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Fri Nov 21, 2008 5:11 pm

Postby MrSnowflake » Tue Jan 13, 2009 2:34 pm

Why are you trying to do such crazy stuff? You can't create your own Context for a good reason: The context should be created by the system, because it has references to a lot of stuff that's present in the system. And that's something you can't do when you want to instantiate it yourself.
If you have an Activity, BroadcastReceiver, ContentProvider or Service, that's your context and you should always give it as a reference to child objects. You should NEVER instantiate your own Context directly.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby aglesteban » Wed Jan 14, 2009 9:04 pm

Oh, I see. I didn´t notice, I´m using a different class called Context, now I´m renaming this, but now I found a different problem. I can not import this 2 classes:

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
aglesteban
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Fri Nov 21, 2008 5:11 pm

Postby MrSnowflake » Wed Jan 14, 2009 9:42 pm

that's because java.beans isn't in Android...
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Postby aglesteban » Thu Jan 15, 2009 9:35 am

Ok, thank you. Thanks a lot. Now I have to figure out how to change that if possible. Thanks.
aglesteban
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Fri Nov 21, 2008 5:11 pm

Postby aglesteban » Thu Jan 15, 2009 12:41 pm

Is there a way to include the package java.beans in android.
aglesteban
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Fri Nov 21, 2008 5:11 pm

Postby MrSnowflake » Thu Jan 15, 2009 3:08 pm

I don't think so, as I imagine it uses JNI, but you could try though.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 12 guests