Jxl android app崩溃了

时间:2014-02-25 17:18:17

标签: java android intellij-idea jxl

我一直试图让它工作一段时间,甚至在查看StackOverflow和谷歌搜索时我似乎无法弄清楚这一点。我不知道如何使用LogCat过滤我的应用程序的输出(我目前正在使用Intellij 13.0.2)所以我无法粘贴它,但这是我的代码:

package com.example.MobileSurvey;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
//Java bestanden
import java.io.*;
import java.util.Iterator;

//Apache POI (voor Excel)
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import java.io.File;
import java.io.IOException;

import jxl.CellView;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.format.*;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

public class MyActivity extends Activity {

    /**
     * Called when the activity is first created.
     */

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        try
        {
            write();
        } catch (IOException e)
        { e.printStackTrace(); }
        catch(WriteException e)
        {
            e.printStackTrace();
        }
    }

        private WritableCellFormat timesBoldUnderline;
        private WritableCellFormat times;
        private String inputFile;

    public void setOutputFile(String inputfile)
    {
        this.inputFile = inputfile;
    }

    public void write() throws IOException, WriteException
    {
        File file = new File(inputFile);
        WorkbookSettings resultatenSettings = new WorkbookSettings();
        WritableWorkbook resultaten = Workbook.createWorkbook(file, resultatenSettings);
        resultaten.createSheet("Personalia", 0);
        WritableSheet personalia = resultaten.getSheet(0);
        createLabel(personalia);
        createContent(personalia);
        resultaten.write();
        resultaten.close();
    }

    private void createLabel(WritableSheet sheet) throws WriteException
    {
        //Creeren van lettertype
        WritableFont lettertype = new WritableFont(WritableFont.TIMES,10);
        //Celformat definieren
        times = new WritableCellFormat(lettertype);
        //Cellen automatisch laten wrappen
        times.setWrap(true);
        //Times 12pt bold underlined
        WritableFont times12ptBoldUnderline = new WritableFont(WritableFont.TIMES, 12, WritableFont.BOLD, false, UnderlineStyle.SINGLE);
        timesBoldUnderline =  new WritableCellFormat(times12ptBoldUnderline);
        timesBoldUnderline.setWrap(true);

        CellView cv = new CellView();
        cv.setFormat(times);
        cv.setFormat(timesBoldUnderline);
        cv.setAutosize(true);

        //Hoofdingen toevoegen
        addCaption(sheet, 0, 0, "Bedrijfsnaam");
        addCaption(sheet, 1, 0, "Naam respondent");
        addCaption(sheet, 2, 0, "Postcode bedrijf");
    }

    private void createContent(WritableSheet sheet) throws WriteException, RowsExceededException
    {
        for (int i = 1; i < 10; i++)
        {
            //Eerste kolom
            addNumber(sheet, 0, i, i + 10);
            //Tweede kolom
            addNumber(sheet, 1, i, i + 10);
        }
    }
    private void addCaption(WritableSheet sheet, int column, int row, String s) throws WriteException, RowsExceededException
    {
        Label label;
        label =  new  Label(column, row, s, timesBoldUnderline);
        sheet.addCell(label);
    }

    private void addNumber(WritableSheet sheet, int column, int row, Integer integer) throws WriteException, RowsExceededException
    {
        Number number;
        number = new Number(column, row, integer, times);
        sheet.addCell(number);
    }

    private void addLabel(WritableSheet sheet, int column, int row, String s) throws WriteException, RowsExceededException
    {
        Label label;
        label =  new  Label(column, row, s, times);
        sheet.addCell(label);
    }




    public void onFocusChangeListener(View v, boolean hasFocus) {
        EditText Bedrijfsnaam = (EditText)findViewById(R.id.Bedrijfsnaam);
        switch(v.getId())
        {
            case R.id.Bedrijfsnaam:
                if (!hasFocus)
                {
                    String NaamBedrijf = Bedrijfsnaam.getText().toString();
                }

        }
    }
}

我需要能够在两天内将数据写入内部存储上的excel文件,并且我非常渴望能够正常工作。我意识到可能有一个简单的解决方案,但是我变得过于紧张,无法使任何工作,我似乎无法找到我的错误。该应用程序刚启动时崩溃。我目前正在测试运行Android 4.2.2的Acer Iconia A1。非常感谢提前阅读和回复

0 个答案:

没有答案