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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:02:08+00:00 2026-05-24T17:02:08+00:00

I have the following setup: LibProjectWithActivity – an android library project which contains PreviewActivity

  • 0

I have the following setup:

  • LibProjectWithActivity – an android library project which contains PreviewActivity
  • AppProject – usual Android Project which uses LibProjectWithActivity
  • AppProjectTest – an Android JUnit Test Project which is an ActivityInstumentationTestCase2

First of all: all basic dependencies are set up correctly, because I can perfectly launch my app in emulator, it shows PreviewActivity just ok, things work – no problems here.

But I fail to launch the test… Here’s the setup:

public class PreviewActivityTest 
      extends ActivityInstrumentationTestCase2<PreviewActivity> {
    public PreviewActivityTest() {
        // note: if i put "com.the7art.libprojectwithactivity" instead it wont find it
        // and will fail with "activity not found"
        super("com.the7art.appproject", PreviewActivity.class);
    }

    public void testDummy() {
        getActivity();
    }
}

This throws a NullPointerException like this:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.the7art.appproject/com.the7art.libprojectwithactivity.PreviewActivity}: java.lang.NullPointerException
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
    .......
Caused by: java.lang.NullPointerException
    at com.the7art.libprojectwithactivity.PreviewActivity.onCreate(PreviewActivity.java:37)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
    ... 11 more

Here are lines PreviewActivity.java:36,37:

mButtonAdd = (Button) findViewById(R.id.button_add);
mButtonAdd.setOnClickListener(this);

So what this exception means is that R.id.button_add (which is in a libproject) is perfectly found, but the view by this id can’t be found. If I comment out this code, it’ll crash similarly when trying to obtain another resource.

Looks like test uses right R.java, but wrong Context object. Or something like this.

Again, the app code is ok, because it works in emulator, something is wrong with test setup…

Any hints on what is wrong and how to fix this?

  • 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-24T17:02:09+00:00Added an answer on May 24, 2026 at 5:02 pm

    Yes the test can be only use the Activity project as a target, look at the projectTarget in your Test manifest file.
    This means that your test can use the same context as your application does. Accessing only the application’s project resources. However, you can’t access Library’s project resources, you can use the R.string.XX from the library’s project because this was first built it, and it’s only a generated identifier that will be used in the application’s context to find the resource. So the result will be an mistake in the resource found or a resource not found exception.
    There are 2 ways to test a library project, here they are

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

Sidebar

Related Questions

I have the following setup: ASP.net 3.5 Web Site Project C# Class Library with
I have following setup in cloud9 IDE. Project root folder Hello.html - contains simple
I have the following setup: eclipse a standard Java project (A) an eclipse plugin
I have the following setup: Main assembly that contains a WcfService and IWcfService contract.
I have the following setup: Project A Project B depends on A Each project
I have the following Setup: One service called CoreHost should receive a ExecuteWorkflowByAttributeCommand which
I have the following setup in my project: com.foo - Main com.foo.util - StringUtil
I have the following setup (which works fine). Using CodeFirst (CTP4). A template has
I have following setup, but when I put 1024 and replace all 512 with
I have the following setup: Code on my local machine (OS X) shared as

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.