My code keeps crashing am not really sure whats wrong all i know is that the caller for the arraylist is not receiving it I feel as though its something with the adapter. there is no exception in android studio sinces it lets the app run the app opens up it crashes. heres what the debugger says. the app runs until the return line within the arraylist after that the app crashes.
E/e.reportcardap: Invalid ID 0x00000041. D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.reportcardapp, PID: 8949 android.content.res.Resources$NotFoundException: String resource ID #0x41 at android.content.res.Resources.getText(Resources.java:348) at android.widget.TextView.setText(TextView.java:5858) at com.example.reportcardapp.ReportCardAdapter.getView(ReportCardAdapter.java:45) at android.widget.AbsListView.obtainView(AbsListView.java:2373) at android.widget.ListView.makeAndAddView(ListView.java:2052) at android.widget.ListView.fillDown(ListView.java:786) at android.widget.ListView.fillFromTop(ListView.java:847) at android.widget.ListView.layoutChildren(ListView.java:1826) at android.widget.AbsListView.onLayout(AbsListView.java:2165) at android.view.View.layout(View.java:20713) at android.view.ViewGroup.layout(ViewGroup.java:6197) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:20713) at android.view.ViewGroup.layout(ViewGroup.java:6197) at androidx.appcompat.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:444) at android.view.View.layout(View.java:20713) at android.view.ViewGroup.layout(ViewGroup.java:6197) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:20713) at android.view.ViewGroup.layout(ViewGroup.java:6197) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656) at android.widget.LinearLayout.onLayout(LinearLayout.java:1565) at android.view.View.layout(View.java:20713) at android.view.ViewGroup.layout(ViewGroup.java:6197) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at com.android.internal.policy.DecorView.onLayout(DecorView.java:792) at android.view.View.layout(View.java:20713) at android.view.ViewGroup.layout(ViewGroup.java:6197) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2831) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2358) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1494) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7288) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949) at android.view.Choreographer.doCallbacks(Choreographer.java:761) at android.view.Choreographer.doFrame(Choreographer.java:696) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6936) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
//Main activity //
package com.example.reportcardapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grade_list);
ArrayList<Grade> grades = new ArrayList<Grade>();
grades.add(new Grade("Name: Jake;", "Math;", 'A'));
grades.add(new Grade("Name: Jake;", "Science", 'C'));
grades.add(new Grade("Name: Jake;", "Gym", 'B'));
grades.add(new Grade("Name: Jake;", "Web Design", 'c'));
grades.add(new Grade("Name: Jake;", "Music", 'F'));
ReportCardAdapter aadapter = new ReportCardAdapter(this, grades);
// Find the {@link ListView} object in the view hierarchy of the {@link Activity}.
// There should be a {@link ListView} with the view ID called list, which is declared in the
// word_list.xml layout file.
ListView listView = (ListView) findViewById(R.id.list);
// Make the {@link ListView} use the {@link WordAdapter} we created above, so that the
// {@link ListView} will display list items for each {@link Word} in the list.
listView.setAdapter(aadapter);
}
}
// Grade class package com.example.reportcardapp;
public class Grade {
private String mname;
private String mclassName;
private char mgradeLetter;
public Grade(String name, String className, char gradeLetter) {
mname = name;
mclassName = className;
mgradeLetter = gradeLetter;
}
public String getName() {
return mname;
}
public String getClassName() {
return mclassName;
}
public char getGradeLetter() {
return mgradeLetter;
}
}
//Report Card addapter//
package com.example.reportcardapp;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.ArrayList;
public class ReportCardAdapter extends ArrayAdapter<Grade> {
public ReportCardAdapter(Context context, ArrayList<Grade> grades) {
super(context, 0, grades);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Check if an existing view is being reused, otherwise inflate the view
View listItemView = convertView;
if (listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(
R.layout.list_item, parent, false);
}
// Get the {@link Word} object located at this position in the list
Grade currentGrade = getItem(position);
TextView nameTextView = listItemView.findViewById(R.id.name);
nameTextView.setText(currentGrade.getName());
TextView classNameTextView = listItemView.findViewById(R.id.className);
classNameTextView.setText(currentGrade.getClassName());
TextView gradeLetterTextView = listItemView.findViewById(R.id.letterGrade);
gradeLetterTextView.setText(currentGrade.getGradeLetter());
return listItemView;
}
}
Looks like R.id.name does not exist. Check your strings.xml file
User contributions licensed under CC BY-SA 3.0