-1

this is the error that i've got

12-05 13:26:18.102: E/AndroidRuntime(10101): FATAL EXCEPTION: main
12-05 13:26:18.102: E/AndroidRuntime(10101): Process: com.example.project_1_4, PID: 10101
12-05 13:26:18.102: E/AndroidRuntime(10101): java.lang.RuntimeException: Unable to start activity         
ComponentInfo{com.example.project_1_4/          
com.example.project_1_4.MainActivity}: android.view.InflateException: Binary XML file line #14:     
Error inflating class fragment

my xml file - i think i missed bracket when i was posting. now i correct it.

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
        <ListView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="410dp" >
        </ListView>
</LinearLayout>

source code

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.zip.Inflater;

import android.app.ListFragment;
import android.content.Context;
import android.os.Bundle;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

public class Dday_fragment extends ListFragment{

    ArrayList<Detail> detailList = new ArrayList<Detail>();
    ArrayList<String> detailName = new ArrayList<String>();
    DetailOperation DetailDBOperation;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        View view = new View(getActivity());
        try{
        view = inflater.inflate(R.layout.dday_fragment, container, false);
        }catch (InflateException e){
        }

        DetailDBOperation = new DetailOperation(null);
        try {
            DetailDBOperation.open();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        if(DetailDBOperation.getAllDetail()!=null){
        detailList = DetailDBOperation.getAllDetail();
        }else{
            detailList = null;
        }

        int size = detailList.size();

        for(int i = 0; i < size; i++){
            detailName.add(detailList.get(i).getSubjectName());
        }
        ArrayAdapter<String> adapter = 
                new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, detailName);
        setListAdapter(adapter);
        return view;
    }
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
        super.onListItemClick(l, v, position, id);
        Detail_fragment dtf = (Detail_fragment) getFragmentManager().findFragmentById(R.layout.detail_fragment);
        dtf.change(position);
        getListView().setSelector(android.R.color.holo_red_dark);
    }

}

this is the full code of Dday_fragment.java how can i use onListItemClick if i don't use ListFragment? what i want is to show list of items in dday_fragment, and there is another xml that changes with item id which is selected by user. another xml will shows details of item. so i used onListItemClick to change and set text on another xml.

3 Answers3

0

You need to use ">" tag for LinearLayout.

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

another thing is you have inflated view in onCreateView() method and also you are trying to create instance of View twice so there is problem. No need to do this. So just change

 @Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {

  try{

     View  view = inflater.inflate(R.layout.dday_fragment, container, false);

  } catch (InflateException e){
  }

  DetailDBOperation = new DetailOperation(getActivity());
  try {
    DetailDBOperation.open();
  } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
Piyush
  • 18,895
  • 5
  • 32
  • 63
  • at the end of this onCreateView, don't i need to return view? if i do that it says 'view cannnot be resolved as a variable'. return view; <--- – SooHwan Chae Dec 05 '14 at 13:19
0

There is a problem with your Layout XML file. Make sure you close the brackets which is opened. Here is what you missed.

<LinearLayout> </LinearLayout>

Alternate way to do this is:

<LinearLayout />
Paresh P.
  • 6,677
  • 1
  • 14
  • 26
0

You forgot to declare attribute end enclose. Please do like below :

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
        <ListView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="410dp" >
        </ListView>
</LinearLayout>
Pratik Dasa
  • 7,439
  • 4
  • 30
  • 44