“不幸的是,[应用程序]已经停止运行”第1238卷(包括Logcat)

时间:2014-06-29 10:53:17

标签: android

创建对象时,我的Android VM上的应用程序停止。关于这个错误有很多问题,但是没有一个问题对我有帮助,现在它变得绝望了。

Logcat(已过滤"例外"):

06-29 06:35:19.189: W/dalvikvm(1035): threadid=1: thread exiting with uncaught exception (group=0x41465700)
06-29 06:35:19.200: E/AndroidRuntime(1035): FATAL EXCEPTION: main
06-29 06:35:19.200: E/AndroidRuntime(1035): java.lang.RuntimeException: Unable to start activity     ComponentInfo{com.example.annoworkspace/com.example.annoworkspace.MainActivity}: java.lang.IllegalArgumentException: is == null
06-29 06:35:19.200: E/AndroidRuntime(1035): Caused by: java.lang.IllegalArgumentException: is == null

我在MainActivity中创建对象(当注释掉时,应用程序不会停止):

    parserClass parse = new parserClass(getApplicationContext());

如果你对parserClass的代码感兴趣,它有点长而且很混乱,但也许它有助于错误检测:

package com.example.annoworkspace;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Struct;
import java.util.ArrayList;
import java.util.HashMap;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import android.os.Bundle;
import android.os.Debug;
import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;


public class parserClass 
{

public ArrayList<String> content= new ArrayList<String>();
HashMap collection = new HashMap();

Cost cost = new Cost(0,0,0,0);
Production production = new Production("",0);
MaintenanceCost maintenanceCost = new MaintenanceCost(0, 0, 0, 0, 0);

Building building = new Building("", cost, production, maintenanceCost);

public TextView Anzeige1;

public InputStream in_s;


        public parserClass(Context context)
        {
            Log.d("Start parserClass", null, null);
            //Öffnen der XML
            try
            {
                InputStream in_s = context.getAssets().open("Buildings.xml");
            }
            catch (IOException e1) 
            {
                e1.printStackTrace();
            }   

            try 
            {
                xmlparser();
            } 
            catch (XmlPullParserException e)
            {
                e.printStackTrace();
            } 
            catch (IOException e) 
            {
                e.printStackTrace();
            }

        }



public void xmlparser() throws XmlPullParserException, IOException 
{

    String xmlInfo = "xml_parser";
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);
    XmlPullParser xpp = factory.newPullParser();

    xpp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);

    xpp.setInput(in_s, null);
    int eventType = xpp.getEventType();

    while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_DOCUMENT)
            Log.d(xmlInfo, "Start document");
        else if (eventType == XmlPullParser.END_DOCUMENT)
            Log.d(xmlInfo, "End document");
        else if (eventType == XmlPullParser.START_TAG)
        {
            Log.d(xmlInfo, "Start tag " + xpp.getName());

            //building tempBuilding;

            if (xpp.getName()=="Building")
            {
                //obsolete
            }
            else if(xpp.getName()=="Name")
            {
                building.name=xpp.nextText();
            }
            else if (xpp.getName() == "Cost")
            {
                //
            }
            else if (xpp.getName() == "Credits")
            {
                cost.credits = xpp.next();
            }
            else if (xpp.getName() == "Buildingmodules")
            {
                cost.buildingmodules = xpp.next();
            }
            else if (xpp.getName() == "Tools")
            {
                cost.tools = xpp.next();
            }
            else if (xpp.getName() == "Concrete")
            {
                cost.concrete = xpp.next();
            }
            else if (xpp.getName() == "Production")
            {}
            else if (xpp.getName() == "Product")
                production.product = xpp.nextText();
            else if (xpp.getName() == "ProductionSpeed")
            {
                production.productionSpeed = xpp.next();
            }
            else if (xpp.getName() == "MaintenanceCost")
            {
                //
            }
            else if (xpp.getName()== "ActiveCost")
            {
                maintenanceCost.activeCost = xpp.next();
            }
            else if (xpp.getName()== "InactiveCost")
            {
                maintenanceCost.inactiveCost = xpp.next();
            }

            else if (xpp.getName()== "ActiveEcoEffect")
            {
                maintenanceCost.activeEcoEffect = xpp.next();
            }

            else if (xpp.getName()== "InactiveEcoEffect")
            {
                maintenanceCost.inactiveEcoEffect = xpp.next();
            }

            else if (xpp.getName()== "ActiveEnergyCost")
            {
                maintenanceCost.activeEnergyCost = xpp.next();
            }

            else if (xpp.getName()== "InactiveEnergyCost")
            {
                maintenanceCost.inactiveEnergyCost = xpp.next();
            }




        }
        else if (eventType == XmlPullParser.END_TAG)
            Log.d(xmlInfo, "End tag " + xpp.getName());
        else if (eventType == XmlPullParser.TEXT) {
            if (xpp.getText().length() == 4) 
            {
                Log.d(xmlInfo, xpp.getText());

            }
            else 
            {
                Log.d(xmlInfo, xpp.getText());
                //serverName = xpp.getText();
            }
        }

        eventType = xpp.next();
    }
}







}

1 个答案:

答案 0 :(得分:0)

您的本地变量in_s会隐藏您的成员变量in_s,因此成员变量未分配(null)。

这可能只是你的错字。