问题描述:

Hoping someone might be able to help me with this. Been trying to fix it for a few hours now - in logcat below I believe the important line is the one with Error inflating class. I've posted my code below. The package compiles but shuts down straight away on my phone when I run it.

Thanks for any help.

I saw similar questions with drawable or OutOfMemoryError solutions but none of them seemed to be relevant to my issue.

02-12 10:38:55.390 31692-31692/com.example.chris.sunil_gupta D/dalvikvm﹕ Late-enabling CheckJNI

02-12 10:38:55.400 31692-31698/com.example.chris.sunil_gupta E/jdwp﹕ Failed writing handshake bytes: Broken pipe (-1 of 14)

02-12 10:38:55.400 31692-31698/com.example.chris.sunil_gupta D/dalvikvm﹕ Debugger has detached; object registry had 0 entries

02-12 10:38:55.420 31692-31692/com.example.chris.sunil_gupta D/ActivityThread﹕ setTargetHeapUtilization:0.75

02-12 10:38:55.420 31692-31692/com.example.chris.sunil_gupta D/ActivityThread﹕ setTargetHeapConcurrentStart:2097152

02-12 10:38:55.450 31692-31692/com.example.chris.sunil_gupta D/AndroidRuntime﹕ Shutting down VM

02-12 10:38:55.450 31692-31692/com.example.chris.sunil_gupta W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x415998e0)

02-12 10:38:55.450 31692-31692/com.example.chris.sunil_gupta E/AndroidRuntime﹕ FATAL EXCEPTION: main

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.chris.sunil_gupta/com.example.chris.sunil_gupta.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class linearlayout

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)

at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)

at android.app.ActivityThread.access$900(ActivityThread.java:148)

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1319)

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.chris.sunil_gupta" >

<uses-permission android:name="android.permission.READ_CALL_LOG"/>

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

<activity

android:name=".MainActivity"

android:label="@string/app_name" >

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

</manifest>

MainActivity.java

package com.example.chris.sunil_gupta;

import java.util.ArrayList;

import java.util.Date;

import java.util.List;

import android.app.Activity;

import android.content.Context;

import android.database.Cursor;

import android.os.Bundle;

import android.provider.CallLog;

import android.widget.ListView;

public class MainActivity extends Activity {

private ListView listview=null;

private String callType=null;

private String phoneNumber=null;

private String callDate=null;

private String callDuration=null;

private Date callDateTime=null;

private List <CallData>list = new ArrayList<CallData>();

private Context context=null;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

context=this;

listview=(ListView)findViewById(R.id.listView_calldata);

getCallDetails();

CustomAdapter adapter = new CustomAdapter(MainActivity.this, list);

listview.setAdapter(adapter);

}

public void getCallDetails()

{

@SuppressWarnings("deprecation")

Cursor managedCursor = managedQuery( CallLog.Calls.CONTENT_URI,null, null,null, null);

int number = managedCursor.getColumnIndex( CallLog.Calls.NUMBER );

int type = managedCursor.getColumnIndex( CallLog.Calls.TYPE );

int date = managedCursor.getColumnIndex( CallLog.Calls.DATE);

int duration = managedCursor.getColumnIndex( CallLog.Calls.DURATION);

while (managedCursor.moveToNext())

{

phoneNumber = managedCursor.getString(number);

callType = managedCursor.getString(type);

callDate = managedCursor.getString(date);

callDateTime = new Date(Long.valueOf(callDate));

callDuration = managedCursor.getString(duration);

String cType = null;

int cTypeCode = Integer.parseInt(callType);

switch(cTypeCode)

{

case CallLog.Calls.OUTGOING_TYPE:

cType = "OUTGOING";

break;

case CallLog.Calls.INCOMING_TYPE:

cType= "INCOMING";

break;

case CallLog.Calls.MISSED_TYPE:

cType = "MISSED";

break;

}

CallData calldata=new CallData(cType, phoneNumber, callDateTime, callDuration);

list.add(calldata);

}

managedCursor.close();

}

}

CustomAdapter.java

package com.example.chris.sunil_gupta;

import java.util.Date;

import java.util.List;

import android.app.Activity;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.ArrayAdapter;

import android.widget.TextView;

public class CustomAdapter extends ArrayAdapter<CallData>{

private List <CallData> listdata=null;

private LayoutInflater mInflater=null;

public CustomAdapter(Activity context, List <CallData> calldata) {

super(context, 0);

this.listdata=calldata;

mInflater = context.getLayoutInflater();

}

@Override

public int getCount() {

return listdata.size();

}

public View getView(int position, View convertView, ViewGroup parent) {

final ViewHolder holder;

if (convertView == null || convertView.getTag() == null) {

holder = new ViewHolder();

convertView = mInflater.inflate(R.layout.list_row, null);

holder.callnumber = (TextView) convertView.findViewById(R.id.textView_callnumber);

holder.calltype = (TextView) convertView.findViewById(R.id.textView_calltype);

holder.calldate = (TextView) convertView.findViewById(R.id.textView_calldate);

holder.callduration = (TextView) convertView.findViewById(R.id.textView_callduration);

convertView.setTag(holder);

}

else {

holder = (ViewHolder) convertView.getTag();

}

CallData calldatalist = listdata.get(position);

String callnumber=calldatalist.getCallnumber();

String calltype=calldatalist.getCalltype();

Date calldate= calldatalist.getCalldatetime();

String callduration=calldatalist.getCallduration();

holder.callnumber.setText("Call Number: "+callnumber);

holder.calltype.setText("Call Type: "+calltype);

holder.calldate.setText("Call Date: "+String.valueOf(calldate));

holder.callduration.setText("Duration: "+callduration);

return convertView;

}

private static class ViewHolder {

TextView callnumber;

TextView calltype;

TextView calldate;

TextView callduration;

}

}

CallData.java

package com.example.chris.sunil_gupta;

import java.io.Serializable;

import java.util.Date;

public class CallData implements Serializable{

private String calltype;

private String callnumber;

private Date calldatetime;

private String callduration;

public CallData()

{

}

public CallData(String calltype, String callnumber, Date calldatetime, String callduration)

{

this.calldatetime=calldatetime;

this.callduration=callduration;

this.callnumber=callnumber;

this.calltype=calltype;

}

public String getCalltype() {

return calltype;

}

public void setCalltype(String calltype) {

this.calltype = calltype;

}

public String getCallnumber() {

return callnumber;

}

public void setCallnumber(String callnumber) {

this.callnumber = callnumber;

}

public Date getCalldatetime() {

return calldatetime;

}

public void setCalldatetime(Date calldatetime) {

this.calldatetime = calldatetime;

}

public String getCallduration() {

return callduration;

}

public void setCallduration(String callduration) {

this.callduration = callduration;

}

}

activity_main.xml

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/LinearLayout1"

android:layout_height="match_parent"

android:layout_width="match_parent"

android:orientation="vertical"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context=".MainActivity">

<listview android:id="@+id/listView_calldata"

android:layout_height="wrap_content"

android:layout_width="match_parent">

</listview>

</linearlayout>

list_row.xml

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_height="match_parent"

android:layout_width="match_parent"

android:orientation="vertical">

<linearlayout android:layout_height="wrap_content"

android:layout_width="match_parent"

android:orientation="vertical">

<textview android:id="@+id/textView_calltype"

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:text="TextView">

<textview android:id="@+id/textView_callnumber"

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:text="TextView_callnumber">

<textview android:id="@+id/textView_calldate"

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:text="TextView">

<textview android:id="@+id/textView_callduration"

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:text="TextView">

</textview>

</textview>

</textview>

</textview>

</linearlayout>

</linearlayout>

网友答案:

change

list_row.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
    android:id="@+id/textView_calltype"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

<Textview
    android:id="@+id/textView_callnumber"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView_callnumber" />

<TextView
    android:id="@+id/textView_calldate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

<TextView
    android:id="@+id/textView_callduration"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />


</LinearLayout>

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

<ListView android:id="@+id/listView_calldata"
    android:layout_height="wrap_content"
    android:layout_width="match_parent">
</ListView>

</LinearLayout>

Also correct the Tag names in Activity too.

网友答案:

You are using

<linearlayout> instead of <LinearLayout>

Just replace that and try again ! Hopefully you'll get success !

网友答案:

You're using a wrong xmls tags in activity_main.xml and list_row.xml files, you need to change them:

linearlayout -> LinearLayout

textview -> TextView

listview -> ListView

相关阅读:
Top