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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:16:41+00:00 2026-05-27T11:16:41+00:00

I made a method where all the font’s get changed, but the problem is

  • 0

I made a method where all the font’s get changed, but the problem is that I want to use the method once so I don’t have to copy and paste it in every script.

Code example:

public void changeFont(){

    int[] id_et = {R.id.inputObjectName, R.id.inputObjectValue};
    int[] id_tv = {R.id.headerUserInfo, R.id.headerUserPW, R.id.headerUserGW};
    int[] id_btn = {R.id.privBtnIncome, R.id.privBtnExpense};

    Typeface font = Typeface.createFromAsset(getAssets(), "Sanford.TTF");

    for(int i = 0; i < id_et.length; i++){
        EditText textbox = (EditText) findViewById(id_et[i]);
        textbox.setTypeface(font);
    }

    for(int i = 0; i < id_tv.length; i++){
        TextView tv = (TextView) findViewById(id_tv[i]);
        tv.setTypeface(font);
    }

    for(int i = 0; i < id_btn.length; i++){
        Button btn = (Button) findViewById(id_btn[i]);
        btn.setTypeface(font);
    }

}

When I create a class and make an object to use the constructor to get the data, the program crashes.

This is how the class looks:

public class ChangeFont extends Activity{
    public ChangeFont(){

    int[] id_et = {R.id.inputObjectName, R.id.inputObjectValue};
    int[] id_tv = {R.id.headerUserInfo, R.id.headerUserPW, R.id.headerUserGW};
    int[] id_btn = {R.id.privBtnIncome, R.id.privBtnExpense};

    Typeface font = Typeface.createFromAsset(getAssets(), "Sanford.TTF");

    for(int i = 0; i < id_et.length; i++){
        EditText textbox = (EditText) findViewById(id_et[i]);
        textbox.setTypeface(font);
    }

    for(int i = 0; i < id_tv.length; i++){
        TextView tv = (TextView) findViewById(id_tv[i]);
        tv.setTypeface(font);
    }

    for(int i = 0; i < id_btn.length; i++){
        Button btn = (Button) findViewById(id_btn[i]);
        btn.setTypeface(font);
    }

    }

}

Error log:

12-12 17:23:49.746: E/AndroidRuntime(6159): FATAL EXCEPTION: main
12-12 17:23:49.746: E/AndroidRuntime(6159): java.lang.RuntimeException: Unable to start activity ComponentInfo{united.aristal.freewallet/united.aristal.freewallet.PrivateWallet}: java.lang.NullPointerException
12-12 17:23:49.746: E/AndroidRuntime(6159):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
12-12 17:23:49.746: E/AndroidRuntime(6159):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
12-12 17:23:49.746: E/AndroidRuntime(6159):     at android.app.ActivityThread.access$600(ActivityThread.java:122)
12-12 17:23:49.746: E/AndroidRuntime(6159):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
12-12 17:23:49.746: E/AndroidRuntime(6159):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-12 17:23:49.746: E/AndroidRuntime(6159):     at android.os.Looper.loop(Looper.java:137)
12-12 17:23:49.746: E/AndroidRuntime(6159):     at android.app.ActivityThread.main(ActivityThread.java:4340)
12-12 17:23:49.746: E/AndroidRuntime(6159):     at java.lang.reflect.Method.invokeNative(Native Method)
12-12 17:23:49.746: E/AndroidRuntime(6159):     at java.lang.reflect.Method.invoke(Method.java:511)
12-12 17:23:49.746: E/AndroidRuntime(6159):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-12 17:23:49.746: E/AndroidRuntime(6159):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-12 17:23:49.746: E/AndroidRuntime(6159):     at dalvik.system.NativeStart.main(Native Method)
12-12 17:23:49.746: E/AndroidRuntime(6159): Caused by: java.lang.NullPointerException
12-12 17:23:49.746: E/AndroidRuntime(6159):     at android.content.ContextWrapper.getAssets(ContextWrapper.java:75)
12-12 17:23:49.746: E/AndroidRuntime(6159):     at united.aristal.freewallet.ChangeFont.<init>(ChangeFont.java:16)
12-12 17:23:49.746: E/AndroidRuntime(6159):     at united.aristal.freewallet.PrivateWallet.onCreate(PrivateWallet.java:32)
12-12 17:23:49.746: E/AndroidRuntime(6159):     at android.app.Activity.performCreate(Activity.java:4465)
12-12 17:23:49.746: E/AndroidRuntime(6159):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
12-12 17:23:49.746: E/AndroidRuntime(6159):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
12-12 17:23:49.746: E/AndroidRuntime(6159):     ... 11 more

So can anyone help me here?

  • 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-27T11:16:42+00:00Added an answer on May 27, 2026 at 11:16 am

    getAssets is throwing NullPointerException because you created the ChangeFont instance instead of letting Android do it. If ChangeFont is just a utility class, it should not extend Activity.

    Instead, initialize it with an instance of your actual activity, and let it call methods on that activity.

    public class ChangeFont {
    
        public ChangeFont(final Activity activity) {
            this.activity = activity;
    
            Typeface font = Typeface.createFromAsset(activity.getAssets(), "Sanford.TTF");
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to find all the method calls in one class which are made
I am just learning how to use ScriptingBridges. I made a method that slowly
i have a problem with the kohana pagination. i have made a method for
i want to mark a method as obsolete, but Delphi 5 doesn't have such
I've made a very simple REST controller method with Spring 3.0.0.RC1 that uses hibernate
I'm trying to use an Objective-C class made in Python to do this but
I've made an anagram method to create all the possible combinations of a word,
I have searched a bit but all the answers on the exception is related
I have a problem that I would like to tell you because is about
I have a base method that I'm writing in order to not repeat the

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.