- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
推荐项目.Java
public class RecommendItem {
private String name;
private String type;
private String address;
private Bitmap avatar;
public RecommendItem(String name, String type, String address, Bitmap avatar) {
this.name = name;
this.type = type;
this.address = address;
this.avatar = avatar;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Bitmap getAvatar() {
return avatar;
}
public void setAvatar(Bitmap avatar) {
this.avatar = avatar;
}
}
FoodRecommendAdapter.Java 公共(public)类 FoodRecommendAdapter 扩展 ArrayAdapter {
private Context context;
private int reID;
private ArrayList<RecommendItem> recommendItems;
public FoodRecommendAdapter(Context context, int resource, ArrayList<RecommendItem> data) {
super(context, resource, data);
this.context = context;
this.reID = resource;
this.recommendItems = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = null;
if (convertView == null) {
LayoutInflater layoutInflater = ((Activity) this.context).getLayoutInflater();
convertView = layoutInflater.inflate(this.reID, parent, false);
return convertView;
}
row = convertView;
RecommendItem item = recommendItems.get(position);
ImageView imageView = (ImageView) row.findViewById(R.id.iv_recommend);
imageView.setImageBitmap(item.getAvatar());
TextView textViewName =(TextView) row.findViewById(R.id.tv_name);
textViewName.setText(item.getName());
TextView textViewType =(TextView) row.findViewById(R.id.tv_type);
textViewType.setText(item.getType());
TextView textViewAddress =(TextView) row.findViewById(R.id.tv_name);
textViewAddress.setText(item.getName());
return row;
}
}
FoodRecommed.Java
public class FoodRecommend extends AppCompatActivity {
ListView listViewFood;
ArrayList<RecommendItem> recommendItems;
FoodRecommendAdapter foodRecommendAdapter;
Button btnMap, btnMyList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_food_recommend);
initComponents();
loadData();
}
private void loadData() {
recommendItems = new ArrayList<>();
recommendItems.add(new RecommendItem("Bánh Mì","Food","26 Lê Thị Riêng, Ben Thanh, District 1",
BitmapFactory.decodeResource(getResources(),R.drawable.banhmi)));
recommendItems.add(new RecommendItem("Phở","Food","19 Nguyễn Thị Minh Khai, District 1",
BitmapFactory.decodeResource(getResources(),R.drawable.pho)));
recommendItems.add(new RecommendItem("Bún Thịt Nướng","Food","195 Cô Giang, District 1",
foodRecommendAdapter = new FoodRecommendAdapter(this, R.layout.layout_item_recommend, recommendItems);
listViewFood.setAdapter(foodRecommendAdapter);
}
private void initComponents() {
listViewFood = (ListView) this.findViewById(R.id.food_recommend_list);
btnMap = (Button) findViewById(R.id.btn_map);
btnMyList = (Button) findViewById(R.id.btn_mylists);
}
public void mapActivity(View view) {
Intent intent = new Intent(FoodRecommend.this, MapsActivity.class);
startActivity(intent);
}
public void mylistActivity(View view) {
Intent intent = new Intent(FoodRecommend.this, MyList.class);
startActivity(intent);
}
}
监视器给出的错误
06-20 09:30:23.735 9834-9834/com.example.phy.hochiminhcity E/InputEventReceiver: Exception dispatching input event.
06-20 09:30:23.736 9834-9834/com.example.phy.hochiminhcity D/AndroidRuntime: Shutting down VM
06-20 09:30:23.738 9834-9834/com.example.phy.hochiminhcity E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.phy.hochiminhcity, PID: 9834
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)' on a null object reference
at com.example.phy.hochiminhcity.FoodRecommendAdapter.getView(FoodRecommendAdapter.java:43)
at android.widget.AbsListView.obtainView(AbsListView.java:2363)
at android.widget.ListView.makeAndAddView(ListView.java:1970)
at android.widget.ListView.fillDown(ListView.java:704)
at android.widget.ListView.fillGap(ListView.java:668)
at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5186)
at android.widget.ListView.trackMotionScroll(ListView.java:1889)
at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3568)
at android.widget.AbsListView.onTouchMove(AbsListView.java:3977)
at android.widget.AbsListView.onTouchEvent(AbsListView.java:3802)
at android.view.View.dispatchTouchEvent(View.java:10023)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2626)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2307)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2321)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2321)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2321)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2321)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2321)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2321)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:413)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1808)
at android.app.Activity.dispatchTouchEvent(Activity.java:3061)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:71)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:375)
at android.view.View.dispatchPointerEvent(View.java:10243)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4438)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4306)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3853)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3906)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3872)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3999)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3880)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4056)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3853)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3906)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3872)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3880)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3853)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6246)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6220)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6181)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6349)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
06-20 09:30:23.739 9834-9834/com.example.phy.hochiminhcity E/AndroidRuntime: at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:6320)
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6372)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874)
at android.view.Choreographer.doCallbacks(Choreographer.java:686)
at android.view.Choreographer.doFrame(Choreographer.java:615)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
06-20 09:30:23.748 1696-3221/system_process W/ActivityManager: Force finishing activity com.example.phy.hochiminhcity/.FoodRecommend
我不知道为什么它说“尝试在空对象引用上调用虚拟方法'void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)'”,而我已经在FoodRecommend中初始化了位图类
最佳答案
像这样更改你的代码
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
LayoutInflater layoutInflater = ((Activity)
this.context).getLayoutInflater();
convertView = layoutInflater.inflate(this.reID, parent, false);
holder.imageView = (ImageView) convertView .findViewById(R.id.iv_recommend);
holder.textViewName =(TextView) convertView .findViewById(R.id.tv_name);
holder.textViewType =(TextView) convertView .findViewById(R.id.tv_type);
holder.textViewAddress =(TextView) convertView .findViewById(R.id.tv_name);
convertView.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
RecommendItem item = recommendItems.get(position);
holder.imageView.setImageBitmap(item.getAvatar());
holder.textViewName.setText(item.getName());
holder.textViewType.setText(item.getType());
holder.textViewAddress.setText(item.getName());
return convertView;
}
class ViewHolder {
public TextView textViewType;
public ImageView imageView;
public TextView textViewType;
public TextView textViewAddress;
}
关于java - Android 应用程序在向下滚动到 ListView 中的第三项并出现位图错误后崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44643013/
我已经使用 vue-cli 两个星期了,直到今天一切正常。我在本地建立这个项目。 https://drive.google.com/open?id=0BwGw1zyyKjW7S3RYWXRaX24tQ
您好,我正在尝试使用 python 库 pytesseract 从图像中提取文本。请找到代码: from PIL import Image from pytesseract import image_
我的错误 /usr/bin/ld: errno: TLS definition in /lib/libc.so.6 section .tbss mismatches non-TLS reference
我已经训练了一个模型,我正在尝试使用 predict函数但它返回以下错误。 Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]])
根据Microsoft DataConnectors的信息我想通过 this ODBC driver 创建一个从 PowerBi 到 PostgreSQL 的连接器使用直接查询。我重用了 Micros
我已经为 SoundManagement 创建了一个包,其中有一个扩展 MediaPlayer 的类。我希望全局控制这个变量。这是我的代码: package soundmanagement; impo
我在Heroku上部署了一个应用程序。我正在使用免费服务。 我经常收到以下错误消息。 PG::Error: ERROR: out of memory 如果刷新浏览器,就可以了。但是随后,它又随机发生
我正在运行 LAMP 服务器,这个 .htaccess 给我一个 500 错误。其作用是过滤关键字并重定向到相应的域名。 Options +FollowSymLinks RewriteEngine
我有两个驱动器 A 和 B。使用 python 脚本,我在“A”驱动器中创建一些文件,并运行 powerscript,该脚本以 1 秒的间隔将驱动器 A 中的所有文件复制到驱动器 B。 我在 powe
下面的函数一直返回这个错误信息。我认为可能是 double_precision 字段类型导致了这种情况,我尝试使用 CAST,但要么不是这样,要么我没有做对...帮助? 这是错误: ERROR: i
这个问题已经有答案了: Syntax error due to using a reserved word as a table or column name in MySQL (1 个回答) 已关闭
我的数据库有这个小问题。 我创建了一个表“articoli”,其中包含商品的品牌、型号和价格。 每篇文章都由一个 id (ID_ARTICOLO)` 定义,它是一个自动递增字段。 好吧,现在当我尝试插
我是新来的。我目前正在 DeVry 在线学习中级 C++ 编程。我们正在使用 C++ Primer Plus 这本书,到目前为止我一直做得很好。我的老师最近向我们扔了一个曲线球。我目前的任务是这样的:
这个问题在这里已经有了答案: What is an undefined reference/unresolved external symbol error and how do I fix it?
我的网站中有一段代码有问题;此错误仅发生在 Internet Explorer 7 中。 我没有在这里发布我所有的 HTML/CSS 标记,而是发布了网站的一个版本 here . 如您所见,我在列中有
如果尝试在 USB 设备上构建 node.js 应用程序时在我的树莓派上使用 npm 时遇到一些问题。 package.json 看起来像这样: { "name" : "node-todo",
在 Python 中,您有 None单例,在某些情况下表现得很奇怪: >>> a = None >>> type(a) >>> isinstance(a,None) Traceback (most
这是我的 build.gradle (Module:app) 文件: apply plugin: 'com.android.application' android { compileSdkV
我是 android 的新手,我的项目刚才编译和运行正常,但在我尝试实现抽屉导航后,它给了我这个错误 FAILURE: Build failed with an exception. What wen
谁能解释一下?我想我正在做一些非常愚蠢的事情,并且急切地等待着启蒙。 我得到这个输出: phpversion() == 7.2.25-1+0~20191128.32+debian8~1.gbp108
我是一名优秀的程序员,十分优秀!