Eclipse ListFragment class stürtzt immer ab LOG CAT DABEI !

  • Antworten:1
Lukas R.
  • Forum-Beiträge: 180

28.04.2014, 18:48:45 via Website

Hallo habe mir via ListFragment eine Custom ListView erstellen wollen.... Das problem ist dass mir im Code selber keine Fehler angezeigt werden aber wenn ich die App starte stürtzt sie sofort ab.... Ich werde auch aus der logcat nicht schlau aber vll könnt ihr mir helfen

Hier ein Ausschnitt der Logcat wo sie abstürtzt! image

Und hier der Code von der java:

 import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;



import android.content.Context;

import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class Mitglieder extends ListFragment {

 public class MyListAdapter extends ArrayAdapter<String> {

  Context myContext;

  public MyListAdapter(Context context, int textViewResourceId,
    String[] objects) {
   super(context, textViewResourceId, objects);
   myContext = context;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
   //return super.getView(position, convertView, parent);

   LayoutInflater inflater = 
     (LayoutInflater)myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   View row=inflater.inflate(R.layout.mitglieder, parent, false);
   TextView label=(TextView)row.findViewById(R.id.month);
   label.setText(month[position]);
   ImageView icon=(ImageView)row.findViewById(R.id.icon);

   //Customize your icon here
   icon.setImageResource(R.drawable.ic_launcher);

   return row;
  }

 }

 String[] month ={
   "January", 
   "February", 
   "March", 
   "April",
   "May", 
   "June", 
   "July", 
   "August",
   "September", 
   "October", 
   "November", 
   "December"
 };

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  /*
  ListAdapter myListAdapter = new ArrayAdapter<String>(
    getActivity(),
    android.R.layout.simple_list_item_1,
    month);
  setListAdapter(myListAdapter);
  */
  MyListAdapter myListAdapter = 
    new MyListAdapter(getActivity(), R.layout.mitglieder, month);
  setListAdapter(myListAdapter);
 }

 @Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
   Bundle savedInstanceState) {
  return inflater.inflate(R.layout.mitglieder, container, false);
 }

 @Override
 public void onListItemClick(ListView l, View v, int position, long id) {
  Toast.makeText(
    getActivity(), 
    getListView().getItemAtPosition(position).toString(), 
    Toast.LENGTH_LONG).show();
 }

}

und hier der xml Code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView
        android:id="@+id/month"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout

Hoffe ihr könnt mir weiterhelfen :))

MFG Lukas R.
Programmieren ist nicht nur eine Wissenschaft, sondern auch ein Lifestyle!

Antworten