启动包含导航抽屉的活动时遇到问题,或者在添加之前我不明白我的所有代码都能正常工作,并且错误发生在活动的onCreate()方法中。
La partie Java
Public class Walcome extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, OnMapReadyCallback {
SupportMapFragment supportMapFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_walcome);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
navigationView.setNavigationItemSelectedListener(this);
supportMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
supportMapFragment.getMapAsync(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.walcome, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_home) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_tools) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
@Override
public void onMapReady(GoogleMap googleMap) {
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(37.7750,122.4183))
.title("Kinshasa"));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(37.7750,122.4183),15));
}
}
//错误
07-09 12:12:14.265 11623-11623/cd.fastdev.fast_book E/dalvikvm: Could not find class 'androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper', referenced from method androidx.core.view.ViewCompat.addOnUnhandledKeyEventListener
07-09 12:12:14.265 11623-11623/cd.fastdev.fast_book E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method androidx.core.view.ViewCompat.dispatchApplyWindowInsets
07-09 12:12:14.275 11623-11623/cd.fastdev.fast_book E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method androidx.core.view.ViewCompat.onApplyWindowInsets
07-09 12:12:14.285 11623-11623/cd.fastdev.fast_book E/dalvikvm: Could not find class 'android.view.View$OnUnhandledKeyEventListener', referenced from method androidx.core.view.ViewCompat.removeOnUnhandledKeyEventListener
07-09 12:12:14.285 11623-11623/cd.fastdev.fast_book E/dalvikvm: Could not find class 'androidx.core.view.ViewCompat$1', referenced from method androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener
07-09 12:12:41.285 11623-11623/cd.fastdev.fast_book E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method androidx.appcompat.widget.AppCompatImageHelper.hasOverlappingRendering
07-09 12:13:14.295 11623-11623/cd.fastdev.fast_book E/ViewRootImpl: sendUserActionEvent() mView == null
07-09 12:13:14.485 11623-11623/cd.fastdev.fast_book E/dalvikvm: Could not find class 'androidx.drawerlayout.widget.DrawerLayout$1', referenced from method androidx.drawerlayout.widget.DrawerLayout.<init>
07-09 12:13:14.495 11623-11623/cd.fastdev.fast_book E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method androidx.drawerlayout.widget.DrawerLayout.onDraw
07-09 12:13:14.495 11623-11623/cd.fastdev.fast_book E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method androidx.drawerlayout.widget.DrawerLayout.onMeasure
07-09 12:13:14.495 11623-11623/cd.fastdev.fast_book E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method androidx.drawerlayout.widget.DrawerLayout.onMeasure
07-09 12:13:14.835 11623-11623/cd.fastdev.fast_book E/dalvikvm: Could not find class 'dalvik.system.DelegateLastClassLoader', referenced from method z.b
07-09 12:13:15.835 11623-11623/cd.fastdev.fast_book E/dalvikvm: Could not find class 'android.view.accessibility.AccessibilityNodeInfo$AccessibilityAction', referenced from method ea.onInitializeAccessibilityNodeInfo
07-09 12:13:15.855 11623-11623/cd.fastdev.fast_book E/dalvikvm: Could not find class 'android.view.accessibility.AccessibilityNodeInfo$AccessibilityAction', referenced from method ea.performAccessibilityAction
07-09 12:13:15.975 11623-11623/cd.fastdev.fast_book E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{cd.fastdev.fast_book/cd.fastdev.fast_book.view.Walcome}: android.view.InflateException: Binary XML file line #52: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2362)
at android.app.ActivityThread.access$700(ActivityThread.java:168)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5493)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #52: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:804)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:812)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:812)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:812)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:898)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:794)
at android.view.LayoutInflater.inflate(LayoutInflater.java:526)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:382)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at cd.fastdev.fast_book.view.Walcome.onCreate(Walcome.java:39)
at android.app.Activity.performCreate(Activity.java:5372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2362)
at android.app.ActivityThread.access$700(ActivityThread.java:168)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5493)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException: name == null
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:491)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at androidx.fragment.app.Fragment.isSupportFragmentClass(Fragment.java:483)
at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3709)
at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:120)
at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:405)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:387)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:738)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:804)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:812)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:812)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:812)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:898)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:794)
at android.view.LayoutInflater.inflate(LayoutInflater.java:526)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:382)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at cd.fastdev.fast_book.view.Walcome.onCreate(Walcome.java:39)
at android.app.Activity.performCreate(Activity.java:5372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2362)
at android.app.ActivityThread.access$700(ActivityThread.java:168)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5493)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
at dalvik.system.NativeStart.main(Native Method)