Android :: Adding To ArrayList In Characters Method Of DefaultHandler SAX

Jun 30, 2010

I'm assuming that your input XML is very simple and uses no element attributes, namespaces, or recursively nested elements. I recommend you use the following pattern, which I've used countless times:

Use a StringBuffer or StringBuilder to collect character data. Initialize it in startElement. In the characters method, do only the following: sb.append(ch, start, length). Please note that SAX parsers are not required to return the full contents of a text node in a single call to characters(). For efficiency, the parser may use an input buffer which may be smaller than a particular text node. A lot of people seem to miss this. Do the major processing in the endElement() method.

Do you use a debugger to step through your code?

Android :: Adding to ArrayList in Characters method of DefaultHandler SAX


Android :: Adding ArrayList Of LinearLayout Objects To UI

Jan 27, 2010

I am trying to use the following code to go through an ArrayList of LinearLayout objects, add each one to a TableLayout, and finally add that TableLayout to a ScrollView defined in the main.xml file.

ScrollView theScrollView = (ScrollView) findViewById (R.id.scroll_view); TableLayout theList = new TableLayout(this); ArrayList<LinearLayout> theArray = Edit.getTheArray();

if (theArray.size() > 0) { for (int i = 0; i < theArray.size(); i++) { theList.addView(theArray.get(i)); } theScrollView.addView(theList); }

A second activity (Edit) is used to convert user input into a new LinearLayout and put it in the ArrayList. The code works successfully on the first item in the Array, however, after adding a second LinearLayout to the ArrayList and returning to the main activity, I get a force close and the following error: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

I can't seem to figure out what is happening here. Is there another method I should be using to get my desired results?

View 2 Replies View Related

Android :: Adding To The Middle Of An Empty ArrayList

Aug 26, 2010

If I create a new arraylist of size 5...

And then I try to add to the middle of that arraylist...orderedPlayers.add(2, P);


I get an indexoutofbounds...I also get indexoutofbounds if I use set instead of add...orderedPlayers.set(2, P);


In fact the only way I can add P to the arraylist is if I use the 0 index...orderedPlayers.add(0, P);

And also for some strange reason when I do that my debugger in eclipse sees that element added to the 4th index of orderedPlayers instead of the 0th... is ArrayList buggy or am I completely missing something? how would I add to the middle of a null ArrayList?

View 7 Replies View Related

Android :: Adding Group ArrayList Into Single One / How To Recognize Each?

Oct 28, 2010

Can I add a group of ArrayList into a single ArrayList? The ArrayList groups are of different sizes. Then How can I recognize each ArrayList?

View 3 Replies View Related

Android :: ArrayList In Adapter Not Working / Using History Share Method

Nov 21, 2010

I retrieve Json data (the JSONArray) and I wanted to make a List of all the names in the JSONArray, something like this.
List list = new ArrayList<String>();
for(int i=0;i < data.length();
i++){list.add(data.getJSONObject(i).getString("names").toString());}

And I wanted to take this list in an `ListView' so I did this:
ArrayList<String> test = history_share.list;
names_list = (String[]) test.toArray();
ArrayAdapter<String> adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, names_list);
setListAdapter(adapter);

History_share is one of the method I created to take json data from an api. Eclipse doesn't see any error, and me neither.

View 1 Replies View Related

Android :: Implementing Characters Method Using SAXParser On Android?

Feb 8, 2010

I am parsing xml using the SAXParser and want to know if this is the right way to implement the characters method. Assume there's a class-level String variable named elementValue and it is initialized to "" in the startElement method.

Here is the characters method:
@Override
public void characters(char[] ch, int start, int length) {
String charsToAppend = new String(ch, start, length);
elementValue = elementValue + charsToAppend;
}
Is it correct that we need to append to the value we have so far and is the append being done correctly? Also, why does the characters method give the start index? Won't it be zero every time?

View 2 Replies View Related

General :: Browser Sign-in Method For Adding Google Accounts In Android?

Apr 16, 2012

Android 3 and 4 have a new option that allows the user to add new a Google Account to the phone by using the Browser Sign-In. The option is available when you try to add a new Google Account to Android (see screenshot).

Use Browser Sign-In with SAML based Single Sign-On? It is not working with our SAML setup.

View 1 Replies View Related

Motorola Droid :: App / Method For Quickly Adding A Contact?

Nov 13, 2009

I have searched the Android store, and also searched these forums but maybe some more advanced Droid users can help me find an answer.

As with the iphone, inputting a new phone number within seconds is rather difficult on the Droid. That got me wondering if there were any third party apps or at least a way through the device OS that will let me quickly add a new contact. So far as I can tell the quickest way is to hit Phone--> input # --->option key---> add to contacts ---> Create new contact. That is 6 steps just to take someone's number! There's got to be a better way.

View 2 Replies View Related

Android :: Method OnBackPressed() Of Type FirstGroup Must Override Superclass Method

Sep 7, 2010

I'm trying to override the onBackPressed() method of the ActivityGroup class:

public class MyClass extends ActivityGroup {

@Override
public void onBackPressed() {
// do something
return;
}

but I'm getting the error The method onBackPressed() of type MyClass must override a superclass method. I'm relatively new to Java, I've seen here that people do it and it works for them Why I'm getting this error? I'm writing an app for android 1.5, could the problem be here?

View 1 Replies View Related

Android :: Show Method Definition - Eclipse Recognizes Warning On Method

Nov 22, 2010

In Eclipse, when I mouse hover over a built-in method, it displays a method definition including stuff like what the method does, input objects, return objects etc. If I have a yellow line (warning) under the method I'm trying to use, I can't get the mouse-over to show the definition. If I try hitting F3, I get a "The Jar of this class file belongs to container "Android 1.6" How do I show the definition of the method I am using when there is a warning?

View 1 Replies View Related

Android :: Method.getAnnotation( ) Or Method.isAnnotationPresent( ) Not Working

May 12, 2010

I am trying to use annotation - method.getAnnotation( ) or method.isAnnotationPresent( ) and it is not working. I am using eclipse emulator for 2.1 OS version with JDK 1.6. Following is information about what I did..................

View 4 Replies View Related

Motorola Droid :: Adding Contacts To Phone W/o Adding To Gmail

May 3, 2010

I want to add a contact just to my phone and not to my gmail account.Whenever I start to add a contact (phone, 208544.menu, +contact, create new contact,) the next thing it forces me to do is to choose an account to create the new contact under and it lists my 3 gmail accounts.I have no option to just put it on the phone.Any ideas here?We do the same thing on the Incredible but it gives us the gmail account and the phone to choose from but not on the Motorola.

View 4 Replies View Related

Android :: How To Display An ArrayList?

Sep 9, 2009

I'm new to android developing and I've done a function which return an arraylist type ArrayList<ArrayList>. I would like to display this arraylist for see if my function work.

View 11 Replies View Related

Android :: ArrayList In Custom View?

Oct 9, 2010

I'm writing my own custom view, a keyboard, which I think the ArrayList in the keyboard view is causing the application to quit in the emulator.
public static ArrayList<HexButton> hexButtons = new ArrayList<HexButton>();

The application ran fine when I did
setContentView(myKeyboardView);

But I want to nest my keyboard with a TextView so I'd like to be able to do
setContentView(R.layout.main);

View 2 Replies View Related

Android :: Passing An ArrayList Of Objects

Nov 12, 2010

Is there a way to pass an Array List of objects between activities? The myObject implements Parcelable and I'm able to successfully pass the objects around individually, but that means I need to have an exact amount of "myObjects" coded. I want this to dynamically grow/shrink by what the user does with the app. I have seen some posts on the web about doing:

Activity A
ArrayList<myObject> myObjArray = new ArrayList<myObject>();

Then when passing this into the intent I would use:
intent.putParcelableArrayListExtra("myObjArray", myObjArray);

Activity B
ArrayList<myObject> myObjArray = new ArrayList<myObject>();
Bundle extras = getIntent().getExtras(); myObjArray = extras.getParcelableArray("myObjArray");

However, the myObjArray always gets filled with "null". How can I achieve this?

View 3 Replies View Related

Android :: Passing ArrayList Across Activities

Apr 7, 2009

I have an ArrayList<MyList> aList in an activity. I would like to send this data to another activty. Such that,
ArrayList<MyList> aList;
Intent intent = new Intent(); intent.setClass(mainactivity.this, newActivity.class); intent.putExtra("MyList", aList ); startActivity(intent);

On the receiving activity,
Intent i = getIntent(); newList = (ArrayList<MyList>) i.getSerializableExtra("MyList");
But this gets me no where. ERROR! My intention is to share this List between activities.

View 4 Replies View Related

Android :: Arraylist Storage In SQLite

Nov 16, 2009

Can any one tell me how to store and retrieve arraylist in/from sqlite.
ArrayList<Double> results = new ArrayList<Double>();

View 4 Replies View Related

Android :: Custom ArrayList Serialization

May 30, 2010

I was trying to serialize an ArrayList which contains custom objects. I'm serializing it in a Servlet (server side), and deserialize at the client side. (using ObjectOutputStream and ObjectInputStream)

It worked fine, when I work with ArrayList<String>.
But when I tried it with ArrayList<MyObject> I couldn't get any results in the client side, this is the exception:
java.lang.ClassNotFoundException: web.MyObject

Of course I have done this:
public class MyObject implements Serializable { ... }
MyObject contains only String fields.

View 1 Replies View Related

Android :: ArrayList & Contains() - Case Insensitive

Jun 8, 2010

I want the contains() method from ArrayList to be case insensitive. Is there any way?

View 1 Replies View Related

Android :: Share An Arraylist Between Applications

Jun 15, 2010

I have two applications which i want them to share the same arraylist.

How could i achive something like that? is there anything in Android for sharing such a prefrenceses?

View 2 Replies View Related

Android :: Correct Way To Add Objects To An ArrayList

Aug 19, 2010

I am trying to add an object to an arraylist but when I view the results of the array list, it keeps adding the same object over and over to the arraylist. I was wondering what the correct way to implement this would be.

CODE:..............

I have double checked my JSONArray data and made sure they are not duplicates. It seems to keep adding the first object over and over.

View 2 Replies View Related

Android :: Save The Contents Of An ArrayList?

Aug 26, 2010

I want to save an ArrayList so that it is persistent. The contents can change. What is the best way of approaching this in android?

View 2 Replies View Related

Android :: How To Pass ArrayList Using PutStringArrayListExtra()

Oct 27, 2010

I want to pass an Arraylist from one activity to another. I use putStringArrayListExtra(), but there shows an error : "The method putStringArrayListExtra(String,ArrayList is undefined for the type bundle." Is there any other method available for passing ArrayList?

CODE:..................

View 3 Replies View Related

Android :: Can't Add Item To Arraylist With Bottonclick / How To Do

Sep 1, 2010

Something is wrong whit my code. in application when I "add item", it doesn't show anything, and if aim clicking somewhere around the android application, then "item" sometimes comes. code...

View 1 Replies View Related

Android :: Displaying Certain Data Of Object In ArrayList?

Apr 7, 2010

I wish to display data in the the arraylist in a list view. The arraylist is not a generic list but a object defined by me. I want to display only certain data of the object. Something like, an object of a student, I want to display the student's name only, the student id and the student dob is not required.

View 4 Replies View Related

Android :: Code Which Would Be Much Easier Implemented As ArrayList

Apr 3, 2009

I notice in the source code they are not used in critical loops, e.g. in View.java :
http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;...
I can see this kind of code which would be much easier implemented as an ArrayList :

1867 private void addInArray(View child, int index) { 1868 View[] children = mChildren;
1869 final int count = mChildrenCount;
1870 final int size = children.length;
1871 if (index == count) { 1872 if (size == count) { 1873 mChildren = new View[size + ARRAY_CAPACITY_INCREMENT];
1874 System.arraycopy(children, 0, mChildren, 0, size);
1875 children = mChildren;
1876 } 1877 children[mChildrenCount++] = child;
1878 } else if (index < count) { 1879 if (size == count) { 1880 mChildren = new View[size + ARRAY_CAPACITY_INCREMENT];
1881 System.arraycopy(children, 0, mChildren, 0, index);
1882 System.arraycopy(children, index, mChildren, index + 1, count - index);
1883 children = mChildren; 1884 } else { 1885 System.arraycopy(children, index, children, index + 1, count - index);
1886 } 1887 children[index] = child;
1888 mChildrenCount++;
1889 } else { 1890 throw new IndexOutOfBoundsException("index=" + index + " count=" + count);
1891 } 1892 };

View 3 Replies View Related

Android :: Pass ArrayList Parameters Between Two Activities

Apr 19, 2010

Today I met a problem, I need to pass a ArrayList<MyClass> from an activity to another. I dont know what the Intent exactly do when I use putExtra to pass in an ArrayList<MyClass> object. I guess MyClass need to implement Parcelable interface, so I just did it. But still, it does not work. Maybe I need to create a Bundle and then use Bundle's putParcelableArrayList method to put my ArrayList<MyClass> object in, and then pass this bundle as parameter of putExtra to the intent. So crazy! I am lazy, I just want to pass an ArrayList<MyClass> object simply, is there a simple way??

View 10 Replies View Related

Android :: Using SAXParser To Get List Of Strings To Arraylist

Jun 21, 2010

I'm trying to parse a web service response using SAXParser and get certain values, store them into an arraylist, then display them in a listview. Example XML being returned from web service:
<ArrayOfStrings>
<string>value</string>
<string>value</string>
<string>value</string>
</ArrayOfStrings>

Here is my SAXHandler class:
public class SAXHandler extends DefaultHandler {
private boolean outertag = false;
private boolean mytag = false;
ArrayList<String> alist;
public ArrayList<String> getList(){
return this.alist;
} @Override
public void startDocument() throws SAXException {
} @Override
public void endDocument() throws SAXException{
} //@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
if (localName.equals("ArrayOfString")){ this.outertag=true;
}else if (localName.equals("string")){ this.mytag=true;
} }
@Override
public void characters(char ch[], int start, int length) {
if (this.mytag){ String s = new String(ch, start, length);
alist.add(s);
} }
@Override public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
if (localName.equals("ArrayOfString")){ this.outertag=false;
}else if (localName.equals("string")){ this.mytag=false;
} } }

And here's my method calling and returing my web service:
try{ URL url = new URL("xxxxxxx");
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
SAXHandler SAXHandler = new SAXHandler();
xr.setContentHandler(SAXHandler);
xr.parse(new InputSource(url.openStream()));
ArrayList<String> stateList = SAXHandler.getList();
aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, stateList);
RESTlist.setAdapter(aa);
I keep getting an exception and I don't know why. Can anyone give me a hand?

Logcat:
06-21 20:10:47.901: ERROR/AndroidRuntime(472): Uncaught handler: thread main exiting due to uncaught exception
06-21 20:10:47.950: ERROR/AndroidRuntime(472): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pa.passammain/com.pa.passammain.RESTtest}: java.lang.NullPointerException: println needs a message
06-21 20:10:47.950: ERROR/AndroidRuntime(472): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
06-21 20:10:47.950: ERROR/AndroidRuntime(472): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
06-21 20:10:47.950: ERROR/AndroidRuntime(472): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
06-21 20:10:47.950: ERROR/AndroidRuntime(472): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
06-21 20:10:47.950: ERROR/AndroidRuntime(472): at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 20:10:47.950: ERROR/AndroidRuntime(472): at android.os.Looper.loop(Looper.java:123)
06-21 20:10:47.950: ERROR/AndroidRuntime(472): at android.app.ActivityThread.main(ActivityThread.java:4203)
06-21 20:10:47.950: ERROR/AndroidRuntime(472): at java.lang.reflect.Method.invokeNative(Native Method)
06-21 20:10:47.950: ERROR/AndroidRuntime(472): at java.lang.reflect.Method.invoke(Method.java:521)
06-21 20:10:47.950: ERROR/AndroidRuntime(472): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
06-21 20:10:47.950: ERROR/AndroidRuntime(472): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
06-21 20:10:47.950: ERROR/AndroidRuntime(472): at dalvik.system.NativeStart.main(Native Method)
06-21 20:10:47.950: ERROR/AndroidRuntime(472): Caused by: java.lang.NullPointerException: println needs a message
06-21 20:10:47.950: ERROR/AndroidRuntime(472): at android.util.Log.println(Native Method)
06-21 20:10:47.950: ERROR/AndroidRuntime(472): at android.util.Log.e(Log.java:208)
06-21 20:10:47.950: ERROR/AndroidRuntime(472): at com.pa.passammain.RESTtest.onCreate(RESTtest.java:82)
06-21 20:10:47.950: ERROR/AndroidRuntime(472): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
06-21 20:10:47.950: ERROR/AndroidRuntime(472): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
06-21 20:10:47.950: ERROR/AndroidRuntime(472): ... 11 more

After editing how my error is displayed in my try/catch i'm not longer getting an exception, but just a blank screen. Here is what my logcat is displaying:

06-21 20:22:00.330: WARN/System.err(542): java.lang.NullPointerException
06-21 20:22:00.352: WARN/System.err(542): at com.pa.passammain.SAXHandler.characters(SAXHandler.java:45)
06-21 20:22:00.352: WARN/System.err(542): at org.apache.harmony.xml.ExpatParser.text(ExpatParser.java:166)
06-21 20:22:00.362: WARN/System.err(542): at org.apache.harmony.xml.ExpatParser.append(Native Method)
06-21 20:22:00.371: WARN/System.err(542): at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:506)
06-21 20:22:00.371: WARN/System.err(542): at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:467)
06-21 20:22:00.371: WARN/System.err(542): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:329)
06-21 20:22:00.381: WARN/System.err(542): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:286)
06-21 20:22:00.381: WARN/System.err(542): at com.pa.passammain.RESTtest.onCreate(RESTtest.java:71)
06-21 20:22:00.391: WARN/System.err(542): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
06-21 20:22:00.391: WARN/System.err(542): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
06-21 20:22:00.401: WARN/System.err(542): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
06-21 20:22:00.401: WARN/System.err(542): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
06-21 20:22:00.410: WARN/System.err(542): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
06-21 20:22:00.410: WARN/System.err(542): at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 20:22:00.420: WARN/System.err(542): at android.os.Looper.loop(Looper.java:123)
06-21 20:22:00.420: WARN/System.err(542): at android.app.ActivityThread.main(ActivityThread.java:4203)
06-21 20:22:00.420: WARN/System.err(542): at java.lang.reflect.Method.invokeNative(Native Method)
06-21 20:22:00.430: WARN/System.err(542): at java.lang.reflect.Method.invoke(Method.java:521)
06-21 20:22:00.430: WARN/System.err(542): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
06-21 20:22:00.442: WARN/System.err(542): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
06-21 20:22:00.442: WARN/System.err(542): at dalvik.system.NativeStart.main(Native Method)

View 1 Replies View Related

Android :: Passing ArrayList - String - Between Tabs

Jun 5, 2010

I'm not very clear about the Intent object and how to use it to pass data between Activities. In my application I have several tabs between which I want to pass ArrayList. Here is a sample code I plan to use, but I'm missing the part where the main activity catches the Intent and passes it to the new activity on start :

1. myTabs.java ==> This is where I think I need to add some code to pass the data between TabOne and TabTwo. For now it is just using the sample code of the TabActivity sample.

CODE:...........

2. TabOne.java ==> I added a piece of code in the onStop procedure to fill in the Intent data with the array I want to pass to TabTwo. Not sure it is the right way to do though.

CODE:...................

View 2 Replies View Related

Android :: Save Variable And ArrayList Of Object

Dec 1, 2009

I created an application with loging and an arraylist to fill a ListView.

If i am calling or i need to check my mail, sometimes i lost the context of my application (variables and the listview !)

It is a little complex to save arraylist in SharedPreferences and i am not an expert in SQLite.

Do you know a solution to keep persistent my data (variables and the arraylist) during the use of my application?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved