我正在尝试设置警报管理器应用程序,但是每当我运行我的应用程序时,都会弹出一个运行时异常,告诉我工具栏不能膨胀,我似乎也无法弄清楚原因。
我注释掉了xml中工具栏的代码以及mainactivity,以尝试调试该应用程序。但对于浮动操作按钮,我也会在布局中看到相同的错误,这向我表明问题不是工具栏,而是其他问题。
这是logcat:
Process: com.example.alarmmanager, PID: 17402
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.alarmmanager/com.example.alarmmanager.MainActivity}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.v7.widget.Toolbar
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.v7.widget.Toolbar
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class android.support.v7.widget.Toolbar
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.Toolbar" on path: DexPathList[[zip file "/data/app/com.example.alarmmanager-kj3KUbYybMt0cIjBxRbFUw==/base.apk", zip file "/data/app/com.example.alarmmanager-kj3KUbYybMt0cIjBxRbFUw==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.alarmmanager-kj3KUbYybMt0cIjBxRbFUw==/split_lib_resources_apk.apk", zip file "/data/app/com.example.alarmmanager-kj3KUbYybMt0cIjBxRbFUw==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.alarmmanager-kj3KUbYybMt0cIjBxRbFUw==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.alarmmanager-kj3KUbYybMt0cIjBxRbFUw==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.alarmmanager-kj3KUbYybMt0cIjBxRbFUw==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.alarmmanager-kj3KUbYybMt0cIjBxRbFUw==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.alarmmanager-kj3KUbYybMt0cIjBxRbFUw==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.alarmmanager-kj3KUbYybMt0cIjBxRbFUw==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.alarmmanager-kj3KUbYybMt0cIjBxRbFUw==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.alarmmanager-kj3KUbYybMt0cIjBxRbFUw==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.alarmmanager-kj3KUbYybMt0cIjBxRbFUw==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.alarmmanager-kj3KUbYybMt0cIjBxRbFUw==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.alarmmanager.MainActivity.onCreate(MainActivity.java:34)
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.example.alarmmanager-kj3KUbYybMt0cIjBxRbFUw==/split_lib_resources_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:354)
at dalvik.system.DexFile.<init>(DexFile.java:101)
at dalvik.system.DexFile.<init>(DexFile.java:75)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
MainActivity.java:
private FloatingActionButton mAddReminderButton;
private Toolbar mToolbar;
AlarmCursorAdapter mCursorAdapter;
AlarmReminderDbHelper alarmReminderDbHelper = new AlarmReminderDbHelper(this);
ListView reminderListView;
ProgressDialog prgDialog;
public static final int VEHICLE_LOADER = 0;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
//by the way the (MainActivitty.java:34 )
//reference in the logcat is this line
setContentView(R.layout.activity_main);
mToolbar = findViewById(R.id.myToolbar);
setSupportActionBar (mToolbar);
mToolbar.setTitle(R.string.app_name);
reminderListView = (ListView) findViewById(R.id.list);
View emptyView = findViewById(R.id.empty_view);
reminderListView.setEmptyView(emptyView);
mCursorAdapter = new AlarmCursorAdapter(this, null);
reminderListView.setAdapter(mCursorAdapter);
reminderListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(MainActivity.this, AddReminderActivity.class);
Uri currentVehicleUri = ContentUris.withAppendedId(AlarmReminderContract.AlarmReminderEntry.CONTENT_URI, id);
// Set the URI on the data field of the intent
intent.setData(currentVehicleUri);
startActivity(intent);
}
});
mAddReminderButton = (FloatingActionButton) findViewById(R.id.fab);
mAddReminderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), AddReminderActivity.class);
startActivity(intent);
}
});
getLoaderManager().initLoader(VEHICLE_LOADER, null, (android.app.LoaderManager.LoaderCallbacks<Object>) this);
}
xml代码
<RelativeLayout 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=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/myToolbar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:minHeight="@dimen/abc_action_bar_default_height_material"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:contentInsetLeft="0dp"
app:contentInsetStart="16dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="@color/myColor" />
<ListView
android:id="@+id/list"
android:layout_below="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RelativeLayout
android:id="@+id/empty_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<TextView
android:id="@+id/no_reminder_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:padding="16dp"
android:gravity="center"
android:text="@string/no_card_details"/>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_add"
app:backgroundTint="@color/colorPrimary"
app:fabSize="normal"/>
</RelativeLayout>
构建gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:multidex:1.0.2'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.bignerdranch.android:recyclerview-multiselect:+'
implementation 'com.wrapp.floatlabelededittext:library:0.0.6'
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
implementation 'com.getbase:floatingactionbutton:1.9.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
答案 0 :(得分:0)
支持status:
请将您的媒体库降级为v7:28.0.0
,然后查看问题是否仍然存在
例如:
27.1.0
您还需要更改编译版本并将构建工具也更改为27。
implementation 'com.android.support:appcompat-v7:27.1.0' // appcompat library
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:recyclerview-v7:27.1.0'
同步后,重建并清理您的项目