我有扩展MainActivity的活动,这是我的MainActivity
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{
private DrawerLayout dw;
private ActionBarDrawerToggle barToggle;
private Toolbar toolBar;
private NavigationView navigationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setActivityView(R.layout.activity_main);
this.toolBar = (Toolbar) findViewById(R.id.nav_action);
setSupportActionBar(this.toolBar);
this.dw = (DrawerLayout) findViewById(R.id.drawerLayout);
this.barToggle = new ActionBarDrawerToggle(this, dw, R.string.nav_open, R.string.nav_close);
dw.addDrawerListener(barToggle);
barToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
this.navigationView = (NavigationView)findViewById(R.id.navigationView);
this.navigationView.setNavigationItemSelectedListener(this);
setActionBarTitle("Home");
}
public void setActivityView(int view){
setContentView(view);
}
public void setActionBarTitle(String title){
this.getSupportActionBar().setTitle(title);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (barToggle.onOptionsItemSelected(item))
return true;
return super.onOptionsItemSelected(item);
}
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item
return true;
}
这是我的提醒活动,它扩展了MainActivity
public class ReminderActivity extends MainActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_reminder);
setActionBarTitle("Reminder");
//setActivityView(R.layout.activity_reminder);
}
@Override
public boolean onNavigationItemSelected(MenuItem item) {
return super.onNavigationItemSelected(item);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
@Override
public void setActionBarTitle(String title) {
super.setActionBarTitle(title);
}
@Override
public void setActivityView(int view) {
super.setActivityView(view);
}
当我尝试更改其布局时,我的问题是关于ReminderActivity的布局我遇到应用程序崩溃错误。如果我没有,一切都很好。我认为问题在于继承,使用基于onCreate的基础。
调试日志:
09-06 08:12:05.230: E/AndroidRuntime(12068): FATAL EXCEPTION: main
09-06 08:12:05.230: E/AndroidRuntime(12068): Process: com.activityagent.tayfunakguc.activityagent, PID: 12068
09-06 08:12:05.230: E/AndroidRuntime(12068): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.activityagent.tayfunakguc.activityagent/com.activityagent.tayfunakguc.activityagent.ReminderActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.DrawerLayout
09-06 08:12:05.230: E/AndroidRuntime(12068): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
09-06 08:12:05.230: E/AndroidRuntime(12068): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
09-06 08:12:05.230: E/AndroidRuntime(12068): at android.app.ActivityThread.-wrap12(ActivityThread.java)
09-06 08:12:05.230: E/AndroidRuntime(12068): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
09-06 08:12:05.230: E/AndroidRuntime(12068): at android.os.Handler.dispatchMessage(Handler.java:102)
09-06 08:12:05.230: E/AndroidRuntime(12068): at android.os.Looper.loop(Looper.java:154)
09-06 08:12:05.230: E/AndroidRuntime(12068): at android.app.ActivityThread.main(ActivityThread.java:6119)
09-06 08:12:05.230: E/AndroidRuntime(12068): at java.lang.reflect.Method.invoke(Native Method)
09-06 08:12:05.230: E/AndroidRuntime(12068): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
09-06 08:12:05.230: E/AndroidRuntime(12068): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
09-06 08:12:05.230: E/AndroidRuntime(12068): Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.DrawerLayout
09-06 08:12:05.230: E/AndroidRuntime(12068): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.constraint.DrawerLayout
09-06 08:12:05.230: E/AndroidRuntime(12068): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.DrawerLayout" on path: DexPathList[[zip file "/data/app/com.activityagent.tayfunakguc.activityagent-2/base.apk", zip file "/data/app/com.activityagent.tayfunakguc.activityagent-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.activityagent.tayfunakguc.activityagent-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.activityagent.tayfunakguc.activityagent-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.activityagent.tayfunakguc.activityagent-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.activityagent.tayfunakguc.activityagent-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.activityagent.tayfunakguc.activityagent-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.activityagent.tayfunakguc.activityagent-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.activityagent.tayfunakguc.activityagent-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.activityagent.tayfunakguc.activityagent-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.activityagent.tayfunakguc.activityagent-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.activityagent.tayfunakguc.activityagent-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.activityagent.tayfunakguc.activityagent-2/lib/arm, /system/lib, /vendor/lib]]
09-06 08:12:05.230: E/AndroidRuntime(12068): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
09-06 08:12:05.230: E/AndroidRuntime(12068): at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
09-06 08:12:05.230: E/AndroidRuntime(12068): at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
09-06 08:12:05.230: E/AndroidRuntime(12068): at android.view.LayoutInflater.createView(LayoutInflater.java:609)
09-06 08:12:05.230: E/AndroidRuntime(12068): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
09-06 08:12:05.230: E/AndroidRuntime(12068): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
09-06 08:12:05.230: E/AndroidRuntime(12068): at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
09-06 08:12:05.230: E/AndroidRuntime(12068): at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
09-06 08:12:05.230: E/AndroidRuntime(12068): at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
09-06 08:12:05.230: E/AndroidRuntime(12068): at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
09-06 08:12:05.230: E/AndroidRuntime(12068): at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
09-06 08:12:05.230: E/AndroidRuntime(12068): at com.activityagent.tayfunakguc.activityagent.MainActivity.setActivityView(MainActivity.java:47)
09-06 08:12:05.230: E/AndroidRuntime(12068): at com.activityagent.tayfunakguc.activityagent.ReminderActivity.setActivityView(ReminderActivity.java:38)
09-06 08:12:05.230: E/AndroidRuntime(12068): at com.activityagent.tayfunakguc.activityagent.ReminderActivity.onCreate(ReminderActivity.java:19)
09-06 08:12:05.230: E/AndroidRuntime(12068): at android.app.Activity.performCreate(Activity.java:6679)
09-06 08:12:05.230: E/AndroidRuntime(12068): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
09-06 08:12:05.230: E/AndroidRuntime(12068): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
09-06 08:12:05.231: E/AndroidRuntime(12068): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
09-06 08:12:05.231: E/AndroidRuntime(12068): at android.app.ActivityThread.-wrap12(ActivityThread.java)
09-06 08:12:05.231: E/AndroidRuntime(12068): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
09-06 08:12:05.231: E/AndroidRuntime(12068): at android.os.Handler.dispatchMessage(Handler.java:102)
09-06 08:12:05.231: E/AndroidRuntime(12068): at android.os.Looper.loop(Looper.java:154)
09-06 08:12:05.231: E/AndroidRuntime(12068): at android.app.ActivityThread.main(ActivityThread.java:6119)
09-06 08:12:05.231: E/AndroidRuntime(12068): at java.lang.reflect.Method.invoke(Native Method)
09-06 08:12:05.231: E/AndroidRuntime(12068): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
09-06 08:12:05.231: E/AndroidRuntime(12068): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)