【发布时间】:2019-09-23 13:21:49
【问题描述】:
android 编程新手,java,我正在尝试创建一个“简单的..”BottomSheet,当我单击我的一个位置时,它必须出现。实际上我已经能够创建我的地图并加载我的点数据。我的地图在片段中..
<?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">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
/>
</RelativeLayout>
然后我创建了查看在线教程的 BottomSheet。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinaCoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.chargesplit.android.activities.MainActivity">
<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@android:color/holo_green_light"
android:clipToPadding="true"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="@string/bottom_sheet_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ciao"
android:textColor="@android:color/white"
android:textSize="24sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="ciao2"
android:textColor="@android:color/white" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinaCoordinatorLayout>
最后,在我的 Main Activity 中,我设法引用了我的底页,但可能由于缺乏经验,我每次都会在这一行出错:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
-> View nestedScrollView = (View) findViewById(R.id.nestedScrollView);
mBottomSheetBehaviour = BottomSheetBehavior.from(nestedScrollView);
我总是遇到这个错误,我可能在这里遗漏了一部分......有人可以尝试让我朝着正确的方向前进以了解问题所在吗?
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewGroup$LayoutParams android.view.View.getLayoutParams()' on a null object reference
【问题讨论】:
标签: java android android-fragments