1

Hi so I have been going at this for days and I keep getting a crash everytime I try to move into my list view activity. I have rewritten the list view activity twice here is the activity code:

protected List<ParseObject> exercise_name;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_exersise_display);

    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Exercises");
    query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> list, ParseException e) {
            if(e==null){
                //success
                exercise_name = list;

                Excercise_Adapter adapter = new Excercise_Adapter(getListView().getContext(), exercise_name);
                setListAdapter(adapter);
            }
            else {

            }
        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_exersise__display, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

here is the Exercise Adapter class protected Context mContext; protected List mExercise; public Excercise_Adapter (Context context, List exercise){ super(context, R.layout.da_excerisises, exercise); mContext = context; mExercise = exercise; }

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if(convertView == null){
        convertView = LayoutInflater.from(mContext).inflate(R.layout.da_excerisises, null);
        holder = new ViewHolder();
        //holder.exerciseImage = (ImageView)convertView.findViewById(R.id.Exersise_image);
        holder.exerciseName = (TextView) convertView.findViewById(R.id.Exersise_name_menu);

        convertView.setTag(holder);
    }
    else{
        holder = (ViewHolder)convertView.getTag();
    }

    ParseObject exercise_object = mExercise.get(position);

    String title = exercise_object.getString("exercise_name");
    holder.exerciseName.setText(title);

    return convertView;
}

public static class  ViewHolder{
    //ImageView exerciseImage;
    TextView exerciseName;
}

and here is the calling code:

protected Button fitcalcmain;
protected Button excersise;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
   // Parse.initialize(this, "BEFmOu6ru7ulUKCaFaNP8JdGU73RBc4wFfvOjfWp", "dV460EGCxMwhzvRhHQDne2zlYoeOQu2aDypfuTTW");
    fitcalcmain = (Button)findViewById(R.id.FitnessCalcMain);
    excersise = (Button)findViewById(R.id.ExersisesMain);

    fitcalcmain.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent gomeasure = new Intent(MainActivity.this, fitcalc.class);
            startActivity(gomeasure);
        }
    });
    excersise.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent goexcercises =  new Intent(MainActivity.this, Exersise_Display.class);
            startActivity(goexcercises);
        }
    });
}

here is the log (sorry it doesn't let me paste it into here because of "bad formatting":google doc with logcat

XML file of activity:

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/list"
    android:layout_centerHorizontal="true"
    android:layout_alignParentTop="true" />

here is the manifest

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="Workout Buddy"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".LoginActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:label="@string/Mainmenu" >
    </activity>
    <activity
        android:name=".RegisterActivity"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".fitcalc"
        android:label="@string/title_activity_fitcalc" >
    </activity>
    <activity
        android:name=".Exersise_Display"
        android:label="@string/title_activity_exersise__display" >
    </activity>
    <activity
        android:name=".Types_Activity"
        android:label="@string/title_activity_types_" >
    </activity>
</application>

Igal Flegmann
  • 582
  • 1
  • 8
  • 19

1 Answers1

1

You should return convertView in your adapter getView instead of calling super. Plus if this didnt help you please post the code to start your activity. edit Please add the two of your activities into the manifest inside of application tag ex:

<activity android:name="myActivity"> <activity android:name="myActivity"Two>

Kosh
  • 6,140
  • 3
  • 36
  • 67