android - recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
问题描述
日志猫2020-11-05 22:49:22.581 1663-1663/? W/ContextImpl:在没有合格用户的情况下调用系统进程中的方法:android.app.ContextImpl.sendBroadcast:1025 com.android.server.location.OppoSuplController.sendSuplConfigUpdateBroadcast:293 com.android.server.location.OppoSuplController.updateSuplConfig: 274 com.android.server.location.OppoSuplController.access$1300:47 com.android.server.location.OppoSuplController$2.handleMessage:619 2020-11-05 22:49:22.582 1663-1663/?D/OppoSuplController:mSuplHostName:supl.google.com,mSuplHostPort:7275,mSuplMode:3,mMsaEnabled:真,mMsbEnabled:真,mSpecHostEnabled:真,mHostSwitchEnabled:真,mTelephonyImsi:40494 2020-11-05 22:49:22.620 2935 -2935/? D/CdmaVolteServiceChecker:onReceive,action = android.intent.action.SERVICE_STATE 2020-11-05 22:49:22。620 2935-2935/? D/CdmaVolteServiceChecker:updateState,检查 = 假 2020-11-05 22:49:22.620 2935-2935/?D/CdmaVolteServiceChecker:shouldShowVolteAlert cdma混合电压支持,返回false。2020-11-05 22:49:22.844 1663-3532/? E/进程:get_ion_cache_memory:无法打开/d/ion/heaps/system 2020-11-05 22:49:22.980 1663-4211/?E/进程:get_ion_cache_memory:无法打开/d/ion/heaps/system 2020-11-05 22:49:25.681 22324-22457/?E/Parcel:此处不支持读取 NULL 字符串。2020-11-05 22:49:27.649 1173-1382/? E/存储:getDiskStats 失败,结果为 NOT_SUPPORTED,大小为 0 2020-11-05 22:49:28.068 1663-1663/?D/BatteryService:发送广播:oppo.intent.action.BATTERY_DATA_UPDATE 2020-11-05 22:49:28.069 1663-1663/? W/ContextImpl:在没有合格用户的情况下调用系统进程中的方法:android.app.ContextImpl。sendBroadcast:1025 com.android.server.BatteryService$8.run:803 android.os.Handler.handleCallback:873 android.os.Handler.dispatchMessage:99 android.os.Looper.loop:226 2020-11-05 22:49 :29.396 10556-10598/? W/Settings:设置 plane_mode_on 已从 android.provider.Settings.System 移至 android.provider.Settings.Global,返回只读值。2020-11-05 22:49:29.520 1663-1663/? D/意图:disableDeathOnFileUriExposure com.android.chrome 2020-11-05 22:49:29.568 19152-19332/? I/BtGatt.ScanManager:msg.what = 6 2020-11-05 22:49:29.591 818-818/?i//vendor/bin/hw/vendor.qti.hardware.servicetracker@1.0-service: service: com.android.chrome/org.chromium.components.background_task_scheduler.BackgroundTaskJobService的服务连接大小删除后为0 2020-11- 05 22:49:29.591 818-818/?我//供应商/bin/hw/vendor.qti.hardware。servicetracker@1.0-service:客户端的客户端连接大小:系统删除后为 16 2020-11-05 22:49:29.593 22324-23131/? D/意图:disableDeathOnFileUriExposure com.android.chrome 2020-11-05 22:49:29.611 22324-22324/? E/cr_BkgrdTaskJS: 尝试完成非当前 BackgroundTask。2020-11-05 22:49:29.683 14000-24041/? E/MCS2.0_CIPHER_ALGO: checkSign 1 2020-11-05 22:49:29.691 14000-24041/? D/MCS2.0_CIPHER_ALGO:riv native_AES_encrypt 标志 0 2020-11-05 22:49:34.182 1663-2761/?带看门狗:!@WatchDog_3773 2020-11-05 22:49:29.705 14000-24041/? D/MCS2.0_CIPHER_ALGO:riv native_AES_encrypt 标志 0 2020-11-05 22:49:34.577 1663-1663/?D/意图:disableDeathOnFileUriExposure com.facebook.katana 2020-11-05 22:49:34.622 19152-19332/? I/BtGatt.ScanManager: msg.what = 6 2020-11-05 22:49:35.253 818-818/? 我//供应商/bin/hw/vendor.qti.hardware。servicetracker@1.0-service:服务连接的大小:com.facebook.katana/com.facebook.analytics2.logger.LollipopUploadService 删除后为 0 2020-11-05 22:49:35.253 818-818/? I//vendor/bin/hw/vendor.qti.hardware.servicetracker@1.0-service: 客户端的客户端连接大小: 删除后系统为16 2020-11-05 22:49:38.656 1663-1673/? I/system_server:后台并发复制GC释放90991(7MB)个AllocSpace对象,40(976KB)LOS对象,17%空闲,36MB/44MB,暂停563us共168.097ms 2020-11-05 22:49:38.830 1663-1663/ ? D/BatteryService:发送广播:oppo.intent.action.BATTERY_DATA_UPDATE 2020-11-05 22:49:38.831 1663-1663/? W/ContextImpl:在没有合格用户的情况下调用系统进程中的方法:android.app.ContextImpl.sendBroadcast:1025 com.android.server.BatteryService$8.run:803 android.os.Handler。handleCallback:873 android.os.Handler.dispatchMessage:99 android.os.Looper.loop:226 2020-11-05 22:49:39.072 1663-4881/? W/System.err:java.io.FileNotFoundException:/proc/blackCheckStatus(没有这样的文件或目录)2020-11-05 22:49:39.073 1663-4881/?W/System.err:在 java.io.FileInputStream.open0(本机方法)2020-11-05 22:49:39.073 1663-4881/?W/System.err:在 java.io.FileInputStream.open(FileInputStream.java:231) 2020-11-05 22:49:39.073 1663-4881/?W/System.err:在 java.io.FileInputStream.(FileInputStream.java:165) 2020-11-05 22:49:39.073 1663-4881/?W/System.err:在 android.os.FileUtils.readTextFile(FileUtils.java:514) 2020-11-05 22:49:39.073 1663-4881/?W/System.err:在 com.android.server.BootReceiver$2.run(BootReceiver.java:232) 2020-11-05 22:49:39.074 1663-4882/?W/System.err: java.io.FileNotFoundException: /proc/brightCheckStatus (没有这样的文件或目录) 2020-11-05 22:49:39.075 1663-4882/? W/System.err:在 java.io.FileInputStream.open0(本机方法)2020-11-05 22:49:39.075 1663-4882/?W/System.err:在 java.io.FileInputStream.open(FileInputStream.java:231) 2020-11-05 22:49:39.075 1663-4882/?W/System.err:在 java.io.FileInputStream.(FileInputStream.java:165) 2020-11-05 22:49:39.075 1663-4882/?W/System.err:在 android.os.FileUtils.readTextFile(FileUtils.java:514) 2020-11-05 22:49:39.075 1663-4882/?W/System.err:在 com.android.server.BootReceiver$3.run(BootReceiver.java:259) 2020-11-05 22:49:40.739 818-818/?I//vendor/bin/hw/vendor.qti.hardware.servicetracker@1.0-service: 客户端连接大小: com.android.chrome 删除后为3 2020-11-05 22:49:41.368 5961-5965/ ? E/rutils:releaseProcess gCount = 1 2020-11-05 22:49:41.475 10556-10598/? W/Settings:设置 plane_mode_on 已从 android.provider.Settings.System 移至 android.provider.Settings.Global,返回只读值。2020-11-05 22:49:49.067 1663-1663/? D/BatteryService:发送广播:oppo.intent.action.BATTERY_DATA_UPDATE 2020-11-05 22:49:49.068 1663-1663/? W/ContextImpl:在没有合格用户的情况下调用系统进程中的方法:android.app.ContextImpl.sendBroadcast:1025 com.android.server.BatteryService$8.run:803 android.os.Handler.handleCallback:873 android.os。 Handler.dispatchMessage:99 android.os.Looper.loop:226 2020-11-05 22:49:53.552 10556-10598/? W/Settings:设置 plane_mode_on 已从 android.provider.Settings.System 移至 android.provider.Settings.Global,返回只读值。2020-11-05 22:49:55。710 22324-22457/? E/Parcel:此处不支持读取 NULL 字符串。2020-11-05 22:50:00.080 1663-1663/? D/电池服务:发送广播:oppo.intent.action.BATTERY_DATA_UPDATE 2020-11-05 22:50:00.081 1663-1663/? W/ContextImpl:在没有合格用户的情况下调用系统进程中的方法:android.app.ContextImpl.sendBroadcast:1025 com.android.server.BatteryService$8.run:803 android.os.Handler.handleCallback:873 android.os。 Handler.dispatchMessage:99 android.os.Looper.loop:226 构建错误
执行任务:项目 G:\SOFTWARES\Recyclerview 中的 [:app:assembleDebug]
任务 :app:preBuild UP-TO-DATE 任务 :app:preDebugBuild UP-TO-DATE 任务 :app:compileDebugAidl NO-SOURCE 任务 :app:generateDebugBuildConfig UP-TO-DATE 任务 :app:compileDebugRenderscript NO-SOURCE 任务 :app: javaPreCompileDebug 最新任务 :app:generateDebugResValues 最新任务 :app:generateDebugResources 最新任务 :app:createDebugCompatibleScreenManifests 最新任务 :app:extractDeepLinksDebug 最新任务 :app: processDebugManifest 最新任务 :app:mergeDebugShaders 最新任务 :app:compileDebugShaders NO-SOURCE 任务 :app:generateDebugAssets 最新任务 :app:mergeDebugAssets 最新任务 :app:mergeDebugResources 任务:app:processDebugResources
任务 :app:compileDebugJavaWithJavac G:\SOFTWARES\Recyclerview\app\src\main\java\com\example\recyclerview\MainActivity.java:23: 错误:找不到符号 recyclerView = (RecyclerView) findViewById(R.id.recyclerView) ; ^ 符号:变量 recyclerView 位置:类 id 注意:G:\SOFTWARES\Recyclerview\app\src\main\java\com\example\recyclerview\ProductAdapter.java 使用或覆盖已弃用的 API。注意:使用 -Xlint:deprecation 重新编译以获取详细信息。1 个错误
任务 :app:compileDebugJavaWithJavac 失败
FAILURE:构建失败并出现异常。
- 出了什么问题:任务“:app:compileDebugJavaWithJavac”执行失败。
编译失败;有关详细信息,请参阅编译器错误输出。
尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。
在https://help.gradle.org获得更多帮助
在 1m 14s 内构建失败 11 个可操作的任务:3 个已执行,8 个是最新的
Mainactivity.java包 com.example.recyclerview;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import java.util.ArrayList; import java.util.List;
public class MainActivity extends AppCompatActivity {
//List<Product> ProductList;
RecyclerView recyclerView;
List<Object> productList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//getting the recyclerview from xml
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
//initializing the productlist
productList = new ArrayList<>();
//adding some items to our list
productList.add(
new Product(
1,
"Apple MacBook Air Core i5 5th Gen - (8 GB/128 GB SSD/Mac OS Sierra)",
"13.3 inch, Silver, 1.35 kg",
4.3,
60000,
R.drawable.macbook));
productList.add(
new Product(
1,
"Dell Inspiron 7000 Core i5 7th Gen - (8 GB/1 TB HDD/Windows 10 Home)",
"14 inch, Gray, 1.659 kg",
4.3,
60000,
R.drawable.dellinspiron));
productList.add(
new Product(
1,
"Microsoft Surface Pro 4 Core m3 6th Gen - (4 GB/128 GB SSD/Windows 10)",
"13.3 inch, Silver, 1.35 kg",
4.3,
60000,
R.drawable.surface));
//creating recyclerview adapter
ProductAdapter adapter = new ProductAdapter(this, productList);
//setting adapter to recyclerview
recyclerView.setAdapter(adapter);
} }
布局.product.xml
<androidx.appcompat.widget.LinearLayoutCompat
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="120dp"
android:layout_height="90dp"
android:padding="4dp" />
<TextView
android:id="@+id/textViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@id/imageView"
android:text="Apple MacBook Air Core i5 5th Gen - (8 GB/128 GB SSD/Mac OS Sierra)"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"
android:textColor="#000000" />
<TextView
android:id="@+id/textViewShortDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textViewTitle"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@id/imageView"
android:text="13.3 Inch, 256 GB"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small" />
<TextView
android:id="@+id/textViewRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textViewShortDesc"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@id/imageView"
android:background="@color/colorPrimary"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:text="4.7"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small.Inverse"
android:textStyle="bold" />
<TextView
android:id="@+id/textViewPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textViewRating"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@id/imageView"
android:text="INR 56990"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
android:textStyle="bold" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.cardview.widget.CardView>
</androidx.appcompat.widget.LinearLayoutCompat>
activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout
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">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="354dp"
android:layout_height="626dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayou
我正在使用以下网站https://www.simplifiedcoding.net/android-recyclerview-cardview-tutorial/进行回收商参考
解决方案
请在recyclerview中设置id。
android:id="@+id/recyclerView"
<androidx.constraintlayout.widget.ConstraintLayout
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">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="354dp"
android:layout_height="626dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
推荐阅读
- angular - `retryWhen`过期后如何返回值?(对于 `canActivate` 守卫)
- c# - 流利的断言:如何断言“集合中的单个等效项”?
- xml - 使用 Logstash 解析 XML 日志
- node.js - Google使用passport-google-oauth20登录时出现Heroku错误
- kubernetes - Kubernetes 中请求的具体用途是什么
- python - ctc 的训练损失为 inf,而验证损失似乎正常
- excel - 在没有开发人员选项卡的 Excel 中使用宏
- ios - 更新 ObservedObjects 时 SwiftUI 计时器不断重置
- javascript - 如何使用 React 创建 Tabs 组件
- javascript - Google Apps 脚本:发送 docx 电子邮件附件