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

  • Home
  • SEARCH
  • 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 7993525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:52:26+00:00 2026-06-04T13:52:26+00:00

When i try to create a textview and link it to a XML component

  • 0

When i try to create a textview and link it to a XML component in my application my app seems to crash. the code i am using is:

public class WorkoutAdvice extends Activity {
TextView adviceshow;
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    String[] advice = getResources().getStringArray(R.array.races_array);
    Random rand = new Random(); 
    int ad = rand.nextInt(5);
    String gen = advice[ad];
    adviceshow = (TextView)findViewById(R.id.advice);
    adviceshow.setText(gen);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.advice);       

}
}

and the logcat for when my application closes is

05-26 01:43:23.018: E/AndroidRuntime(363): FATAL EXCEPTION: main
05-26 01:43:23.018: E/AndroidRuntime(363): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.b00348312.workout/com.b00348312.workout.WorkoutAdvice}: java.lang.NullPointerException
05-26 01:43:23.018: E/AndroidRuntime(363): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-26 01:43:23.018: E/AndroidRuntime(363): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-26 01:43:23.018: E/AndroidRuntime(363): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-26 01:43:23.018: E/AndroidRuntime(363): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-26 01:43:23.018: E/AndroidRuntime(363): at android.os.Handler.dispatchMessage(Handler.java:99)
05-26 01:43:23.018: E/AndroidRuntime(363): at android.os.Looper.loop(Looper.java:123)
05-26 01:43:23.018: E/AndroidRuntime(363): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-26 01:43:23.018: E/AndroidRuntime(363): at java.lang.reflect.Method.invokeNative(Native Method)
05-26 01:43:23.018: E/AndroidRuntime(363): at java.lang.reflect.Method.invoke(Method.java:521)
05-26 01:43:23.018: E/AndroidRuntime(363): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-26 01:43:23.018: E/AndroidRuntime(363): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-26 01:43:23.018: E/AndroidRuntime(363): at dalvik.system.NativeStart.main(Native Method)
05-26 01:43:23.018: E/AndroidRuntime(363): Caused by: java.lang.NullPointerException
05-26 01:43:23.018: E/AndroidRuntime(363): at com.b00348312.workout.WorkoutAdvice.onCreate(WorkoutAdvice.java:22)
05-26 01:43:23.018: E/AndroidRuntime(363): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-26 01:43:23.018: E/AndroidRuntime(363): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-26 01:43:23.018: E/AndroidRuntime(363): … 11 more

the application works without the statements dealing with the findbyID lines which work in other parts of the application

  • 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-06-04T13:52:27+00:00Added an answer on June 4, 2026 at 1:52 pm

    Until you actually set your activity content by calling setContentView, there are no views to be found. Once you have called setContentView, then you may try to find your TextView. Note that before this call, the Activity has no knowledge at all of which(s) XML layouts will it be binded to (if any).

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

Sidebar

Related Questions

I try to create a very simple app using windows API. I've done some
I try to create a multi-threaded singleton pattern class. Header: class HL{ public: static
I try to create listView dynamically from code with: @Override public View getView(int position,
I try to create a from application, in the app I have a lengthy
I try to create 2 buttons inside my app case WM_CREATE:{ hWnd =CreateWindowEx(NULL, LBUTTON,
I try to create some li elements in my XUL Application. Theres only the
Hi have a problem with singleton Class in iPhone app. I have create a
In Android in litemitemclick I am using this piece of code: TextView tvofpostedText =
I'm trying to create a TabActivity for my android application. When my layout XML
I want to create a custom View which contains two buttons without using xml.

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.