Problem in providing a string to the JavaScript

by Nishant Bhargava » Fri, 19 Nov 2010 13:24:33 GMT


Sponsored Links
 I am trying to pass an array from Java to JavaScript by converting the
array into a string with the help of delimiter and later splitting in
JavaScript with the split function in JavaScript. Now the problem
arrives if I display String in the form of alert the String is coming
in the JavaScript and is displaying the right output which I want but
the split function doesn't work here for unknown reason but the same
function works if I give the String for same name with the same type
of values defined in the code. The problem is in JavaScript for sure
as the string I am fetching from is being displayed in alert. Please
suggest something, I worked on the problem on emulator only.


This is the function in JavaScript
                function load()
                {
                //var stringFromJava =  
"Nishant|Amit|Ankit|Ashok|Working|Ishaan|
Hallelujah|Floor|Haroon|Fish|Wasim|";
                var stringFromJava = window.cname;
                var names = stringFromJava.split("|");
                sortnames(names);

                }

--



Re: Problem in providing a string to the JavaScript

by Brad Gies » Sat, 20 Nov 2010 01:24:50 GMT


 I don't really fully understand what problem you are having.... Can you 
show an example of what's it's doing... and what you want it to do?


The code you sent looks fine... except that the last string after you 
split the string will be an empty string because you have a "|" at the 
end of the string.


Are you sure "window.cname" is passing what you think it is? Have you 
debugged it and checked to see exactly what you are getting?


Sincerely,

Brad Gies
-----------------------------------------------------------------------
Bistro Bot - Bistro Blurb
 http://bgies.com              http://nocrappyapps.com 
 http://bistroblurb.com        http://forcethetruth.com 
 http://ihottonight.com 
-----------------------------------------------------------------------
Everything in moderation, including abstinence (paraphrased)

Every person is born with a brain... Those who use it well are the successful 
happy ones - Brad Gies

Adversity can make or break you... It's your choice... Choose wisely - Brad Gies

Never doubt that a small group of thoughtful, committed people can
change the world. Indeed. It is the only thing that ever has - Margaret Mead




I am trying to pass an array from Java to JavaScript by converting the array into a string with the help of delimiter and later splitting in JavaScript with the split function in JavaScript. Now the problem arrives if I display String in the form of alert the String is coming in the JavaScript and is displaying the right output which I want but the split function doesn't work here for unknown reason but the same function works if I give the String for same name with the same type of values defined in the code. The problem is in JavaScript for sure as the string I am fetching from is being displayed in alert. Please suggest something, I worked on the problem on emulator only. This is the function in JavaScript function load() { //var stringFromJava = "Nishant|Amit|Ankit|Ashok|Working|Ishaan| Hallelujah|Floor|Haroon|Fish|Wasim|"; var stringFromJava = window.cname; var names = stringFromJava.split("|"); sortnames(names); }
--


Sponsored Links


Re: Problem in providing a string to the JavaScript

by Frank Weiss » Sat, 20 Nov 2010 11:37:01 GMT


 This sounds a bit like the problem of trying to match "|" in a regular
expression (regex). But I can't really tell that the split method is
thinking that its parameter is a regex instead of simple a string. Try "\\|"
and see if that fixes it.

-- 



Re: Problem in providing a string to the JavaScript

by nubh bhargava » Mon, 22 Nov 2010 13:12:53 GMT


 Ya, that's what really makes me worry. I get the string as output when I
provide an alert and when I pass the string which I have commented in the
above code a specific function the code works fine. Just don't understand
the problem why its not showing the output when I pass the string from Java.
For a reason I thought it would be that the string is not coming but strange
thing happened when I display it as alert. The string is coming the way I
want. But its not going in the split command. Tried few cases in which I can
get the output but all in vain. Can you suggest any other way to pass the
array into JavaScript. If there please let me know the code. So I can
improve in this example.

Thanks in Advance and for the kind help and support.
Nishant Bhargava

-- 



Re: Problem in providing a string to the JavaScript

by nubh bhargava » Mon, 22 Nov 2010 14:42:56 GMT


 Guys, I am able to do it. By converting the value to String which I am
fetching from Java. The value was coming in the alert which was strange
earlier.

Thanks for helping anyway.

Nishant

-- 



Other Threads

1. Google G1 for developers Shipping cost $170!? is this a joke?

Hello

I was trying to purchase the G1 unlocked for developers this morning
for $399 and when i got to the shipping charge it said $170+ which i
think to the UK is outrageous! Is this a misprint or is it really that
stupid a price!?

Please help as this is stopping me getting the unlocked G1.

Regards

Sparklehedgehog

--~--~---------~--~----~------------~-------~--~----~

2. IOException in HttpClient: unknown error while trying to access run simple MAP application

Hi
I am trying to run a simple MAP application.The source code is as
below:

package test.test;

import android.os.Bundle;
import android.view.KeyEvent;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

public class testapp extends MapActivity
{
    private MapView myMapView;

    @Override
    protected boolean isRouteDisplayed()
    {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        myMapView = new MapView(this, "");

        // Lets start at the Statue of Liberty
        // I grabbed the data from Google-Maps
        GeoPoint p = new GeoPoint((int) (40.689213 * 1000000), (int)
(-74.044558 * 1000000));
        // Get the controller, that is used for translation and
zooming
        MapController mc = myMapView.getController();
        // Translate to the Statue of Liberty
        mc.animateTo(p);
        // Zoom Very close
        // mc..zoomTo(21);
        // Make myMapView the exilicit view of this app
        setContentView(myMapView);
        // Enable Sattelite-Mode, so we will se the
        // Statue of liberty instantly on the screen
        myMapView.setSatellite(true);
    }

    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if (keyCode == KeyEvent.KEYCODE_I)
        {
            // Zooming In
            // myMapView.getController().zoomTo(myMapView.getZoomLevel
() + 1);
            return true;
        }
        else
            if (keyCode == KeyEvent.KEYCODE_O)
            {
                // Zooming Out
                // myMapView.getController().zoomTo
(myMapView.getZoomLevel() -
                // 1);
                return true;
            }
            else
                if (keyCode == KeyEvent.KEYCODE_S)
                {
                    // Switch to satellite view
                    myMapView.setSatellite(true);
                    return true;
                }
                else
                    if (keyCode == KeyEvent.KEYCODE_T)
                    {
                        // Switch on traffic overlays
                        myMapView.setTraffic(true);
                        return true;
                    }
        return false;
    }

}


The application runs and a blank map screen is displayed.
The logcat output is
E/OSNetworkSystem(15783): unknown socket error -1
W/AndroidHttpConnectionFactory(15783): IOException in HttpClient:
unknown error
D/dalvikvm(   57): GC freed 7089 objects / 342672 bytes in 243ms
E/OSNetworkSystem(15783): unknown socket error -1
W/AndroidHttpConnectionFactory(15783): IOException in HttpClient:
unknown error
E/OSNetworkSystem(15783): unknown socket error -1
W/AndroidHttpConnectionFactory(15783): IOException in HttpClient:
unknown error
E/OSNetworkSystem(15783): unknown socket error -1
W/AndroidHttpConnectionFactory(15783): IOException in HttpClient:
unknown error
E/OSNetworkSystem(15783): unknown socket error -1
W/AndroidHttpConnectionFactory(15783): IOException in HttpClient:
unknown error
E/OSNetworkSystem(15783): unknown socket error -1
W/AndroidHttpConnectionFactory(15783): IOException in HttpClient:
unknown error
E/OSNetworkSystem(15783): unknown socket error -1
W/AndroidHttpConnectionFactory(15783): IOException in HttpClient:
unknown error
E/OSNetworkSystem(15783): unknown socket error -1
W/AndroidHttpConnectionFactory(15783): IOException in HttpClient:
unknown error
E/OSNetworkSystem(15783): unknown socket error -1
W/AndroidHttpConnectionFactory(15783): IOException in HttpClient:
unknown error
E/OSNetworkSystem(15783): unknown socket error -1
W/AndroidHttpConnectionFactory(15783): IOException in HttpClient:
unknown error
D/dalvikvm(15783): GC freed 10468 objects / 533944 bytes in 316ms
E/OSNetworkSystem(15783): unknown socket error -1
W/AndroidHttpConnectionFactory(15783): IOException in HttpClient:
unknown error
E/OSNetworkSystem(15783): unknown socket error -1
W/AndroidHttpConnectionFactory(15783): IOException in HttpClient:
unknown error
E/OSNetworkSystem(15783): unknown socket error -1
W/AndroidHttpConnectionFactory(15783): IOException in HttpClient:
unknown error

.
I am sitting behind a proxy and have already set the proxy in the
settings db.

Kindly provide help and inputs on the issue.

Thanks
Ajit

--~--~---------~--~----~------------~-------~--~----~

3. Can some please create this?

4. SQLite, android_metadata

5. Can we have PACKAGE_ADDED and CHANGED back?

6. Make it easier to add to contacts

7. Street View integration needs some work