gpt4 book ai didi

java - 切换 Activity 时应用程序崩溃

转载 作者:行者123 更新时间:2023-11-30 02:02:52 25 4
gpt4 key购买 nike

您好,我已经这样做了好几天了,每次我尝试进入 ListView Activity 时,我总是遇到崩溃。我已经重写了两次 ListView Activity ,这里是 Activity 代码:

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 上下文 mContext; protected 列表练习; public Excercise_Adapter (Context context, List exercise){ super (上下文,R.layout.da_excerisises,练习); mContext = 上下文; 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

Activity 的 XML 文件:

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

这是 list

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

最佳答案

您应该在适配器 getView 中返回 convertView 而不是调用 super。另外,如果这对您没有帮助,请发布代码以开始您的 Activity 。编辑请将您的两个 Activity 添加到应用程序标签内的 list 中,例如:

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

关于java - 切换 Activity 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31211790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com