请帮帮我。
这是错误还是警告?
我怎么解决这个问题?
错误是View v
是无法访问的语句
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
return super.getView(position, convertView, parent);
View v;
v = convertView;
LayoutInflater li = LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = li.inflate(R.layout.custom_layout, null);
TextView champ = (TextView)v.findViewById(R.id.textView);
TextView year = (TextView)v.findViewById(R.id.textView2);
ImageView pic = (ImageView)v.findViewById(R.id.imageView);
champ.setText(adaptArray.get(position).getChamp()); year.setText(adaptArray.get(position).getYear()); pic.setImageResource(adaptArray.get(position).getSport());
return v;
}
答案 0 :(得分:0)
删除此
return super.getView(position, convertView, parent);
答案 1 :(得分:0)
在return关键字无法访问之后写入其他任何内容。 从函数的第一行中删除返回 super.getView(position,convertView,parent); 。
答案 2 :(得分:0)
这是一个警告,告诉您对代码的静态分析显示您的某些代码永远不会到达,因为该方法之前会返回。
以下是如何通过将convertView
传递给super.getView(...)
来解决问题并正确使用public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View v = super.getView(position, convertView, parent);
if(v == null){
LayoutInflater li = LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = li.inflate(R.layout.custom_layout, null);
}
TextView champ = (TextView)v.findViewById(R.id.textView);
TextView year = (TextView)v.findViewById(R.id.textView2);
ImageView pic = (ImageView)v.findViewById(R.id.imageView);
champ.setText(adaptArray.get(position).getChamp());
year.setText(adaptArray.get(position).getYear());
pic.setImageResource(adaptArray.get(position).getSport());
return v;
}
:
this
答案 3 :(得分:0)
这是因为该方法的 Top 中的以下代码行:
return super.getView(position, convertView, parent);
当您从return
method
method
内部时,java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2750)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2811)
at android.app.ActivityThread.-wrap12 (ActivityThread.java)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1528)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:154)
at android.app.ActivityThread.main (ActivityThread.java:6316)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:762)
Caused by: java.lang.SecurityException:
at android.os.Parcel.readException (Parcel.java:1683)
at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel (DatabaseUtils.java:146)
at android.content.ContentProviderProxy.openTypedAssetFile (ContentProviderNative.java:692)
at android.content.ContentResolver.openTypedAssetFileDescriptor (ContentResolver.java:1163)
at android.content.ContentResolver.openTypedAssetFileDescriptor (ContentResolver.java:1107)
at android.content.ClipData$Item.coerceToText (ClipData.java:332)
at br.com.sicoob.camera.clipboard.ClipboardInterface.getText (ClipboardInterface.java:35)
at br.com.sicoobnet.InicioWap.verificarExisteBoletoCopiado (InicioWap.java:312)
at br.com.sicoobnet.InicioWap.verificarAcao (InicioWap.java:308)
at br.com.sicoobnet.InicioWap.onCreate (InicioWap.java:126)
at android.app.Activity.performCreate (Activity.java:6757)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2703)
的其余代码将不会运行。 < / p>