ios-应用报出了不兼容指针错误

问题描述

应用报出了不兼容指针错误
正在读取UTF8编写的txt文件。

代码:

- (NSString *) readFromFile {    NSArray *paths = NSSearchPathForDirectoriesInDomains    (NSDocumentDirectory NSUserDomainMask YES);    NSString *documentsDirectory = [paths objectAtIndex:0];    NSString *fileName = [NSString stringWithFormat:@""%@/textfile.txt""                          documentsDirectory];    return [[NSString alloc] initWithContentsOfFile:fileName                        usedEncoding:NSUTF8StringEncoding                        error:nil];}

在最后一行报错: ** incompatible integer to pointer conversion sending int to parameter of type NSUTF8StringEncoding **

请高手指点,谢谢

解决方案

usedEncoding这个参数是用来传递调用方的返回值。
因此需要声明一个变量,传递关联给它

NSStringEncoding enc;NSString *result = [[NSString alloc] initWithContentsOfFile:fileName                    usedEncoding: &enc                    error:nil];// Do something with the information about the encoding usedif ( enc == NSUTF8StringEncoding ) {     // ...}return result;
时间: 2024-08-03 01:14:59

ios-应用报出了不兼容指针错误的相关文章

C++系统中指针错误,添加不了对象,真的很急!!!!

问题描述 C++系统中指针错误,添加不了对象,真的很急!!!! 为什么不能实现添加啊!!!!!真的很急 #include <iostream>#include <iomanip>#include <conio.h>#include <string>#include <fstream>#include <cstdlib>using namespace std;int i=0;const int Maxp=100;//最大商品类的数量cl

请问在调用自定义控件的button事件时会有空指针错误

问题描述 请问在调用自定义控件的button事件时会有空指针错误 出错的代码如下,是菜单中的按钮事件,点击就会出现空指针错误.如果把setOnClickListener注释掉就不会出错.请问各位为什么会报错呢?代码如下. public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()){ case 1: LayoutInflater inflater = getLayoutInflater(); View

ios 上线的版本推送通知错误

问题描述 ios 上线的版本推送通知错误 我在-(void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken{},将获得的deviceToken保存到了本地,开发测试的时候都是好的,但是等到上线了,从商店里下载下来的应用却在本地文件里没有发现保存的deviceToken,我的推断是没有调用这个方法,但在真机测试的时候都是好的,求

智能车-用IAR 编写K60程序,报出关于memory map的错误。

问题描述 用IAR 编写K60程序,报出关于memory map的错误. there has already included a memory map.Only one memory map can be included. 解决方案 http://wenku.baidu.com/link?url=zjVdhUXmEnn3kcGfoXTpp6jz3FqlC0J_VSoK4_c7SgkH7mO2EHqTxLb3bjWlV4iICiAP6uIuz3Vg6MPEBae9XOKVZuOrmXRCAA5

求助ios上线的时候报的90037错误,一直没解决掉,在线等~

问题描述 求助ios上线的时候报的90037错误,一直没解决掉,在线等~ 打包成功以后,上传的时候报错,ERROR ITMS-90037: ""This bundle is invalid. The Info.plist file is missing or could not be parsed. Please check it for embedded control characters."" 请大神帮忙~ 解决方案 你的工程是否正确填了bundle信息. 解

c++-什么情况下会在未进入主函数前报非法指针错误

问题描述 什么情况下会在未进入主函数前报非法指针错误 在使用VS2005编译MFC的工程,在未进入主函数前就报非法指针错误. 解决方案 请在Debug模式下打开call stack,看看函数调用堆栈,找到出错的函数调用. 解决方案二: 全局变量初始化的时候就出错了呀.

mfc-MFC在停靠窗口里获取当前文档指针错误

问题描述 MFC在停靠窗口里获取当前文档指针错误 void CPropertiesWnd::OnTimer(UINT_PTR nIDEvent) { if(nIDEvent == 10) { CMainFrame* pMainFrm = (CMainFrame*)AfxGetMainWnd(); CMyMDI1Doc* cur_doc = (CMyMDI1Doc*)pMainFrm->GetActiveDocument(); if (cur_doc->vector_ddd.size() >

ios 支付宝网页支付 总是显示参数错误是怎莫回事

问题描述 ios 支付宝网页支付 总是显示参数错误是怎莫回事 partner="2088811116320160"&seller_id="jms@jimaisong.com"&out_trade_no="7TC5SNSTPWZBMP8"&subject="哇哈哈"&body="有营养"&total_fee="0.10"&notify_url

一个c语言的链表问题,总是产生垃圾值,好几个指针错误找不到。

问题描述 一个c语言的链表问题,总是产生垃圾值,好几个指针错误找不到. #include #include typedef int ElemType; typedef struct LNode{ ElemType data; struct LNode *next; }LNode,*LinkList; typedef int Status; Status ListInsert_L(LinkList *L,int i,ElemType e) { LinkList p,s; int j=0; p=*L