当前位置: 编程技术>移动开发
本页文章导读:
▪Undefined symbols for architecture i386 异常 Undefined symbols for architecture i386 错误
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_CLLocationManager", referenced from:
objc-class-ref in HotelQueryViewController.o
ld: symbol(s) not found for architecture i386
.........
▪ 施用消息机制原理列出所有的文件 使用消息机制原理列出所有的文件消息机制这个玩意儿,理解起来还是有点费劲的。要理解清楚的话需要对线程有很好的理解,出此之外还要掌握好消息机制的用法。这里我用的是Android里的.........
▪ 不用在pthread线程中使用printf() 不要在pthread线程中使用printf()创建一个线程,printf()一些信息,
void *thread_dsp_comm(void *arg)
{
printf("in thread\n");
while (1) {
printf("I am here\n");
sl.........
[1]Undefined symbols for architecture i386 异常
来源: 互联网 发布时间: 2014-02-18
Undefined symbols for architecture i386 错误
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_CLLocationManager", referenced from:
objc-class-ref in HotelQueryViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是今天弄百度地图api发现的错误,出现这个错误就是在项目中缺少框架
只要导入一个框架即可----CoreLocation.framework。
[2] 施用消息机制原理列出所有的文件
来源: 互联网 发布时间: 2014-02-18
使用消息机制原理列出所有的文件
下面是辅助界面
2.下面先来这个比较复杂的类,这个类继承AsyncTask
这里代码不是很复杂关键在于理解,我们执行后台任务的时候传递的是文件对象,更新主界面UI返回的是File类型,返回的信息则是string类型。
代码看起来有点多,但是这的确是个很好的例子,下面来看看效果图
消息机制这个玩意儿,理解起来还是有点费劲的。要理解清楚的话需要对线程有很好的理解,出此之外还要掌握好消息机制的用法。这里我用的是Android里的一个工具类叫AsyncTask,这个类使用泛型指定了3个参数。第一个参数是启动任务需要的参数类型,第二个参数表示后台执行任务的百分比,第三个参数表示任务完成之后返回的信息。下面就一步一步的做这个小例子。
1.主界面准备一个ListView来显示文件信息,辅助界面是信息的主体如下所示
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
下面是辅助界面
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TableRow>
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</TableRow>
</TableLayout>
2.下面先来这个比较复杂的类,这个类继承AsyncTask
private class ListFileTools extends AsyncTask<File, File, String>{
@Override
protected void onProgressUpdate(File... values) {
Map<String,Object> fileItem=new HashMap<String, Object>();
//如果为目录
if(values[0].isDirectory()){
fileItem.put("img", R.drawable.folder_close);
}else{
fileItem.put("img", R.drawable.file);
}
fileItem.put("name", values[0]);
ListActivity.this.allFileItems.add(fileItem);
//包装数据
ListActivity.this.simple=new SimpleAdapter(ListActivity.this,
allFileItems, R.layout.file_list, new String[]{"img","name"}, new int[]{R.id.img,R.id.name});
ListActivity.this.fileList.setAdapter(ListActivity.this.simple);
}
@Override
protected String doInBackground(File... params) {
if(!params[0].getPath().equals(java.io.File.separator)){
Map<String,Object> fileItem=new HashMap<String, Object>();
fileItem.put("img", R.drawable.folder_open);
fileItem.put("name", params[0].getParentFile());
ListActivity.this.allFileItems.add(fileItem);
}
if(params[0].isDirectory()){
File tempFile[]=params[0].listFiles();
if(tempFile!=null){
for(int i=0;i<tempFile.length;i++){
this.publishProgress(tempFile[i]);
}
}
}
return "文件已经列出";
}
}这里代码不是很复杂关键在于理解,我们执行后台任务的时候传递的是文件对象,更新主界面UI返回的是File类型,返回的信息则是string类型。
3.activity载入的时候我们需要执行后台任务,列出一级文件夹和文件,listview被点击时也执行这个任务列出子文件夹的信息
private List<Map<String,Object>> allFileItems=new ArrayList<Map<String,Object>>();
private SimpleAdapter simple=null;
private ListView fileList=null;
private ListFileTools tools=null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.fileList=(ListView)super.findViewById(R.id.list);
//从根目录列出所有文件
File filePath=new File(java.io.File.separator);
//定义子任务
tools=new ListFileTools();
tools.execute(filePath);
this.fileList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
File currentFile=(File)ListActivity.this.allFileItems.get(position).get("name");
if(currentFile.isDirectory()){
ListActivity.this.allFileItems=new ArrayList<Map<String,Object>>();
ListFileTools tool=new ListFileTools();
tool.execute(currentFile);
}
}
});
}代码看起来有点多,但是这的确是个很好的例子,下面来看看效果图
[3] 不用在pthread线程中使用printf()
来源: 互联网 发布时间: 2014-02-18
不要在pthread线程中使用printf()
创建一个线程,printf()一些信息,
void *thread_dsp_comm(void *arg)
{
printf("in thread\n");
while (1) {
printf("I am here\n");
sleep_sec(1);
}
printf("thread exit\n");
return NULL;
}
在主线程中,cancel然后join,
pthread_cancel(m_thread);
pthread_join(m_thread, &res);
如果打开线程中的printf(),会导致pthread_join死机,线程也不会打印"I am here"
。即使你用信号量保护printf()也没有用。去掉printf(),一切正常。
可能是arm-2012.09-64-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2库的
原因。
创建一个线程,printf()一些信息,
void *thread_dsp_comm(void *arg)
{
printf("in thread\n");
while (1) {
printf("I am here\n");
sleep_sec(1);
}
printf("thread exit\n");
return NULL;
}
在主线程中,cancel然后join,
pthread_cancel(m_thread);
pthread_join(m_thread, &res);
如果打开线程中的printf(),会导致pthread_join死机,线程也不会打印"I am here"
。即使你用信号量保护printf()也没有用。去掉printf(),一切正常。
可能是arm-2012.09-64-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2库的
原因。
最新技术文章: