Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7049109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:58:22+00:00 2026-05-28T02:58:22+00:00

I develop an app using PhoneGap. I got a service which is in background

  • 0

I develop an app using PhoneGap. I got a service which is in background and is coded natively (the service and the phone gap app is in the same project). Unfortunatly, I want to call a javascript function from this service. So I searched on the Web and founded something interesting : create a class extending Plugin and do some treatment in it. Then I found this :

this.ctx.sendJavascript("myJavascriptFunction");

I tested with this code, but something wrong happened :

java.lang.NullPointerException

Here is how I tested :

class c = new class();
c.execute("myFunction",null,null);

In the class c, the execute method is like this :

public PluginResult execute(String action, JSONArray args, String callbackId) {
if (action.equals("myFunction")){
    Log.d(TAG,"start actions to do");
    this.ctx.sendJavascript("nameOfFunctionToLaunch");
    Log.d(TAG,"end actions to do");
    return new PluginResult(PluginResult.Status.OK);
}
}

When the app start, I have the first

Log.d(TAG,"start actions to do");

How can I solve this problem ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:58:23+00:00Added an answer on May 28, 2026 at 2:58 am

    Finally I found the solution : in fact the NullPointerException was on ctx.
    To fix it, I setup the Context value of my object c like this :

    c.setContext(use_An_Object_Of_Type_PhonegapActivity);
    

    To get the object, I grab it from the AppActivity in this method :

    public class CloudPhoneAppActivity extends DroidGap {
    private class NoScaleWebViewClient extends GapViewClient {
    
        public NoScaleWebViewClient(DroidGap ctx) {
            super(ctx);
            myApp.ctx = ctx;
        }
    
        public void onScaleChanged(WebView view, float oldScale, float newScale) {
            Log.d("NoScaleWebViewClient", "Scale changed: " + String.valueOf(oldScale) + " => " + String.valueOf(newScale));
        }
    }
    /** other stuff after**/ 
    }
    

    So finally here is the solution :

    class c = new class();
    c.setContext(myApp.ctx);
    c.execute("myFunction",null,null);
    

    There is no change to do in the execute method which is describe before. But be careful of how you call the javascript function.

    Erwan

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Phonegap 1.3.0, and want to develop an app which uses local
I am using phonegap and sqlite to develop cross-platform mobile app for android,ios,blackberry.For reference
I am trying to develop a Qt App using 4.7.3 which involves the writing
I'm planning to develop web app using html.(using html tool like phonegap). I want
I am using phonegap to develop one of my iPhone app. In the index.html
I am using .net mvc 3 to develop web app. Currently I got a
I just wanted to develop location based app which is using GPS. So i
I am trying to develop an iPhone app using PhoneGap and jQuery Mobile. This
I'm trying to develop an app using XNA and for state management I'm using
If we develop a winform app using an MVC architecture, it should not be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.