Android &引用;不幸的是,[应用程序]已停止运行;第1238卷(包括Logcat)
我的Android VM上的应用程序在创建对象时停止。关于这个错误有很多问题,但没有一个对我有帮助,现在它变得绝望了 Logcat(针对“异常”进行过滤): 我在MainActivity中创建对象(当注释掉时,应用程序不会停止): 如果您对parserClass的代码感兴趣,它有点长,有点混乱,但可能有助于错误检测:Android &引用;不幸的是,[应用程序]已停止运行;第1238卷(包括Logcat),android,Android,我的Android VM上的应用程序在创建对象时停止。关于这个错误有很多问题,但没有一个对我有帮助,现在它变得绝望了 Logcat(针对“异常”进行过滤): 我在MainActivity中创建对象(当注释掉时,应用程序不会停止): 如果您对parserClass的代码感兴趣,它有点长,有点混乱,但可能有助于错误检测: package com.example.annoworkspace; import java.io.IOException; import java.io.InputStream
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();
}
}
}
package com.example.annoworkspace;
导入java.io.IOException;
导入java.io.InputStream;
导入java.sql.Struct;
导入java.util.ArrayList;
导入java.util.HashMap;
导入org.xmlpull.v1.XmlPullParser;
导入org.xmlpull.v1.XmlPullParserException;
导入org.xmlpull.v1.XmlPullParserFactory;
导入android.os.Bundle;
导入android.os.Debug;
导入android.app.Activity;
导入android.content.Context;
导入android.content.ContextWrapper;
导入android.util.Log;
导入android.view.Menu;
导入android.widget.TextView;
公共类parserClass
{
public ArrayList content=new ArrayList();
HashMap集合=新建HashMap();
成本=新成本(0,0,0,0);
生产量=新生产量(“,0);
MaintenanceCost MaintenanceCost=新的MaintenanceCost(0,0,0,0);
建筑=新建筑(“成本、生产、维护成本”);
公共文本视图Anzeige1;
公共输入流;
公共parserClass(上下文)
{
Log.d(“启动parserClass”,null,null);
//Öffnen der XML
尝试
{
InputStream in_=context.getAssets().open(“Buildings.xml”);
}
捕获(IOE1异常)
{
e1.printStackTrace();
}
尝试
{
xmlparser();
}
catch(XMLPullParseRexE)
{
e、 printStackTrace();
}
捕获(IOE异常)
{
e、 printStackTrace();
}
}
public void xmlparser()引发XmlPullParserException,IOException
{
字符串xmlInfo=“xml_解析器”;
XmlPullParserFactory工厂=XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp=factory.newPullParser();
setFeature(XmlPullParser.FEATURE_进程_名称空间,false);
xpp.setInput(单位为空);
int eventType=xpp.getEventType();
while(eventType!=XmlPullParser.END_文档){
if(eventType==XmlPullParser.START\u文档)
Log.d(xmlInfo,“启动文档”);
else if(eventType==XmlPullParser.END_文档)
Log.d(xmlInfo,“结束文件”);
else if(eventType==XmlPullParser.START_标记)
{
Log.d(xmlInfo,“开始标记”+xpp.getName());
//建筑工程;
如果(xpp.getName()=“建筑”)
{
//过时的
}
else if(xpp.getName()=“Name”)
{
building.name=xpp.nextText();
}
else if(xpp.getName()=“成本”)
{
//
}
else if(xpp.getName()=“Credits”)
{
cost.credits=xpp.next();
}
else if(xpp.getName()=“Buildingmodules”)
{
cost.buildingmodules=xpp.next();
}
else if(xpp.getName()=“工具”)
{
cost.tools=xpp.next();
}
else if(xpp.getName()=“具体”)
{
cost.concrete=xpp.next();
}
else if(xpp.getName()=“生产”)
{}
else if(xpp.getName()=“产品”)
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_标记)
Log.d(xmlInfo,“End tag”+xpp.getName());
else if(eventType==XmlPullParser.TEXT){
if(xpp.getText().length()==4)
{
Log.d(xmlInfo,xpp.getText());
}
其他的
{
Log.d(xmlInfo,xpp.getText());
//serverName=xpp.getText();
}
}
eventType=xpp.next();
}
}
}
您的局部变量在
中隐藏您的成员变量,因此成员变量未赋值(null
)
这可能只是您的输入错误。这实际上是应用程序停止的原因。我修好了,现在可以用了。
parserClass parse = new parserClass(getApplicationContext());
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();
}
}
}