Error in returning NULL pointer for findviewbyid

Source: Internet
Author: User

================================= Problem description ========================== =
Today, I encountered an error. Baidu failed to solve the problem. Maybe the search capability needs to be improved.
Paste some code first
protected void onCreate(Bundle savedInstanceState) {Log.v("GameWindow", "onCreate");super.onCreate(savedInstanceState);setContentView(R.layout.gameview);//LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);     //View layout = inflater.inflate(R.layout.gameview,null);//gameView = (GameView) view.findViewById(R.id.game_sudo_view);gameView = (GameView) findViewById(R.id.game_sudo_view);if(gameView == null){Log.v("gameView", "onCreate->null");}levelTextView = (TextView)findViewById(R.id.leveltextview);levelTextView.setText("Topic."+1));if(levelTextView == null){Log.v("TextView", "onCreate->null");}}

Below is gameview. xml
<?xml version="1.0" encoding="utf-8" ?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:background="@drawable/back">        <ImageView    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:layout_alignParentBottom="true"    android:contentDescription="@string/app_name"    android:src="@drawable/grass" />        <com.ljx.gameview.GameView        android:id="@+id/game_sudo_view"        android:layout_centerInParent="true"        android:layout_width="fill_parent"        android:layout_height="wrap_content"/>        <TextView        android:layout_centerHorizontal="true"         android:layout_above="@id/game_sudo_view"        android:id="@+id/leveltextview"        android:layout_marginTop="10dp"        android:layout_width="wrap_content"        android:layout_height="wrap_content"/>    </RelativeLayout>

Now the problem is that in a layout file, textview can be obtained through findviewbyid, but the custom component com. ljx. gameview. gameview always gets a null pointer.
Ask for support from predecessors
=============================== Solution 1 ========================== ===
Findviewbyid is found on the activity's own window...

Do you have the view code?

No, you can create a view in the code dynamically.

Error in returning NULL pointer for findviewbyid

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.