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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:11:51+00:00 2026-06-05T14:11:51+00:00

I am refering to Using MySurfaceView with main.xml (android) , with the code textView1.setText(set);

  • 0

I am refering to Using MySurfaceView with main.xml (android), with the code “textView1.setText(“set”);” inside the onCreate method there will be an error ( tv1 = (TextView)findViewById(R.id.tv1); – declare is working fine). How can I resolve this? Thanks in advance for any help.

public class For12junonly2Activity extends Activity {


TextView tv1;
EditText et1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try
    {
    tv1 = (TextView)findViewById(R.id.tv1);     
    tv1.setText("Hi");
    }catch(Exception e)
    {
        Log.d("prob",String.valueOf(e));
    }
    et1 = (EditText)findViewById(R.id.et1); 
    setContentView(R.layout.main);

    float sss = surf.getX();
    Log.d("float create",String.valueOf(sss));
}

}

 class surf extends SurfaceView implements SurfaceHolder.Callback
{
...... from https://stackoverflow.com/q/8149225/1393006




public boolean onTouchEvent(MotionEvent event)
{   
    canvas.drawBitmap(myBitmap, event.getX() - (myBitmap.getWidth() / 2), event.getY() - (myBitmap.getHeight() / 2), null);
    canvas.drawCircle(event.getX(), event.getY(), 10, paint);
    surfaceHolder.unlockCanvasAndPost(canvas);
    Log.d("onTouch","X: "+event.getX()+" , Y: "+event.getY());
    x = event.getX();
    return true;
}
}

code from xml

<TextView
    android:id="@+id/tv1" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="tv1" />

<te.de11.surf
    android:id="@+id/surfaceview" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
   />

error message from log cat

D/dalvikvm(443): Debugger has detached; object registry had 1 entries
I/AndroidRuntime(443): NOTE: attach of thread 'Binder Thread #3' failed
D/prob(363): java.lang.NullPointerException
D/float create(363): 0.0
I/ActivityManager(60): Displayed te.de11/.For12junonly2Activity: +1s29ms
D/dalvikvm(127): GC_EXPLICIT freed 66K, 52% free 2855K/5895K, external 4998K/6087K, paused 44ms
  • 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-05T14:11:53+00:00Added an answer on June 5, 2026 at 2:11 pm

    You are trying to get a reference to the TextView in your XML before setting that XML as the view for your activity. As your Activity doesn’t have any view right now, any findViewById() call will result in a NullPointerException. To fix it, simply call setContentView() before referencing any of the widgets used in the XML. It is usually called directly after the super() call.

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

Sidebar

Related Questions

Hi after refering to http://www.mono-project.com/Embedding_Mono i can call methods from managed code by using
I am using Server version: Apache/1.3.34 (Debian) mod_perl - 1.29 By refering to STDIN,
Is there anyway to grab the referring URL using javascript, lets say the reffering
I was watching MIX session. Presenter there was refering Panoramic experience in windows phone.
Using two ScriptManagers(ASP.Net and Telerik) will effect the page performance ? I have both
I have defined schema for xml in file packetTemplate.xsd.Using ms tool xsd.exe i have
I'm able to change an entire documentation block's color inside textmate by using the
refering to this answer , the second code block. My question is: If I
So I am using a Repeater inside a form to display a list of
I am refering to article at http://www.wintoolzone.com/articles/AuthoringStackWalkerForX86.pdf I am using VC++ 2008. I realize

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.