aspose file tools*
The moose likes Android and the fly likes global varible gives ClassCastException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "global varible gives ClassCastException" Watch "global varible gives ClassCastException" New topic
Author

global varible gives ClassCastException

sam liya
Ranch Hand

Joined: Nov 25, 2008
Posts: 1225
this is my main class



this is manifest file



below is the error i am getting

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42926
    
  68
Something is amiss: the stack trace mentions line 93 in the onCreate method of MainActivity, but the code you posted is way shorter. Which one is line 93?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42926
    
  68
Ah, that stack trace makes more sense. You're not setting the app context class to anything called "Global" in the manifest, so it's android.app.Application - nothing mysterious about it.
sam liya
Ranch Hand

Joined: Nov 25, 2008
Posts: 1225
But i have added the below to manifest

Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

sameera liyanage wrote:But i have added the below to manifest


Yes, you defined an Activity with the name Global. But you try to get the application (Global global = ((Global)getApplicationContext());) and assign it to Global. The Application Context is a subclass of android.app.Application, not an activity.

Read this document on the Android Manifest: http://developer.android.com/guide/topics/manifest/manifest-intro.html. It has links on the application element, which is what you would use to override the class used for the Application Context.
sam liya
Ranch Hand

Joined: Nov 25, 2008
Posts: 1225
I change the manifest code as below.Now it's fine.Anyway if i have two Global classes how to add them to manifest file.Because we can't add two name parameters to manifest file

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42926
    
  68
An app can only have a single app context class. What are you trying to accomplish by having two? That would seem to make things more difficult, instead of simpler.
sam liya
Ranch Hand

Joined: Nov 25, 2008
Posts: 1225
below is my Global class


My problem is ,in the set method it just initialize he size of arra.it's ok.But how to add element to them?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42926
    
  68
You can either call getTIME() (for example), and then do whatever needs doing with the array it returns, or add a method that addToTIME(String) that adds that string as the last element of the TIME array.

Two remarks, though: variables have lowercase names. While uppercase is permissible, it is so exceedingly rare that people who look at your code will wonder what's going on. Uppercase is generally used for names of constants.

Secondly, if you don't know beforehand how many elements an array has, it's probably better to use a Collection instead of an array - maybe an ArrayList<String>. That makes it easy to add elements at the end, and to find out how many elements it already contains.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: global varible gives ClassCastException