1. java
  2. android
  3. c#
  4. .net
  5. javascript
  6. php
  7. jquery
  8. html
  9. sql

FATAL EXCEPTION: main , java.lang.NullPointerException. porque?

Eu sou leigo em java, estou usando jsoup para analisar textos e retornar arquivos html ... é mais com o erro java.lang.NullPointerException. poderá ser autorizada em manifesto ou do jeito que eu estou passando? Eu não sei por favor me ajude.

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener,
        OnItemClickListener {
    private HtmlSearch buscador = null;
    private EditText campoPesquisa;
    private ListView listaArquivos;
    private Button botaoPesquisa;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        String caminho =Environment.getDataDirectory().getPath() + "/documentos/";


        try {
            this.buscador = new HtmlSearch(caminho);
        } catch (IOException e) {

            e.printStackTrace();
        }
        montaIterfaceGrafica();

    }

    private void montaIterfaceGrafica() {
        this.campoPesquisa = (EditText) findViewById(R.id.edTxtPesquisa);
        this.listaArquivos = (ListView) findViewById(R.id.listView1);
        this.botaoPesquisa = (Button) findViewById(R.id.button1);
        this.botaoPesquisa.setOnClickListener(this);
        this.listaArquivos.setOnItemClickListener(this);

    }

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

    @Override
    public void onClick(View v) {
        String nome;
        nome = this.campoPesquisa.getText().toString();

        List<String> conteudo;
        try {
            conteudo = buscador.pesquisaTextoNosArquivosHtml(nome);
            preencheListaArquivo(conteudo);
        } catch (IOException e) {
            exibeMensagemErro(e.getMessage());
        }

    }

    private void exibeMensagemErro(String mensagem) {
        Toast.makeText(this, mensagem, Toast.LENGTH_LONG).show();

    }

    private void preencheListaArquivo(List<String> conteudo) {
        limparListaArquivo();
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, conteudo);
        this.listaArquivos.setAdapter(adapter);
    }

    private void limparListaArquivo() {
        this.listaArquivos.setAdapter(arrayAdaterNull());
    }

    private ListAdapter arrayAdaterNull() {
        List<String> vazio = new ArrayList<String>();
        return new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, vazio);
    }

    @Override
    public void onItemClick(AdapterView<?> adapter, View view, int posicao,
            long id) {
        try {
            String nomeArquivo;
            nomeArquivo = this.buscador.getCaminho()
                    + adapter.getItemAtPosition(posicao).toString();
            abriArquivo(nomeArquivo);
        } catch (Exception e) {
            exibeMensagemErro(e.getMessage());
        }
    }

    private void abriArquivo(String nomeArquivo) {

        File targetFile = new File(nomeArquivo);
        Uri targetUri = Uri.fromFile(targetFile);

        Intent intent;
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(targetUri, "application/html");

        try {
            startActivity(intent);
        } catch (ActivityNotFoundException act) {
            exibeMensagemErro("É necassário instalar um leitor de pdf:");
        } catch (Exception e) {
            exibeMensagemErro(e.getMessage());
        }

    }

}


**12-29 13:20:45.391: D/memalloc(32045): /dev/pmem: Mapped buffer base:0x51212000 size:9535488 offset:7999488 fd:48
12-29 13:20:45.541: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:45.581: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:45.621: D/memalloc(32045): /dev/pmem: Mapped buffer base:0x51c2a000 size:5693440 offset:4157440 fd:55
12-29 13:20:45.991: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.001: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.051: D/memalloc(32045): /dev/pmem: Mapped buffer base:0x52540000 size:4157440 offset:2621440 fd:58
12-29 13:20:46.301: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.301: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.341: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.341: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.351: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.351: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.371: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.371: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.381: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.381: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.421: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.421: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.421: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.421: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.431: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.431: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.451: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.451: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.471: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.471: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.481: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.481: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.491: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.491: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.501: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.501: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.521: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.521: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.531: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.531: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.551: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.551: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.571: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.571: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.581: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.581: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:46.971: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:46.971: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:47.471: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:47.471: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:47.971: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:47.971: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:48.471: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:48.471: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:48.981: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:48.981: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:49.471: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:49.481: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:50.511: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:50.521: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:51.001: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:51.001: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:51.501: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:51.501: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:51.571: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:51.571: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:51.581: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:51.581: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:51.961: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(9)
12-29 13:20:52.001: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:52.001: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:52.091: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:52.101: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:52.591: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:52.601: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:52.841: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:52.841: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:53.051: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:53.061: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:53.501: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:53.501: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:53.971: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(3)
12-29 13:20:53.971: E/Adreno200-ES20(32045): <qgl2DrvAPI_glUseProgram:1318>: **** 32045: glUseProgram(6)
12-29 13:20:54.511: W/dalvikvm(32045): threadid=1: thread exiting with uncaught exception (group=0x40db31f8)
12-29 13:20:54.561: E/AndroidRuntime(32045): FATAL EXCEPTION: main
12-29 13:20:54.561: E/AndroidRuntime(32045): java.lang.NullPointerException
12-29 13:20:54.561: E/AndroidRuntime(32045):     at br.com.manualgug.ListadorDearquivos.listaHttml(ListadorDearquivos.java:21)
12-29 13:20:54.561: E/AndroidRuntime(32045):     at br.com.manualgug.HtmlSearch.pesquisaTextoNosArquivosHtml(HtmlSearch.java:45)
12-29 13:20:54.561: E/AndroidRuntime(32045):     at br.com.manualgug.MainActivity.onClick(MainActivity.java:72)
12-29 13:20:54.561: E/AndroidRuntime(32045):     at android.view.View.performClick(View.java:3521)
12-29 13:20:54.561: E/AndroidRuntime(32045):     at android.view.View$PerformClick.run(View.java:14185)
12-29 13:20:54.561: E/AndroidRuntime(32045):     at android.os.Handler.handleCallback(Handler.java:605)
12-29 13:20:54.561: E/AndroidRuntime(32045):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-29 13:20:54.561: E/AndroidRuntime(32045):     at android.os.Looper.loop(Looper.java:137)
12-29 13:20:54.561: E/AndroidRuntime(32045):     at android.app.ActivityThread.main(ActivityThread.java:4464)
12-29 13:20:54.561: E/AndroidRuntime(32045):     at java.lang.reflect.Method.invokeNative(Native Method)
12-29 13:20:54.561: E/AndroidRuntime(32045):     at java.lang.reflect.Method.invoke(Method.java:511)
12-29 13:20:54.561: E/AndroidRuntime(32045):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:822)
12-29 13:20:54.561: E/AndroidRuntime(32045):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:589)
12-29 13:20:54.561: E/AndroidRuntime(32045):     at dalvik.system.NativeStart.main(Native Method)
**

não o a classe ListadorDearquivos

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class ListadorDearquivos {
    private final File pasta;
    private static final String SEPARADOR = File.separator; // constante

    public ListadorDearquivos(String caminho) {
        this.pasta = new File(caminho);
    }

    public List<String> listaHttml() {
        // instancia o list de retorno
        ArrayList<String> arquivos = new ArrayList<String>();
        // obtem o conteudo interno da pasta (arquivos e pastas)
        String[] arqs = this.pasta.list();
        // adiciona a list apenas arquivos
        for (String a : arqs) {
            if (ehUmArquivoHTML(a)) {
                arquivos.add(a);
            }
        }
        return arquivos;
    }

    private boolean ehUmArquivoHTML(String nomeDoArquivo) {
        return nomeDoArquivo.toUpperCase().endsWith(".HTML");
    }

    public String caminhoBase() {
        return this.pasta + SEPARADOR;
    }
}
  • Por favor, posta as mensagens de erros do LogCat.

    A H Gusukuma   30 de dez de 2013
  • Please, edit your question posting the full stack trace of the error.

    utluiz   30 de dez de 2013
  • Caro utluiz, o GUJ Respostas só tem sentido se for em português, caso contrário usaríamos o Stackoverflow não é?

    A H Gusukuma   30 de dez de 2013
  • deixa o menino treinar o inglês dele kkkk

    ric_analista   30 de dez de 2013
  • kkkkk, veio é ki ja entrei e li tanta coisa, ki nem sei mais se pergunto em português ou inglês kkkkk

    makiellson   30 de dez de 2013
Mostrar todos os 7 comentários>
  1. Você vai ver essas setas em qualquer página de pergunta. Com elas, você pode dizer se uma pergunta ou uma resposta foram relevantes ou não.
  2. Edite sua pergunta ou resposta caso queira alterar ou adicionar detalhes.
  3. Caso haja alguma dúvida sobre a pergunta, adicione um comentário. O espaço de respostas deve ser utilizado apenas para responder a pergunta.
  4. Se o autor da pergunta marcar uma resposta como solucionada, esta marca aparecerá.
  5. Clique aqui para mais detalhes sobre o funcionamento do GUJ!

3 respostas

Não é a resposta que estava procurando? Procure outras perguntas com as tags android ou faça a sua própria pergunta.