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 7652381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:45:15+00:00 2026-05-31T11:45:15+00:00

java.lang.NullPointerException at com.android.deviceintelligence1.test.Testappdata.testappd(Testappdata.java:29) at java.lang.reflect.Method.invokeNative(Native Method) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)

  • 0
java.lang.NullPointerException
at com.android.deviceintelligence1.test.Testappdata.testappd(Testappdata.java:29)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)

this is error after running my test class.in error log.

public class Testappdata extends ServiceTestCase<MainService> {

    public Testappdata() {
        super(MainService.class);
    }

    protected void setUp() throws Exception {
        try {
            super.setUp();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
    MainService main;

    public void testappd() {
        main = getService();
        String Package = "com.android";
        Assert.assertNotNull(main.appData(Package));

    }

this is my test class.to test service to get data value.

public class MainService extends Service {
private final static String TAG = "Device Intelligence";
double lat = 0.0;
double lng = 0.0;
List<Address> addresses = null;
String addre;
Handler mHandler = new Handler();
String lPackAgeName, packAgeName = "";
public static DataHelper dh;

public String appData(String pName) {
    PackageManager pm = getPackageManager();
    try {

        Method getPackageSizeInfo = pm.getClass().getMethod(
                "getPackageSizeInfo", String.class,
                IPackageStatsObserver.class);
        getPackageSizeInfo.invoke(pm, pName,
                new IPackageStatsObserver.Stub() {
                    public void onGetStatsCompleted(PackageStats pStats,
                            boolean succeeded) throws RemoteException {
                        data_value = String.valueOf(pStats.dataSize / 1024)
                                + "kb";
                        Log.d("bugs", "datavalue: " + data_value);
                    }
                });
    } catch (Exception e) {
        e.printStackTrace();
    }
    return data_value;
}

this is my service class.so how can I clear my error.is ther any changes needed in test class to get out of the error .thanks for help in advance.

  • 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-31T11:45:17+00:00Added an answer on May 31, 2026 at 11:45 am

    I would assume NullPointerException comes from this line:

    ... ...
    
    public void testappd() {
      main = getService(); // <-- Wrong at here, this will not return a testable service
      String Package = "com.android";
      Assert.assertNotNull(main.appData(Package)); // <-- throw NullPointerException
    }
    
    ... ...
    

    The correct way to get a testable service is by calling either startService(Intent) or bindService(Intent) in your ServiceTestCase class, check out the API here:

    The test case waits to call onCreate() until one of your test methods calls startService(Intent) or bindService(Intent). This gives you an opportunity to set up or adjust any additional framework or test logic before you test the running service.

    Assume you have a proper start service properly, you should write you test code something like this:

    startService(new Intent(getContext(), MainService.class));
    main = getService();
    ... ...
    

    Hope this helps.

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

Sidebar

Related Questions

[2011-02-18 23:41:16 - ddms]null java.lang.NullPointerException at com.android.ddmlib.Client.sendAndConsume(Client.java:571) at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142) at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65) at com.android.ddmlib.Client.getJdwpPacket(Client.java:670) at
During navigation of the java.lang.reflect.Method class I came across the method isBridge . Its
15 reports java.lang.RuntimeException: Unable to start activity ComponentInfo{com.oas.fruitkungfufree/com.openfeint.internal.ui.IntroFlow}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) at
I've received a crash report with the following log content: java.lang.NullPointerException at android.webkit.PluginFullScreenHolder.show(PluginFullScreenHolder.java:85) at
Problems with the TabActivity... I get this Exception java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816) at android.app.ActivityThread.startActivityNow(ActivityThread.java:1651) at
What are Null Pointer Exceptions ( java.lang.NullPointerException ) and what causes them? What methods/tools
Exception in thread Thread-0 java.lang.NullPointerException at org.apache.http.impl.nio.reactor.AbstractIOReactor.closeActiveChannels(AbstractIOReactor.java:532) at org.apache.http.impl.nio.reactor.AbstractIOReactor.hardShutdown(AbstractIOReactor.java:564) at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.doShutdown(AbstractMultiworkerIOReactor.java:411) at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:340) at
It doesn't seem to be working right now. I get a java.lang.NullPointerException I have
import java.lang.reflect.Array; public class PrimitiveArrayGeneric { static <T> T[] genericArrayNewInstance(Class<T> componentType) { return (T[])
I got a java.lang.NullPointerException when I try to call createBitmap. Here is my code:

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.