java - 无法在 android studio 中解析符号 v7 和 appComapat Activity 导入
问题描述
我在这个问题上被困了 3-4 天,我已经尝试了我力所能及的一切,清除了缓存,清理了项目,但它仍然不能在设备上运行。弹出的错误显示无法解析 v7.app.appcompatActivity。感谢您的帮助,代码如下:package com.edunomics.flashchatnewfirebase;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.support.v7.app.AppcompatActivity;
import androidx.appcompat.app.AppCompatActivity;
public class MainChatActivity extends AppCompatActivity {
// TODO: Add member variables here:
private String mDisplayName;
private ListView mChatListView;
private EditText mInputText;
private ImageButton mSendButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_chat);
// TODO: Set up the display name and get the Firebase reference
// Link the Views in the layout to the Java code
mInputText = (EditText) findViewById(R.id.messageInput);
mSendButton = (ImageButton) findViewById(R.id.sendButton);
mChatListView = (ListView) findViewById(R.id.chat_list_view);
// TODO: Send the message when the "enter" button is pressed
// TODO: Add an OnClickListener to the sendButton to send a message
}
// TODO: Retrieve the display name from the Shared Preferences
private void sendMessage() {
// TODO: Grab the text the user typed in and push the message to Firebase
}
// TODO: Override the onStart() lifecycle method. Setup the adapter here.
@Override
public void onStop() {
super.onStop();
// TODO: Remove the Firebase event listener on the adapter.
}
}
这是我的 app 的 build.gradle 文件
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.google.gms:google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
解决方案
只需要一个import
声明。请替换以下import
语句
import android.support.v7.app.AppCompatActivity;
与以下import
声明。
import androidx.appcompat.app.AppCompatActivity;
推荐阅读
- python - 如何获得只能包含 1 到 9 数字的随机 4 位数字?
- python - 使用 pysftp 针对使用自定义端口的 known_hosts 文件验证主机密钥
- python - 为收集的包裹建造轮子:psycopg2
- module - 尝试在 Spyder 中安装模块时出错
- python - RuntimeError:在 django-apscheduler 中添加代理代理作业时,set_wakeup_fd 仅在主解释器的主线程中有效
- python - VScode 运行 pip install 失败
- python - 形状 (3,1) 和 (3,) 未对齐:1 (dim 1) != 3 (dim 0)
- nginx - NGINX 中的 Websockets 无法与具有 Internet 代理的服务器一起使用:错误:3 秒内未收到 pong
- javascript - 从第 n 个孩子计数中排除 display:none div
- php - mysql如何允许用户使用php一次更新数据库中的列