Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >android中找不到资源异常

android中找不到资源异常
EN

Stack Overflow用户
提问于 2013-02-27 10:35:32
回答 1查看 5.4K关注 0票数 3

我正在尝试在我的android应用程序中创建一个列表视图。但我在运行项目时遇到资源找不到异常。

activity_main.xml:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<include
    android:id="@+id/title_bar" 
    layout="@layout/title_bar" />

<ListView 
    android:id="@+id/FeedList"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/title_bar"
    ></ListView>  

</RelativeLayout>

list_item.xml:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" 
android:background="#FFFFFF">

<ImageButton
   android:id="@+id/FeedType"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="#E0E0E0"
   android:padding="9dp"
   android:src="@drawable/ic_launcher" />

<TextView 
   android:id="@+id/FeedTitle"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="Feed Title"
   android:textSize="18sp"
   android:layout_toRightOf="@+id/FeedType"
   android:paddingLeft="5dp"
   android:textColor="#000000"
   />

<TextView 
   android:id="@+id/FeedPostedBy"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_below="@+id/FeedTitle"
   android:text="by FeedOwner"
   android:layout_toRightOf="@+id/FeedType"
   android:paddingLeft="5dp"
   android:textSize="10sp"
   />

<TextView 
   android:id="@+id/FeedContent"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_below="@+id/FeedPostedBy"
   android:layout_toRightOf="@+id/FeedType"
   android:paddingLeft="5dp"
   android:paddingTop="8dp"
   android:text="The content posted as a feed by the feed owner will appear here"
   android:textSize="10sp"/>  

</RelativeLayout>

ListAdapter类:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package com.tcs.internal.prime;

import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity; 
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.TextView;

public class ListAdapter extends BaseAdapter{

private Activity listAdapterActivity = null;
private ArrayList<HashMap<String,String>> data;
private static LayoutInflater inflater;

public ListAdapter(Activity ListActivity,ArrayList<HashMap<String, String>> listData)
{
    listAdapterActivity = ListActivity;
    data = listData;
    inflater = (LayoutInflater)listAdapterActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

}


@Override
public int getCount() {

    return data.size();

}

@Override
public Object getItem(int position) {

    return position;
}

@Override
public long getItemId(int position) {

    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) 
{
    View listItem = convertView;

    if(listItem == null)
        listItem = inflater.inflate(R.id.FeedList, null);

    ImageButton feedIcon = (ImageButton) listItem.findViewById(R.id.FeedType);
    TextView    feedTitle = (TextView) listItem.findViewById(R.id.FeedTitle);
    TextView    feedOwner = (TextView) listItem.findViewById(R.id.FeedPostedBy);
    TextView    feedContent = (TextView) listItem.findViewById(R.id.FeedContent);

    HashMap<String, String> feedData = new HashMap<String, String>();
    feedData = data.get(position);

    feedIcon.setImageResource(R.drawable.ic_launcher);
    feedTitle.setText(feedData.get("FeedTitle"));
    feedOwner.setText(feedData.get("FeedOwner"));
    feedContent.setText(feedData.get("FeedContent"));


    return listItem;
}

}

MainActivity类:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package com.tcs.internal.prime;

import java.util.ArrayList;
import java.util.HashMap;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ListView;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ArrayList<HashMap<String, String>> feedList = new ArrayList<HashMap<String,String>>();

    HashMap<String, String> data = new HashMap<String, String>();

    data.put("FeedTitle","Application crashed when launched in Windows 7");
    data.put("FeedOwner", "By Venkatramanan");
    data.put("FeedContent","Launch the financial aid adminstration in windows 7 environment");

    feedList.add(data);

    data.clear();

    data.put("FeedTitle","Application crashed when launched in Windows 8 ");
    data.put("FeedOwner", "By Siva Guru");
    data.put("FeedContent","Launch the financial aid adminstration in windows 8 environment");

    feedList.add(data);

    ListView feedListView = (ListView)findViewById(R.id.FeedList);

    ListAdapter listAdapter = new ListAdapter(this, feedList);
    feedListView.setAdapter(listAdapter);



}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}

我得到了以下异常:

android.content.res.Resources$NotFoundException:资源ID #0x7f070001类型#0x12无效

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-27 10:40:06

您只需将listview适配器的getview方法中的自定义布局扩展为

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
       listItem = inflater.inflate(R.layout.list_item, null);

而不是

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
     listItem = inflater.inflate(R.id.FeedList, null);
票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15109872

复制
相关文章
Java中常见的异常类型
类格式错误。当Java虚拟机试图从一个文件中读取Java类,而检测到该文件的内容不符合类的有效格式时抛出。
JanYork_简昀
2022/04/02
2.3K0
Java---线程多(工作内存)和内存模型(主内存)分析
转载自 https://www.cnblogs.com/chihirotan/p/6486436.html
allsmallpig
2021/02/25
2K0
JDK源码解析之 java.lang.Error
错误。是所有错误的基类,用于标识严重的程序运行问题。这些问题通常描述一些不应被应用程序捕获的反常情况。
栗筝i
2022/12/01
6280
Java-线程中的异常
给出以下例子,我想问题是线程t1运行期间抛出的异常能够被捕获吗?(这是一个相当好的问题~)
Fisherman渔夫
2020/02/19
1.5K0
cdn节点访问失败,源站测试正常,节点异常?
cdn节点测试访问异常,出现空响应,直接访问源站正常,这里看起来像是节点出现异常。
任雯霄
2020/12/30
3.8K0
java主线程捕获子线程中的异常
如果想要在主线程中捕获子线程的异常,我们需要使用ExecutorService,同时做一些修改。
Java架构师必看
2021/05/14
3K0
java主线程捕获子线程中的异常
java高级用法之:JNA中的Function
在JNA中,为了和native的function进行映射,我们可以有两种mapping方式,第一种是interface mapping,第二种是direct mapping。虽然两种方式不同,但是在具体的方法映射中,我们都需要在JAVA中定义一个和native方法进行映射的方法。
程序那些事
2022/05/17
5710
Java面试系列9
java中的保留字,现在没有在java中使用。 ✎二、必须要知道的运行时异常 ArithmeticException 是出现异常的运算条件时,抛出此异常。 例如,一个整数“除以零”时,抛出此类
Java帮帮
2018/03/19
2K0
winform 多线程中ShowDialog()步骤无效的解决办法
private void Form1_Load(object sender, EventArgs e) { Thread thread = new Thread(remind); thread.IsBackground = true; thread.Start(); } private void remind() { while (true) { string h = "0"; string m = "23";
跟着阿笨一起玩NET
2018/09/19
1.3K0
Java跨语言调用,使用JNA访问Java外部接口
先说JNI(Java Native Interface)吧,有过不同语言间通信经历的一般都知道,它允许Java代码和其他语言(尤其C/C++)写的代码进行交互,只要遵守调用约定即可。首先看下JNI调用C/C++的过程,注意写程序时自下而上,调用时自上而下。
朝雨忆轻尘
2019/06/18
4.6K0
java高级用法之:JNA中的Structure
前面我们讲到了JNA中JAVA代码和native代码的映射,虽然可以通过TypeMapper来将JAVA中的类型和native中的类型进行映射,但是native中的数据类型都是基础类型,如果native中的数据类型是复杂的struct类型该如何进行映射呢?
程序那些事
2022/05/09
1.9K0
java高级用法之:JNA中的Structure
前面我们讲到了JNA中JAVA代码和native代码的映射,虽然可以通过TypeMapper来将JAVA中的类型和native中的类型进行映射,但是native中的数据类型都是基础类型,如果native中的数据类型是复杂的struct类型该如何进行映射呢?
程序那些事
2022/05/17
6640
java高级用法之:JNA中的Function
在JNA中,为了和native的function进行映射,我们可以有两种mapping方式,第一种是interface mapping,第二种是direct mapping。虽然两种方式不同,但是在具体的方法映射中,我们都需要在JAVA中定义一个和native方法进行映射的方法。
程序那些事
2022/05/06
1K0
java高级用法之:JNA中的回调
什么是callback呢?简单点说callback就是回调通知,当我们需要在某个方法完成之后,或者某个事件触发之后,来通知进行某些特定的任务就需要用到callback了。
程序那些事
2022/05/10
1.5K0
java中的异常总结
一般面试中java Exception(runtimeException )是必会被问到的问题
哲洛不闹
2018/09/19
1.4K0
Java多线程中的内存可见性
分为主内存和线程内存,当线程与其他线程共享一个变量时,便会把主内存的变量复制到线程内存中去。当发生对变量的修改时,会同步到主内存,主内存再同步到其他线程内存中去。
zhangheng
2020/04/28
5020
异常、线程
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/100192.html原文链接:https://javaforall.cn
全栈程序员站长
2022/06/29
7660
异常、线程
RuntimeException和Exception区别
Java设置了异常,旨在鼓励将方法中可能出现的异常告知给使用此方法的程序员(你和我!)。当然了,这种方法是比较优雅的,让我们确切的知道是在哪里出了错,并提供了异常捕获。本篇文章主要对Java中的异常进行介绍与区分。
全栈程序员站长
2022/09/15
1.1K0
RuntimeException和Exception区别
WPF中UI元素跨线程访问
dotnet中线程资源独占UI元素,不能跨线程访问,可以通过Dispatcher.Invoke的方式调用,但实际处理还是UI线程中,任务量比较大的数据会增加线程的处理压力。 其实还有一种做法,可以通过设置UI元素为只读的方式,跨线程访问。 如BitmapSource跨线程访问,可以调用Freeze设置元素为只读模式。 Aforge.net跨线程传递图像资源,如下:
sofu456
2019/07/09
1.1K0
java高级用法之:JNA中的回调
什么是callback呢?简单点说callback就是回调通知,当我们需要在某个方法完成之后,或者某个事件触发之后,来通知进行某些特定的任务就需要用到callback了。
程序那些事
2022/05/17
8950

相似问题

JNA无效内存访问

13

JNA:无效内存访问

11

JNA:无效内存访问

18

JNA中的无效内存访问

16

映射JNA中的COM接口方法无效内存访问异常

13
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文