设计很简单,但不知道导致错误的原因。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="top">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
</LinearLayout>
<include layout="@layout/activity_main"/>
<fragment
android:id="@+id/fragmented1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
app:layout="@layout/search_box"
tools:layout="@layout/search_box" />
</LinearLayout>
public class MainActivity extends AppCompatActivity {
RelativeLayout search;
TextView textView;
ImageView close_btn,filter_cars;
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
search=(RelativeLayout) findViewById(R.id.searchingcars);
textView=(TextView) findViewById(R.id.searchcars1);
close_btn=(ImageView) findViewById(R.id.search_close_btn);
// filter_cars=(ImageView) findViewById(R.id.filter);
/* filter_cars.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
intent=new Intent(this,Filtercars.java);
startActivity(intent);
}
});*/
close_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
search.setVisibility(View.GONE);
}
});
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
search.setVisibility(View.VISIBLE);
}
});
}
}
错误:无法启动活动ComponentInfo {in.mega.sliderdrawer/in.mega.sliderdrawer.MainActivity}
:java.lang.NullPointerException:尝试调用虚方法&#39; void android.widget.ImageView.setOnClickListener(android.view) .View $ OnClickListener)&#39;在空对象引用上