java.lang.NullPointerException:尝试在空对象引用

时间:2016-06-25 17:23:35

标签: java android nullpointerexception

我正在开发一个项目,该项目从.txt文件中获取数据并将其处理为3个不同的变量ShowSeriesEpisodes

我遇到了null对象引用错误并且无法修复它并不太确定我在哪里弄乱这个。请您给我的任何帮助将不胜感激,因为我没有太多时间来完成这个项目,然后才能进行评估。

调用功能。

public void GetSetShowData(int Count){

        String[] ShowsStrings = FileRead.ReadUpdates("TvShows.txt",Count);
        Shows[]  ShowData = new Shows[LineCount];
        for(int i = 0; i <= Count;i++) {
            String Temp = ShowsStrings[i];
            String[] Temp2;
            Temp2 = TextUtils.split(Temp, ",");
            Log.d("Line count: ", ""+LineCount);
            Log.d("Temp2 length", Integer.toString(Temp2.length));
            Log.d("Temp2[0] contains: ", Temp2[0].trim());
            Log.d("Temp2[1] contains: ",Temp2[1]);
            String name = Temp2[0];
            Log.d("name: " , name);
            ShowData[0].setName(name);
            Integer series = Integer.parseInt(Temp2[1].trim());
            Log.d("series:", " " + series);
            ShowData[i].setSeries(series);
            for(int i2 = 0;i2 >= (Temp2.length- 2);i2++ ){
                ShowData[i2].setEpisodes(i,Integer.parseInt(Temp2[i2 + 2]));
            }
            for(int log = 0; log > Temp2.length; log++){
                Log.d("Show Data: " + i , "Series: " + ShowData[i].getSeries() + " Episode: " + ShowData[i].getEpisodes(log));
            }

        }


    }

Shows(多数据类型数组)

public class Shows {
    public String Show = "";
    public int SeriesAmount = 0;
    public ArrayList<Integer> Episodes = new ArrayList<>();


    public Shows(){

    }

    public void setName(String Name){
            Show = Name;
    }

    public String getName(){

            return Show;

    }
    public void setSeries(int Series){
        SeriesAmount = Series;
    }

    public int getSeries(){
        return SeriesAmount;
    }

    public void setEpisodes(int Position, int Episode){

        Episodes.add(Position,Episode);
    }
    public int getEpisodes(int Position){
            return Episodes.get(Position);



    }

}

这是我收到的错误消息。

  

06-25 18:06:32.802 729-729 / com.packageName E / AndroidRuntime:FATAL EXCEPTION:main进程:com.packageName,PID:729 java.lang.RuntimeException:无法启动活动ComponentInfo {com.packageName /com.packageName.TvShows2}:java.lang.NullPointerException:尝试在android.app.ActivityThread.performLaunchActivity上的空对象引用上调用虚方法'void com.packageName.Shows.setName(java.lang.String)'( ActivityThread.java:2702)在android.app.A活动时,我在Android.app.ActivityThread.access $ 900(ActivityThread.java:177)上的android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767),来自android.app.ActivityThread $ H.handleMessage(ActivityThread。 Java的:1449)                                                                                在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                    在android.os.Looper.loop(Looper.java:145)                                                                                    在android.app.ActivityThread.main(ActivityThread.java:5951)                                                                                    at java.lang.reflect.Method.invoke(Native Method)                                                                                    在java.lang.reflect.Method.invoke(Method.java:372)                                                                                    在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1400)                                                                                    在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)                                                                                 引发者:java.lang.NullPointerException:尝试在空对象引用上调用虚方法'void com.packageName.Shows.setName(java.lang.String)'                                                                                    at com.packageName.TvShows2.GetSetShowData(TvShows2.java:91)                                                                                    在com.packageName.TvShows2.onCreate(TvShows2.java:51)                                                                                    在android.app.Activity.performCreate(Activity.java:6289)                                                                                    在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)                                                                                    在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2655)                                                                                    在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)                                                                                    在android.app.ActivityThread.access $ 900(ActivityThread.java:177)                                                                                    在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1449)                                                                                    在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                    在android.os.Looper.loop(Looper.java:145)                                                                                    在android.app.ActivityThread.main(ActivityThread.java:5951)                                                                                    at java.lang.reflect.Method.invoke(Native Method)                                                                                    在java.lang.reflect.Method.invoke(Method.java:372)                                                                                    在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1400)                                                                                    在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

0 个答案:

没有答案