Example usage for org.json JSONException getMessage

List of usage examples for org.json JSONException getMessage

Introduction

In this page you can find the example usage for org.json JSONException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.initialxy.cordova.themeablebrowser.InAppChromeClient.java

/**
 * Tell the client to display a prompt dialog to the user.
 * If the client returns true, WebView will assume that the client will
 * handle the prompt dialog and call the appropriate JsPromptResult method.
 *
 * The prompt bridge provided for the ThemeableBrowser is capable of executing any
 * oustanding callback belonging to the ThemeableBrowser plugin. Care has been
 * taken that other callbacks cannot be triggered, and that no other code
 * execution is possible.//from w  ww.  ja  v  a  2s .c om
 *
 * To trigger the bridge, the prompt default value should be of the form:
 *
 * gap-iab://<callbackId>
 *
 * where <callbackId> is the string id of the callback to trigger (something
 * like "ThemeableBrowser0123456789")
 *
 * If present, the prompt message is expected to be a JSON-encoded value to
 * pass to the callback. A JSON_EXCEPTION is returned if the JSON is invalid.
 *
 * @param view
 * @param url
 * @param message
 * @param defaultValue
 * @param result
 */
@Override
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue,
        JsPromptResult result) {
    // See if the prompt string uses the 'gap-iab' protocol. If so, the remainder should be the id of a callback to execute.
    if (defaultValue != null && defaultValue.startsWith("gap")) {
        if (defaultValue.startsWith("gap-iab://")) {
            PluginResult scriptResult;
            String scriptCallbackId = defaultValue.substring(10);
            if (scriptCallbackId.startsWith("ThemeableBrowser")) {
                if (message == null || message.length() == 0) {
                    scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray());
                } else {
                    try {
                        scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray(message));
                    } catch (JSONException e) {
                        scriptResult = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
                    }
                }
                this.webView.sendPluginResult(scriptResult, scriptCallbackId);
                result.confirm("");
                return true;
            }
        } else {
            // Anything else with a gap: prefix should get this message
            LOG.w(LOG_TAG, "ThemeableBrowser does not support Cordova API calls: " + url + " " + defaultValue);
            result.cancel();
            return true;
        }
    }
    return false;
}

From source file:com.commontime.plugin.notification.Notification.java

private void registerForPush(JSONArray data, CallbackContext command) {
    try {/*from  w  w  w .j av a  2s . c om*/
        tmpCommand = command;

        JSONObject jo = data.getJSONObject(0);
        gSenderID = (String) jo.get("senderID");

        GCMRegistrar.register(cordova.getActivity().getApplicationContext(), gSenderID);
        //command.success();
    } catch (JSONException e) {
        command.error(e.getMessage());
    }
}

From source file:com.panchosoft.appspy.models.iTunesProxy.java

public iTunesApp[] buscarApp(String appName, int limit) {
        // Hacemos una bsqueda en iTunes
        String datos_json = buscarDatosAppJSON(appName, 15);

        if (datos_json == null || datos_json.length() == 0) {
            return null;
        }/*from  www .j  ava  2 s.com*/

        try {
            JSONObject ob = new JSONObject(datos_json);

            if (ob == null) {
                return null;
            }

            int totalResultados = ob.getInt("resultCount");
            if (totalResultados == 0) {
                return null;
            }

            iTunesApp[] appsencontradas = new iTunesApp[totalResultados];

            for (int c = 0; c < totalResultados; c++) {
                JSONArray resultados = ob.getJSONArray("results");

                if (resultados == null) {
                    return null;
                }

                JSONObject appdata = resultados.getJSONObject(c);

                if (appdata == null) {
                    return null;
                }

                // Creamos el objeto iTunesApp
                iTunesApp app = new iTunesApp();
                app.setArtistId(appdata.opt("artistId").toString());
                app.setArtistName(appdata.optString("artistName"));
                app.setArtistViewUrl(appdata.optString("artistViewUrl"));
                app.setArtworkUrl100(appdata.optString("artworkUrl100"));
                app.setArtworkUrl60(appdata.optString("artworkUrl60"));
                app.setContentAdvisoryRating(appdata.optString("advisorRating"));
                app.setDescription(appdata.optString("description"));
                app.setFileSizeBytes(appdata.optString("fileSizeBytes"));
                // Generos
                JSONArray generos = appdata.getJSONArray("genreIds");
                String[] generosApp = new String[generos.length()];
                for (int i = 0; i < generos.length(); i++) {
                    generosApp[i] = generos.getString(i);
                }
                app.setGenreIds(generosApp);
                // Generos nombres
                generos = appdata.getJSONArray("genres");
                generosApp = new String[generos.length()];
                for (int i = 0; i < generos.length(); i++) {
                    generosApp[i] = generos.getString(i);
                }
                app.setGenres(generosApp);
                // Lenguajes
                JSONArray lenguajes = appdata.getJSONArray("genres");
                String[] lenguajesApp = new String[lenguajes.length()];
                for (int i = 0; i < lenguajes.length(); i++) {
                    lenguajesApp[i] = lenguajes.getString(i);
                }
                app.setLanguageCodesISO2(lenguajesApp);
                app.setPrice(appdata.optString("price"));
                app.setPrimaryGenreId(appdata.optString("primaryGenreId"));
                app.setPrimaryGenreName(appdata.optString("primaryGenreName"));
                app.setReleaseDate(appdata.optString("releaseDate"));
                // Capturas
                JSONArray capturas = appdata.getJSONArray("screenshotUrls");
                String[] capturasApp = new String[capturas.length()];
                for (int i = 0; i < capturas.length(); i++) {
                    capturasApp[i] = capturas.getString(i);
                }
                app.setScreenshotUrls(capturasApp);
                app.setSellerName(appdata.optString("sellerName"));
                app.setSellerUrl(appdata.optString("sellerUrl"));
                // Dispositivos soportados
                JSONArray dispositivos = appdata.getJSONArray("supportedDevices");
                String[] dispositivosApp = new String[dispositivos.length()];
                for (int i = 0; i < dispositivos.length(); i++) {
                    dispositivosApp[i] = dispositivos.getString(i);
                }
                app.setSupportedDevices(dispositivosApp);
                app.setTrackCensoredName(appdata.optString("trackCensoredName"));
                app.setTrackName(appdata.optString("trackName"));
                app.setTrackViewUrl(appdata.optString("trackViewUrl"));
                app.setVersion(appdata.optString("version"));

                appsencontradas[c] = app;

            }
            return appsencontradas;
        } catch (JSONException ex) {
            Logger.getLogger("com.panchosoft.itunes").log(Level.WARNING, "Error: " + ex.getMessage());
        }

        return null;
    }

From source file:com.panchosoft.appspy.models.iTunesProxy.java

public iTunesApp obtenerAppPorID(String appID) {
        // Hacemos una bsqueda en iTunes
        String datos_json = obtenerDatosAppJSON(appID);

        if (datos_json == null || datos_json.length() == 0) {
            return null;
        }//www  . j  ava  2 s .  c  o m

        try {
            JSONObject ob = new JSONObject(datos_json);

            if (ob == null) {
                return null;
            }

            JSONArray resultados = ob.getJSONArray("results");

            if (resultados == null) {
                return null;
            }

            JSONObject appdata = resultados.getJSONObject(0);

            if (appdata == null) {
                return null;
            }

            // Creamos el objeto iTunesApp
            iTunesApp app = new iTunesApp();
            app.setArtistId(appdata.opt("artistId").toString());
            app.setArtistName(appdata.optString("artistName"));
            app.setArtistViewUrl(appdata.optString("artistViewUrl"));
            app.setArtworkUrl100(appdata.optString("artworkUrl100"));
            app.setArtworkUrl60(appdata.optString("artworkUrl60"));
            app.setContentAdvisoryRating(appdata.optString("advisorRating"));
            app.setDescription(appdata.optString("description"));
            app.setFileSizeBytes(appdata.optString("fileSizeBytes"));
            // Generos
            JSONArray generos = appdata.getJSONArray("genreIds");
            String[] generosApp = new String[generos.length()];
            for (int i = 0; i < generos.length(); i++) {
                generosApp[i] = generos.getString(i);
            }
            app.setGenreIds(generosApp);
            // Generos nombres
            generos = appdata.getJSONArray("genres");
            generosApp = new String[generos.length()];
            for (int i = 0; i < generos.length(); i++) {
                generosApp[i] = generos.getString(i);
            }
            app.setGenres(generosApp);
            // Lenguajes
            JSONArray lenguajes = appdata.getJSONArray("genres");
            String[] lenguajesApp = new String[lenguajes.length()];
            for (int i = 0; i < lenguajes.length(); i++) {
                lenguajesApp[i] = lenguajes.getString(i);
            }
            app.setLanguageCodesISO2(lenguajesApp);
            app.setPrice(appdata.optString("price"));
            app.setPrimaryGenreId(appdata.optString("primaryGenreId"));
            app.setPrimaryGenreName(appdata.optString("primaryGenreName"));
            app.setReleaseDate(appdata.optString("releaseDate"));
            // Capturas
            JSONArray capturas = appdata.getJSONArray("screenshotUrls");
            String[] capturasApp = new String[capturas.length()];
            for (int i = 0; i < capturas.length(); i++) {
                capturasApp[i] = capturas.getString(i);
            }
            app.setScreenshotUrls(capturasApp);
            app.setSellerName(appdata.optString("sellerName"));
            app.setSellerUrl(appdata.optString("sellerUrl"));
            // Dispositivos soportados
            JSONArray dispositivos = appdata.getJSONArray("supportedDevices");
            String[] dispositivosApp = new String[dispositivos.length()];
            for (int i = 0; i < dispositivos.length(); i++) {
                dispositivosApp[i] = dispositivos.getString(i);
            }
            app.setSupportedDevices(dispositivosApp);
            app.setTrackCensoredName(appdata.optString("trackCensoredName"));
            app.setTrackName(appdata.optString("trackName"));
            app.setTrackViewUrl(appdata.optString("trackViewUrl"));
            app.setVersion(appdata.optString("version"));

            return app;
        } catch (JSONException ex) {
            Logger.getLogger("com.panchosoft.itunes").log(Level.WARNING, "Error: " + ex.getMessage());
        }

        return null;
    }

From source file:com.panchosoft.appspy.models.iTunesProxy.java

public iTunesApp obtenerApp(String appName) {

        // Hacemos una bsqueda en iTunes
        String datos_json = buscarDatosAppJSON(appName, 1);

        if (datos_json == null || datos_json.length() == 0) {
            return null;
        }/*from   w w  w .  j  av  a 2s  . c  o m*/

        try {
            JSONObject ob = new JSONObject(datos_json);

            if (ob == null) {
                return null;
            }

            JSONArray resultados = ob.getJSONArray("results");

            if (resultados == null) {
                return null;
            }

            JSONObject appdata = resultados.getJSONObject(0);

            if (appdata == null) {
                return null;
            }

            // Creamos el objeto iTunesApp
            iTunesApp app = new iTunesApp();
            app.setArtistId(appdata.opt("artistId").toString());
            app.setArtistName(appdata.optString("artistName"));
            app.setArtistViewUrl(appdata.optString("artistViewUrl"));
            app.setArtworkUrl100(appdata.optString("artworkUrl100"));
            app.setArtworkUrl60(appdata.optString("artworkUrl60"));
            app.setContentAdvisoryRating(appdata.optString("advisorRating"));
            app.setDescription(appdata.optString("description"));
            app.setFileSizeBytes(appdata.optString("fileSizeBytes"));
            // Generos
            JSONArray generos = appdata.getJSONArray("genreIds");
            String[] generosApp = new String[generos.length()];
            for (int i = 0; i < generos.length(); i++) {
                generosApp[i] = generos.getString(i);
            }
            app.setGenreIds(generosApp);
            // Generos nombres
            generos = appdata.getJSONArray("genres");
            generosApp = new String[generos.length()];
            for (int i = 0; i < generos.length(); i++) {
                generosApp[i] = generos.getString(i);
            }
            app.setGenres(generosApp);
            // Lenguajes
            JSONArray lenguajes = appdata.getJSONArray("genres");
            String[] lenguajesApp = new String[lenguajes.length()];
            for (int i = 0; i < lenguajes.length(); i++) {
                lenguajesApp[i] = lenguajes.getString(i);
            }
            app.setLanguageCodesISO2(lenguajesApp);
            app.setPrice(appdata.optString("price"));
            app.setPrimaryGenreId(appdata.optString("primaryGenreId"));
            app.setPrimaryGenreName(appdata.optString("primaryGenreName"));
            app.setReleaseDate(appdata.optString("releaseDate"));
            // Capturas
            JSONArray capturas = appdata.getJSONArray("screenshotUrls");
            String[] capturasApp = new String[capturas.length()];
            for (int i = 0; i < capturas.length(); i++) {
                capturasApp[i] = capturas.getString(i);
            }
            app.setScreenshotUrls(capturasApp);
            app.setSellerName(appdata.optString("sellerName"));
            app.setSellerUrl(appdata.optString("sellerUrl"));
            // Dispositivos soportados
            JSONArray dispositivos = appdata.getJSONArray("supportedDevices");
            String[] dispositivosApp = new String[dispositivos.length()];
            for (int i = 0; i < dispositivos.length(); i++) {
                dispositivosApp[i] = dispositivos.getString(i);
            }
            app.setSupportedDevices(dispositivosApp);
            app.setTrackCensoredName(appdata.optString("trackCensoredName"));
            app.setTrackName(appdata.optString("trackName"));
            app.setTrackViewUrl(appdata.optString("trackViewUrl"));
            app.setVersion(appdata.optString("version"));

            return app;
        } catch (JSONException ex) {
            Logger.getLogger("com.panchosoft.itunes").log(Level.WARNING, "Error: " + ex.getMessage());
        }

        return null;
    }

From source file:org.jabsorb.ng.serializer.impl.ReferenceSerializer.java

@Override
public Object marshall(final SerializerState state, final Object p, final Object o) throws MarshallException {

    final Class<?> clazz = o.getClass();
    final Integer identity = new Integer(System.identityHashCode(o));
    if (bridge.isReference(clazz)) {
        if (log.isDebugEnabled()) {
            log.debug("marshall",
                    "marshalling reference to object " + identity + " of class " + clazz.getName());
        }//from w  w  w .  java2 s  .  com
        bridge.addReference(o);
        final JSONObject jso = new JSONObject();
        try {
            jso.put("JSONRPCType", "Reference");
            jso.put("javaClass", clazz.getName());
            jso.put("objectID", identity);
        } catch (final JSONException e) {
            throw new MarshallException(e.getMessage(), e);
        }
        return jso;
    } else if (bridge.isCallableReference(clazz)) {
        if (log.isDebugEnabled()) {
            log.debug("marshall",
                    "marshalling callable reference to object " + identity + " of class " + clazz.getName());
        }
        bridge.registerObject(identity, o);
        bridge.addReference(o);

        final JSONObject jso = new JSONObject();
        try {
            jso.put("JSONRPCType", "CallableReference");
            jso.put("javaClass", clazz.getName());
            jso.put("objectID", identity);
        } catch (final JSONException e) {
            throw new MarshallException(e.getMessage(), e);
        }

        return jso;
    }
    return null;
}

From source file:org.jabsorb.ng.serializer.impl.ReferenceSerializer.java

@Override
public Object unmarshall(final SerializerState state, final Class<?> clazz, final Object o)
        throws UnmarshallException {

    final JSONObject jso = (JSONObject) o;
    Object ref = null;//w  ww  .j a  va2 s .  co m
    String json_type;
    int object_id;
    try {
        json_type = jso.getString("JSONRPCType");
        object_id = jso.getInt("objectID");
    } catch (final JSONException e) {
        throw new UnmarshallException(e.getMessage(), e);
    }
    if (json_type != null) {
        if ((json_type.equals("Reference")) || (json_type.equals("CallableReference"))) {
            ref = bridge.getReference(object_id);
        }
    }
    state.setSerialized(o, ref);
    return ref;
}

From source file:com.dedipower.portal.android.CDNLanding.java

public void onCreate(Bundle savedInstanceState) {
    API.SessionID = getIntent().getStringExtra("sessionid");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cdnlanding);

    //Progress test
    list = (ListView) findViewById(R.id.CDNList);
    final ProgressDialog dialog = ProgressDialog.show(this, "DediPortal", "Please wait: loading data....",
            true);/*from ww w .ja  v  a 2 s  .c  om*/
    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();
            if (Success.equals("true")) {
                UpdateErrorMessage(ErrorMessage);
                CDNAdaptor adapter = new CDNAdaptor(CDNLanding.this, listOfCDNs);
                list.setAdapter(adapter);
            } else {
                UpdateErrorMessage(ErrorMessage);
            }
        }
    };

    Thread dataPreload = new Thread() {
        public void run() {
            try {
                CDNs = API.PortalQuery("cdn", "none");
                Success = CDNs.getString("success");
            } catch (JSONException e) {
                ErrorMessage = "An unrecoverable JSON Exception occured.";
                //UpdateErrorMessage("An unrecoverable JSON Exception occured.");
            }

            if (Success.equals("false")) {
                try {
                    //UpdateErrorMessage(CDNs.getString("msg"));
                    ErrorMessage = CDNs.getString("msg");
                } catch (JSONException e) {
                    //UpdateErrorMessage("A JSON parsing error prevented an exact error message to be determined.");
                    ErrorMessage = "A JSON parsing error prevented an exact error message to be determined.";
                }
            } else {
                try {
                    CDNNodes = CDNs.getJSONArray("cdns");
                    //UpdateErrorMessage("");
                    ErrorMessage = "";
                } catch (JSONException e) {
                    //UpdateErrorMessage("There are no CDN nodes in your account.");
                    ErrorMessage = "There are no CDN nodes in your account.";
                }
                int CDNCount = CDNNodes.length();

                if (CDNCount == 0) {
                    //UpdateErrorMessage("There are no CDN nodes for your account.");
                    ErrorMessage = "There are no CDN nodes for your account.";
                    Success = "false";
                    handler.sendEmptyMessage(0);
                }

                for (int i = 0; i < CDNCount; i++) {
                    try {
                        CurrentCDN = CDNNodes.getJSONObject(i);
                    } catch (JSONException e1) {
                        Log.e("APIFuncs", e1.getMessage());
                    }

                    listOfCDNs.add(new CDN(GetString("name"), GetString("backend"), GetInt("bandwidthemea"),
                            GetInt("bandwidthapac"), GetInt("bandwidthamericas"), GetBool("loadbalanced")));
                }
            }
            handler.sendEmptyMessage(0);
        }
    };

    dataPreload.start();
    //Progress test

    /*try 
    {
       CDNs = API.PortalQuery("cdn", "none");
      Success = CDNs.getString("success");   
    } 
    catch (JSONException e) 
    {
       UpdateErrorMessage("An unrecoverable JSON Exception occured.");
       //Toast.makeText(ColoLanding.this, "An unrecoverable JSON Exception occured.", Toast.LENGTH_LONG).show();
    }
            
    if(Success == "false")
    {
       try 
       {
    UpdateErrorMessage(CDNs.getString("msg"));
      } 
       catch (JSONException e) 
       {
     UpdateErrorMessage("A JSON parsing error prevented an exact error message to be determined.");
      }
    }
    else
    {
       Log.i("APIFuncs",CDNs.toString());
       try
        {
     CDNNodes = CDNs.getJSONArray("cdns");
      UpdateErrorMessage("");
        }
        catch (JSONException e) 
        {
      UpdateErrorMessage("There are no CDN nodes in your account.");
        }
                
        //OK lets actually do something useful
        ListView list = (ListView)findViewById(R.id.CDNList);
        List<CDN> listOfCDNs = new ArrayList<CDN>();
        int CDNCount = CDNNodes.length();
                
        if(CDNCount == 0)
        {
      UpdateErrorMessage("There are no CDN nodes for your account.");
      return;
        }
                
        for(int i = 0; i < CDNCount; i++)
        {
    try 
    {
       CurrentCDN = CDNNodes.getJSONObject(i);
    } 
    catch (JSONException e1) 
    {
       Log.e("APIFuncs",e1.getMessage());
    }
            
         listOfCDNs.add(new CDN(GetString("name"),
               GetString("backend"),
               GetInt("bandwidthemea"),
               GetInt("bandwidthapac"),
               GetInt("bandwidthamericas"),
               GetBool("loadbalanced")));
        }
            
        CDNAdaptor adapter = new CDNAdaptor(this, listOfCDNs);
                
        list.setAdapter(adapter);
    }*/
}

From source file:com.mobeelizer.java.definition.type.helpers.MobeelizerFileFieldTypeHelper.java

@Override
public String convertFromEntityValueToJsonValue(final MobeelizerFieldAccessor field, final Object value,
        final Map<String, String> options, final MobeelizerErrorsBuilder errors) {
    MobeelizerFile file = (MobeelizerFile) value;

    if (!validateValue(field, file, options, errors)) {
        return null;
    }/*from   w ww.  j a v  a  2  s  . com*/

    JSONObject json = new JSONObject();
    try {
        json.put("guid", file.getGuid());
        json.put("filename", file.getName());
    } catch (JSONException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }

    return json.toString();
}

From source file:com.aegiswallet.objects.SMSTransactionPojo.java

public SMSTransactionPojo(String base64EncodedJSONString) {
    byte[] decoded = Base64.decode(base64EncodedJSONString.getBytes(), Base64.NO_WRAP);
    String jsonString = new String(decoded);

    try {//from   w  ww  .java 2s. c  o  m
        JSONObject object = new JSONObject(jsonString);

        this.phoneNumber = object.getString("number");
        this.name = object.getString("name");
        this.amount = new BigInteger(object.getString("amount"));
        this.btcAddress = object.getString("address");
        this.timestamp = new Long(object.getString("timestamp")).longValue();
        this.status = new Integer(object.getString("status")).intValue();
        this.tag = object.getString("tag");

    } catch (JSONException e) {
        Log.d(TAG, e.getMessage());
    }
}