android片段android.view.InflateException:二进制XML文件行#7:膨胀类片段时出错
嗨,我运行应用程序时正在创建静态callLogfragment,我收到错误。查看我的代码am get android.view.InflateException:二进制XML文件行#7:在catlog中引发类片段异常时出错,如何重新处理此错误android片段android.view.InflateException:二进制XML文件行#7:膨胀类片段时出错,android,android-fragments,Android,Android Fragments,嗨,我运行应用程序时正在创建静态callLogfragment,我收到错误。查看我的代码am get android.view.InflateException:二进制XML文件行#7:在catlog中引发类片段异常时出错,如何重新处理此错误 //CALL LOGS MAINActivity class public class FragmentCallLogActivity extends Activity { @Override protect
//CALL LOGS MAINActivity class
public class FragmentCallLogActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frament_logs_main);
}
}
/// main XML file
<LinearLayout 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"
android:orientation="vertical" >
<fragment
android:id="@+id/call_log_fragment"
android:name="com.exmple.fragmnetcalllogs.CallLogsFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
//Call Log Fragment class
public class CallLogsFragment extends Fragment {
private List<CallLogModel> callLogModelList;
private CallLogModel callLogModel;
private ListView callLogListView;
private CallLogsArrayAdapter customAdapter;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View callLogsmanagerView = inflater.inflate(
R.layout.fragment_call_history, container, false);
callLogListView = (ListView) container
.findViewById(R.id.call_logs_history);
return callLogsmanagerView;
}
@Override
public void onStart() {
super.onStart();
// creating ArrayList Object
callLogModelList = new ArrayList<CallLogModel>();
// calling fetchCallLogs method
fetchCallLogs();
// creating custom adapter
customAdapter = new CallLogsArrayAdapter(getActivity(),
R.id.call_logs_history, callLogModelList);
// setting values in to list view
callLogListView.setAdapter(customAdapter);
}
// reading call logs from contentReslover
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void fetchCallLogs() {
Cursor callLog = getActivity().getContentResolver().query(
CallLog.Calls.CONTENT_URI, null, null, null,
android.provider.CallLog.Calls.DATE + " DESC");
int cid = callLog.getColumnIndex(CallLog.Calls._ID);
int cName = callLog.getColumnIndex(CallLog.Calls.CACHED_NAME);
int cNumber = callLog.getColumnIndex(CallLog.Calls.NUMBER);
int cType = callLog.getColumnIndex(CallLog.Calls.TYPE);
int cDate = callLog.getColumnIndex(CallLog.Calls.DATE);
int cDuration = callLog.getColumnIndex(CallLog.Calls.DURATION);
// looping call log cursor object
while (callLog.moveToNext()) {
String mId = callLog.getString(cid);
String mName = callLog.getString(cName);
String mNumber = callLog.getString(cNumber);
long mCallDate = callLog.getLong(cDate);
long currentDate = System.currentTimeMillis();
String dateString = getDateTime(mCallDate, currentDate);
String mCallDuration = callLog.getString(cDuration);
if (mName == null) {
mName = " Unknown";
}
if (mNumber == null) {
mNumber = "No Number";
}
int type = 0;
switch (cType) {
case CallLog.Calls.OUTGOING_TYPE:
type = R.drawable.log_out;
break;
case CallLog.Calls.INCOMING_TYPE:
type = R.drawable.log_in;
break;
case CallLog.Calls.MISSED_TYPE:
type = R.drawable.log_miss;
break;
}
Bitmap cPhoto = getContactImage(mNumber);
callLogModel = new CallLogModel(mId, mName, mNumber, mCallDuration,
dateString, type, cPhoto);
callLogModelList.add(callLogModel);
}
callLog.close();
}
// calculate difference between date and time
@SuppressWarnings("deprecation")
private String getDateTime(long callDate, long currentDate) {
// creating String Buffer Class object
StringBuffer tempDate = new StringBuffer();
// Calculate difference in milliseconds
long day = currentDate - callDate;
if ((day / 1000) < 60) {
tempDate.append(day / 1000).append(" Secs Ago");
} else if ((day / (60 * 1000) < 60)) {
tempDate.append(day / (60 * 1000)).append(" Mins Ago");
}
// else if ((day / (60 * 60 * 1000)) < 24) {
else if ((new Date(callDate).getDate()) == (new Date(currentDate))
.getDate()) {
SimpleDateFormat format = new SimpleDateFormat(" hh:mm a ");
tempDate.append("Today").append(format.format(new Date(callDate)));
} else if ((day / (24 * 60 * 60 * 1000)) < 8) {
tempDate.append((day / (24 * 60 * 60 * 1000))).append(" Days Ago");
} else {
SimpleDateFormat parseFormat = new SimpleDateFormat("dd MMM",
Locale.ENGLISH);
tempDate.append(parseFormat.format(new Date(callDate)));
}
return tempDate.toString();
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private Bitmap getContactImage(String mNumber) {
Bitmap cPhoto = null;
BufferedInputStream buf_stream = null;
Cursor cursorPhoto = getActivity().getContentResolver().query(
Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
Uri.decode(mNumber)), new String[] { PhoneLookup._ID },
null, null, null);
InputStream photo_stream = null;
if (cursorPhoto.moveToFirst()) {
String contactId = cursorPhoto.getString(0);
Uri contactPhotoUri = ContentUris.withAppendedId(
ContactsContract.Contacts.CONTENT_URI,
Long.parseLong(contactId));
try {
photo_stream = ContactsContract.Contacts
.openContactPhotoInputStream(getActivity()
.getContentResolver(), contactPhotoUri);
buf_stream = new BufferedInputStream(photo_stream);
cPhoto = BitmapFactory.decodeStream(buf_stream);
// buf_stream.close();
// photo_stream.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (buf_stream != null && photo_stream != null) {
try {
buf_stream.close();
photo_stream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
cursorPhoto.close();
return cPhoto;
}
}
//call log fragmnet xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/call_history"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/call_logs_history"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
// call log Adapter class
public class CallLogsArrayAdapter extends ArrayAdapter<CallLogModel> {
private LayoutInflater inflater;
private TextView mName, mDate, mNumber;
private ImageView mPhoto, mType;
// private ImageButton type;
Context context;
int resourceId;
/* Constructor */
public CallLogsArrayAdapter(Context context, int resourceID,
List<CallLogModel> callLogsList) {
super(context, resourceID, callLogsList);
this.context = context;
this.resourceId = resourceID;
// Cache the LayoutInflate to avoid asking for a new one each time.
inflater = LayoutInflater.from(context);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Contact to display
final CallLogModel callLogModel = this.getItem(position);
convertView = inflater.inflate(R.layout.call_log_list, null);
// Find the child views.
mPhoto = (ImageView) convertView.findViewById(R.id.call_log_photo);
mName = (TextView) convertView.findViewById(R.id.call_log_name);
mNumber = (TextView) convertView.findViewById(R.id.call_log_number);
mDate = (TextView) convertView.findViewById(R.id.call_log_date);
mType = (ImageView) convertView.findViewById(R.id.call_log_type);
// setting values in to view objects
if (callLogModel.getPhoto() != null) {
mPhoto.setImageBitmap(callLogModel.getPhoto());
}
mName.setText(callLogModel.getName());
mDate.setText(callLogModel.getDate());
mNumber.setText(callLogModel.getNumber());
mType.setImageResource(callLogModel.getType());
return convertView;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return super.getCount();
}
}
// call log adpater xml file
<?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="72dp"
android:background="@color/Gray" >
<ImageView
android:id="@+id/call_log_photo"
android:layout_width="72dp"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginBottom="12dp"
android:layout_marginTop="12dp"
android:contentDescription="@string/app_name"
android:src="@drawable/log_default" />
<TextView
android:id="@+id/call_log_name"
android:layout_width="120dp"
android:layout_height="30dp"
android:layout_alignLeft="@+id/call_log_number"
android:layout_alignParentTop="true"
android:layout_marginTop="6dp"
android:gravity="left"
android:paddingLeft="4dp"
android:text="@string/app_name"
android:textSize="12sp" />
<TextView
android:id="@+id/call_log_number"
android:layout_width="120dp"
android:layout_height="30dp"
android:layout_below="@+id/call_log_name"
android:layout_marginBottom="6dp"
android:layout_toRightOf="@+id/call_log_photo"
android:gravity="left"
android:paddingLeft="4dp"
android:text="@string/app_name"
android:textSize="12sp" />
<TextView
android:id="@+id/call_log_date"
android:layout_width="60dp"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/call_log_type"
android:layout_below="@+id/call_log_type"
android:layout_toRightOf="@+id/call_log_name"
android:text="@string/app_name"
android:textSize="12sp" />
<ImageView
android:id="@+id/call_log_type"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/call_log_photo"
android:layout_marginRight="16dp"
android:contentDescription="@string/app_name"
android:src="@drawable/log_out" />
</RelativeLayout>
/// finally call log Model class
public class CallLogModel {
private String id;
private String name;
private String number;
private String duration;
private String date;
private int type;
private Bitmap photo;
public CallLogModel(String id, String name, String number, String duration,
String date, int type, Bitmap photo) {
this.id = id;
this.name = name;
this.number = number;
this.duration = duration;
this.date = date;
this.type = type;
this.photo = photo;
}
public Bitmap getPhoto() {
return photo;
}
public String getId() {
return id;
}
public int getType() {
return type;
}
public String getName() {
return name;
}
public String getNumber() {
return number;
}
public String getDuration() {
return duration;
}
public String getDate() {
return date;
}
}
help me am getting below error messages in my cat log
----------------------------------------------------------
adid=1: thread exiting with uncaught exception (group=0x409961f8)
05-30 09:41:10.503: E/AndroidRuntime(742): FATAL EXCEPTION: main
05-30 09:41:10.503: E/AndroidRuntime(742): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aspiresys.fragmnetcalllogs/com.aspiresys.fragmnetcalllogs.FragmentCallLogActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
05-30 09:41:10.503: E/AndroidRuntime(742): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.app.ActivityThread.access$600(ActivityThread.java:122)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.os.Handler.dispatchMessage(Handler.java:99)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.os.Looper.loop(Looper.java:137)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.app.ActivityThread.main(ActivityThread.java:4340)
05-30 09:41:10.503: E/AndroidRuntime(742): at java.lang.reflect.Method.invokeNative(Native Method)
05-30 09:41:10.503: E/AndroidRuntime(742): at java.lang.reflect.Method.invoke(Method.java:511)
05-30 09:41:10.503: E/AndroidRuntime(742): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-30 09:41:10.503: E/AndroidRuntime(742): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-30 09:41:10.503: E/AndroidRuntime(742): at dalvik.system.NativeStart.main(Native Method)
05-30 09:41:10.503: E/AndroidRuntime(742): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
05-30 09:41:10.503: E/AndroidRuntime(742): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-30 09:41:10.503: E/AndroidRuntime(742): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.app.Activity.setContentView(Activity.java:1835)
05-30 09:41:10.503: E/AndroidRuntime(742): at com.aspiresys.fragmnetcalllogs.FragmentCallLogActivity.onCreate(FragmentCallLogActivity.java:11)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.app.Activity.performCreate(Activity.java:4465)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
05-30 09:41:10.503: E/AndroidRuntime(742): ... 11 more
05-30 09:41:10.503: E/AndroidRuntime(742): Caused by: java.lang.NullPointerException
05-30 09:41:10.503: E/AndroidRuntime(742): at com.aspiresys.fragmnetcalllogs.CallLogsFragment.onCreateView(CallLogsFragment.java:45)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:773)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:977)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1056)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.app.Activity.onCreateView(Activity.java:4243)
05-30 09:41:10.503: E/AndroidRuntime(742): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
//调用日志MAINActivity类
公共类FragmentCallLogActivity扩展活动{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u frament\u logs\u main);
}
}
///主XML文件
//调用日志片段类
公共类CallLogsFragment扩展了片段{
私有列表callLogModelList;
私有CallLogModel CallLogModel;
私有ListView调用LogListView;
私有CallLogsArrayAdapter自定义适配器;
@TargetApi(构建版本代码蜂窝)
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
查看调用LogsManager视图=充气机。充气(
R.layout.fragment_调用_历史记录,容器,false);
callLogListView=(ListView)容器
.findviewbyd(R.id.call\u logs\u history);
返回CallLogsManager视图;
}
@凌驾
public void onStart(){
super.onStart();
//创建ArrayList对象
callLogModelList=newArrayList();
//调用fetchCallLogs方法
fetchCallLogs();
//创建自定义适配器
customAdapter=new CallLogsArrayAdapter(getActivity(),
R.id.call\u日志\u历史记录,callLogModelList);
//在列表视图中设置值
callLogListView.setAdapter(customAdapter);
}
//从contentReslover读取呼叫日志
@TargetApi(构建版本代码蜂窝)
public void fetchCallLogs(){
游标调用日志=getActivity().getContentResolver().query(
CallLog.Calls.CONTENT_URI,null,null,null,
android.provider.CallLog.Calls.DATE+“DESC”);
int cid=callLog.getColumnIndex(callLog.Calls.\u ID);
int cName=callLog.getColumnIndex(callLog.Calls.CACHED_NAME);
int cNumber=callLog.getColumnIndex(callLog.Calls.NUMBER);
int cType=callLog.getColumnIndex(callLog.Calls.TYPE);
int cDate=callLog.getColumnIndex(callLog.Calls.DATE);
int cDuration=callLog.getColumnIndex(callLog.Calls.DURATION);
//循环调用日志游标对象
while(callLog.moveToNext()){
String mId=callLog.getString(cid);
String mName=callLog.getString(cName);
字符串mNumber=callLog.getString(cNumber);
long mCallDate=callLog.getLong(cDate);
长currentDate=System.currentTimeMillis();
String dateString=getDateTime(mCallDate,currentDate);
String mCallDuration=callLog.getString(cDuration);
if(mName==null){
mName=“未知”;
}
if(mNumber==null){
mNumber=“无编号”;
}
int类型=0;
开关(cType){
案例CallLog.Calls.OUTGOING_类型:
类型=R.drawable.log\u out;
打破
案例CallLog.Calls.INCOMING_类型:
type=R.drawable.log\u in;
打破
案例CallLog.Calls.MISSED_类型:
类型=R.drawable.log\u未命中;
打破
}
位图cPhoto=getContactImage(mNumber);
callLogModel=新的callLogModel(mId、mName、mNumber、mCallDuration、,
日期字符串,类型,cPhoto);
添加(callLogModel);
}
callLog.close();
}
//计算日期和时间之间的差异
@抑制警告(“弃用”)
私有字符串getDateTime(长callDate、长currentDate){
//创建字符串缓冲区类对象
StringBuffer tempDate=新的StringBuffer();
//以毫秒为单位计算差异
长日=当前日期-调用日期;
如果((天/1000)<60){
tempDate.append(天/1000.append(“秒前”);
}否则,如果((天/(60*1000)<60)){
tempDate.append(天/(60*1000)).append(“分钟前”);
}
//如果((天/(60*60*1000))<24){
else if((新日期(callDate).getDate())==(新日期(currentDate))
.getDate()){
SimpleDataFormat格式=新的SimpleDataFormat(“hh:mm a”);
tempDate.append(“今天”).append(format.format(newdate(callDate)));
}如果((天/(24*60*60*1000))<8){
tempDate.append((天/(24*60*60*1000)).append(“几天前”);
}否则{
SimpleDataFormat parseFormat=新的SimpleDataFormat(“dd MMM”,
语言环境(英语);
append(parseFormat.format(newdate(callDate)));
}
返回tempDate.toString();
}
@TargetApi(构建版本代码蜂窝)
私有位图getContactImage(字符串mNumber){
位图cPhoto=null;
BufferedInputStream buf_stream=null;
游标cursorPhoto=getActivity().getContentResolver().query(
withAppendedPath(PhoneLookup.CONTENT\u FILTER\u Uri,
Uri.decode(mNumber)),新字符串[]{PhoneLookup.\u ID},
努尔
callLogListView = (ListView) container.findViewById(R.id.call_logs_history);
callLogListView = (ListView) callLogsmanagerView.findViewById(R.id.call_logs_history);