切换活动时应用崩溃

时间:2015-07-03 17:25:52

标签: java android listview

嗨,所以我已经在这几天了,每当我尝试进入列表视图活动时,我都会一直崩溃。我在这里重写了两次列表视图活动是活动代码:

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);
}

这是练习适配器类     protected Context mContext;     protected List mExercise;     public Excercise_Adapter(Context context,List exercise){         super(context,R.layout.da_excerisises,exercise);         mContext = context;         mExercise =运动;     }

@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;
}

这是调用代码:

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);
        }
    });
}

这是日志(抱歉,由于“格式错误”,我不允许将其粘贴到此处:google doc with logcat

活动的XML文件:

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

这是清单

<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>

2 个答案:

答案 0 :(得分:2)

看完你的错误之后,我发现上面的解决方案有了答案。 here 我希望这会有所帮助。

答案 1 :(得分:1)

您应该在适配器getView中返回convertView而不是调用super。此外,如果这对您没有帮助,请发布代码以开始您的活动。 的修改 请将您的两个活动添加到应用程序标记ex:

中的清单中

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