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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:29:44+00:00 2026-05-26T16:29:44+00:00

The scenario is the following: I have an activity RunTrainingWorkoutsView that uses XML layout

  • 0

The scenario is the following:

I have an activity RunTrainingWorkoutsView that uses XML layout _run_workout.xml_ with some labels that are updated by CountDownTimer. Works fine…

Now, apart from labels that are updated every sec by onTick() callback method of CountDownTimer object I want to add a custom surface view to my _run_workout.xml layout_ that would draw some arcs updated by the same onTick() method every second…

my run_workout.xml:

<training.timer.CounterClockView 
    android:id="@+id/counter_clock_surface"
    android:layout_width="300dp" 
    android:layout_height="240dp">
</training.timer.CounterClockView>

My custom View extends surfaceView

public class CounterClockView extends SurfaceView {

Paint paint = new Paint();
Paint paint2 = new Paint();

final RectF rect = new RectF();
final RectF rect2 = new RectF();

int counterArcAngle = 15;
//constructor
public CounterClockView(Context context, AttributeSet attributeSet) {
    super(context);

    //setting some paint properties...

    this.setBackgroundColor(Color.TRANSPARENT);

}

@Override
public void onDraw(Canvas canvas) {

    rect.set(50, 50, 150, 150);
    rect2.set(50, 50, 150, 150);

    this.layout(0, 0, 200, 200);

    canvas.drawArc(rect, -90, 360, false, paint);
    canvas.drawArc(rect2, -90, counterArcAngle, false, paint2);

}

My main class that extends activity is getting the reference to a custom surfaceView in the layout with the following code:

//counterClockView  is declared outside of onCreate() as CounterClockView counterClockView;  

//later in onCreate(){....
counterClockView  = (CounterClockView) findViewById(R.id.counter_clock_surface);

The problem is changing the value of member variables of customView object (counterClockView)

counterClockView.counterArcAngle = 10;

will crash the app…

Also, from my main activity I would like to call invalidate() method to redo the surface view after changing the counterArcAngle value, but this causes app to crash too…

Why can’t create counterClockView object and reference it to a xml layout element of the same type and the change its appereance, invalidate it etc. ?

EDIT LogCat:

threadid=1: thread exiting with uncaught exception (group=0x40015560)

ERROR/AndroidRuntime(487): FATAL EXCEPTION: main

ERROR/AndroidRuntime(487): java.lang.RuntimeException: Unable to start activity ComponentInfo{training.timer/training.timer.RunTrainingWorkoutsView}: java.lang.NullPointerException

ERROR/AndroidRuntime(487):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
ERROR/AndroidRuntime(487):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
ERROR/AndroidRuntime(487):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
ERROR/AndroidRuntime(487):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
ERROR/AndroidRuntime(487):     at android.os.Handler.dispatchMessage(Handler.java:99)
ERROR/AndroidRuntime(487):     at android.os.Looper.loop(Looper.java:123)

ERROR/AndroidRuntime(487):     at android.app.ActivityThread.main(ActivityThread.java:3683)
ERROR/AndroidRuntime(487):     at java.lang.reflect.Method.invokeNative(Native Method)
ERROR/AndroidRuntime(487):     at java.lang.reflect.Method.invoke(Method.java:507)
ERROR/AndroidRuntime(487):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
ERROR/AndroidRuntime(487):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
ERROR/AndroidRuntime(487):     at dalvik.system.NativeStart.main(Native Method)
ERROR/AndroidRuntime(487): Caused by: java.lang.NullPointerException
ERROR/AndroidRuntime(487):     at training.timer.RunTrainingWorkoutsView.onCreate(RunTrainingWorkoutsView.java:72)
ERROR/AndroidRuntime(487):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
ERROR/AndroidRuntime(487):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
ERROR/AndroidRuntime(487):     ... 11 more
  • 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-26T16:29:44+00:00Added an answer on May 26, 2026 at 4:29 pm

    I got it after 3 days of banging my head against the wall and by googling, stacOverflowing etc.

    Actually, it was this stupid little thing…

    My XML file where I defined the layout containing some usual android views (textView and buttons namely) and my custom view CounterClockView I had:

    <training.timer.CounterClockView 
    android:id="@+id/counter_clock_surface"
    android:layout_width="300dp" 
    android:layout_height="240dp">
    

    where I had to have added one more line!

    <training.timer.CounterClockView 
        xmlns:android="http://schemas.android.com/apk/res/android"   !!!
        android:id="@+id/counter_clock_surface"
        android:layout_width="300dp" 
        android:layout_height="240dp">
    </training.timer.CounterClockView>
    

    I have no idea why this namespace line made such a huge difference, but it works great!

    Now, I can update my custom view from my main activity on every onTick() of CountDownTimer()…

    The following answer was very helpful:
    findViewById() returns null for custom component in layout XML, not for other components

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

Sidebar

Related Questions

I have the following scenario (note that activity A has launchMode=singleTop ): Activity A
Consider following scenario: I have RESTful URL /articles that returns list of articles user
Following Scenario: I have a = UIViewController A that contains a UIScrollView I have
I have the following scenario that may warrant storing data in a conroller member
I have following scenario. Some people use approach 1 and some use approach 2.
I have the following scenario: a Bitmap that is used as background and another
I have following scenario: I have a XML-Document, e.g. like this <someRootElement> <tag1> <tag2
I have the following scenario: A user shelves some changes. Time goes by and
I have the following scenario: I have a chat activity, in it's intent it
The scenario is the following: I have a java package ( myapp.config ) that

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.