================================= 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