我想上运行日食这一计划,但获得控制台这个错误 [英] I'm trying to Run this program on eclipse but get this error in console

查看:121
本文介绍了我想上运行日食这一计划,但获得控制台这个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 以价值为java.lang.String布局无效

#已被Java运行时环境检测到一个致命错误:

#内部错误(javaClasses.cpp:129),PID = 6223,TID = 3064822640
#致命错误:preloaded类的布局无效

#JRE版本:7.0_07-B10
#Java虚拟机:Java的热点(TM)服务器VM(23.3-B01混合模式的linux-X86)
#无法写入核心转储。核心转储已被禁用。为了使核心倾销,试试的ulimit -c无限再次启动之前的Java

#更多信息的错误报告文件保存为:
#/home/kailash/workspace/Parsing/hs_err_pid6223.log

#如果您想提交错误报告,请访问:
#http://bugreport.sun.com/bugreport/crash.jsp


  

运行的Andr​​oid应用程序。我是新来的JAVA和Android。并且无法运行此code在控制台显示了下面的错误。所以请任何人都可以帮助我。在这里,在这个code我试图从本地XML文件解析的一些数据,并在一个新的文件写入。


 包com.demo.parsing;进口的java.io.File;
进口java.io.FileInputStream中;
进口java.io.FileNotFoundException;
进口java.io.FileWriter;
进口java.io.IOException异常;
进口java.util.LinkedList中;
进口的java.util.List;进口javax.xml.parsers.DocumentBuilder中;
进口javax.xml.parsers.DocumentBuilderFactory中;
进口javax.xml.parsers.ParserConfigurationException;进口org.jsoup.Jsoup;
进口org.w3c.dom.Document中;
进口org.w3c.dom.Element中;
进口org.w3c.dom.NodeList;
进口org.xml.sax.SAXException;进口android.app.Activity;
进口android.os.Bundle;
进口android.view.Menu;公共类MainActivity延伸活动{    //私有静态OutputStreamWriter出来;
    公共静态无效的主要(字串[] args)抛出FileNotFoundException异常{
        的FileInputStream pustaka =新的FileInputStream(/家庭/神山/工作区/分析/ pustaka-feed.xml);        尝试{
            的DocumentBuilder建设者= DocumentBuilderFactory.newInstance()newDocumentBuilder()。            文档进= builder.parse(pustaka);            节点列表项= feed.getElementsByTagName(项目);            清单<串GT;网址=新的LinkedList<串GT;();            的for(int i = 0; I< items.getLength();我++){
                元素项=(元件)items.item(ⅰ);
                元素说明=(元)item.getElementsByTagName(
                        说明)项目(0);
                urls.addAll(getImages(建设者,description.getTextContent()));
            }             FileWriter的F =新的FileWriter(新文件(OUTFILE));            对于(字符串网址:网址){
                f.write(URL +\\ n);
            }            f.close();        }赶上(的ParserConfigurationException E){
            e.printStackTrace();
        }赶上(SAXException的E){
            e.printStackTrace();
        }赶上(IOException异常五){
            e.printStackTrace();
        }    }    私人静态列表<串GT; getImages(的DocumentBuilder建设者,字符串内容)抛出的SAXException,IOException异常{
        清单<串GT;网址=新的LinkedList<串GT;();        对于(org.jsoup.nodes.Element IMG:Jsoup.parse(内容).getElementsByTag(IMG)){
            urls.add(img.attributes()获得(SRC));
        }        返回的网址;
    }公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
}
公共布尔onCreateOptionsMenu(菜单菜单){
    。getMenuInflater()膨胀(R.menu.activity_main,菜单);
    返回true;
}
}


解决方案

神山,你不能只是贴上你的Java code在Android活动,并期望它的工作。可能你运行该程序作为Java应用程序,所以它悲惨的失败了。

您不能使用静态无效的主要(字串[] args)在Android应用程序,所以第一步将是修改的方法是签名(删除静态,删除的String [] 参数,使其私人)。

在这之后,你的活动根本不会做任何事情,因为你的方法将不会从任何地方调用。你必须找到一个地方(可能是的onCreate())来启动的AsyncTask 来解析XML(另外,您还将不得不切换到由ID获取资源的Andr​​oid的方式,因为你不能真正从任何Android设备访问您的工作空间...)

Invalid layout of java.lang.String at value
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (javaClasses.cpp:129), pid=6223, tid=3064822640
#  fatal error: Invalid layout of preloaded class
#
# JRE version: 7.0_07-b10
# Java VM: Java HotSpot(TM) Server VM (23.3-b01 mixed mode linux-x86 )
# Failed to write core dump. Core dumps have been disabled. To enable core dumping,     try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/kailash/workspace/Parsing/hs_err_pid6223.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
#

Running as Android application. I am new to JAVA and android. and not able to run this code as the following error is shown in console. so please anybody can help me with this. Here in this code i'm trying to parse some data from a local XML file and write it in a new file.

package com.demo.parsing;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.jsoup.Jsoup;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;

public class MainActivity extends Activity{

    //private static OutputStreamWriter out;


    public static void main(String[] args) throws FileNotFoundException {
        FileInputStream pustaka = new FileInputStream("/home/kailash/workspace/parsing/pustaka-feed.xml");

        try {
            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();

            Document feed = builder.parse(pustaka);

            NodeList items = feed.getElementsByTagName("item");

            List<String> urls = new LinkedList<String>();

            for (int i = 0; i < items.getLength(); i++) {
                Element item = (Element) items.item(i);
                Element description = (Element) item.getElementsByTagName(
                        "description").item(0);
                urls.addAll(getImages(builder, description.getTextContent()));
            }

             FileWriter f = new FileWriter(new File("outfile"));

            for (String url : urls) {
                f.write(url + "\n");
            }

            f.close();

        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    private static List<String> getImages(DocumentBuilder builder, String content) throws SAXException, IOException {
        List<String> urls = new LinkedList<String>();

        for (org.jsoup.nodes.Element img : Jsoup.parse(content).getElementsByTag("img")) {
            urls.add(img.attributes().get("src"));
        }

        return urls;
    }



public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}




public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}


}

解决方案

Kailash, you can't just paste your Java code in an Android activity and expect it to work. Likely you run this program as a Java application, so it miserably fails.

You can't use a static void main(String[] args) in an Android application, so the first step will be to modify that signature of that method (remove static, remove the String[] argument, make it private).

After that, your Activity simply won't do anything because your method will not be called from anywhere. You have to find a place (likely onCreate()) to start an AsyncTask to parse the XML (also, you'll have to switch to the Android way of retrieving resources by ID, because you can't really access your workspace from any Android device...)

这篇关于我想上运行日食这一计划,但获得控制台这个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆