0

I have not programmed for a long time and I wanted to do a small project, for me, first doing tests, and when I see that it works, leave the code more presentable and change targets, so this is a "draft".

The doubt is that it is very basic for you, I have reviewed other threads like this java.lang.ClassNotFoundException: Didn't find class on path: dexpathlist

and other links in google, applying what they indicate, but I still have the same error when I run the program java.lang.noclassdeffounderror failed resolution of lorg / jsoup / jsoup

Source:

package es.consulta.gas;

import java.io.IOException;

import org.jsoup.Connection.Method;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.Button;
import android.widget.EditText;

public class Gas extends Activity {

    private Button bconectar;
    private EditText tusuario, tcontraseña;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gas);

        tusuario = (EditText) findViewById(R.id.usuario);
        tcontraseña = (EditText) findViewById(R.id.Contrasena);
        bconectar = (Button) findViewById(R.id.conectar);


        //Capturamos pulsación corta boton Generar
        bconectar.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                run();
            }
        });


        //Capturamos pulsación larga boton Generar
        bconectar.setOnLongClickListener(new OnLongClickListener() {
            public boolean onLongClick(View view) {
                run();
                return true;
            }
        });
    }


    public void run() {
        Thread downloadThread = new Thread();
        {
            try {
                Document doc1 =
                    Jsoup.connect("https://ov.madrilena.es/login")
                    .userAgent("Mozilla/5.0")
                    .timeout(10 * 1000)
                    .method(Method.POST)
                    .data("username", tusuario.getText().toString())
                    .data("password", tcontraseña.getText().toString())
                    .followRedirects(true)
                    .get();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        downloadThread.start();
    }


    public void conecta() {
        try {
            // Response response =
            Document doc =
                Jsoup.connect("https://ov.madrilena.es/login")
                .userAgent("Mozilla/5.0")
                .timeout(10 * 1000)
                .method(Method.POST)
                .data("username", tusuario.getText().toString())
                .data("password", tcontraseña.getText().toString())
                .followRedirects(true)
                .get();
            //.execute();

            //parse the document from response
            // Document document = response.parse();

            //get cookies
            //Map<String, String> mapCookies = response.cookies();


            /*        * You may need to send all the cookies you received
             * from the post response to the subsequent requests.
             * 
             * You can do that using cookies method of Connection*/
        } catch (IOException ioe) {
            System.out.println("Exception: " + ioe);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.gas, menu);
        return true;
    }
}

manifiest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="es.consulta.gas" android:versionCode="1" android:versionName="1.0">
  <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
  <uses-permission android:name="android.permission.INTERNET" />
  <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">
    <activity android:name="es.consulta.gas.Gas" android:label="@string/app_name">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
  </application>
</manifest>

First I did it with the connect function but among the answers I saw .. it was that if a thread is not used, you block the main execution thread, so I tried the run alternative, but with the same result

As I say, I know about the shortcomings of the code, but I am picking up very little by little and I never made applications with an internet connection, from there to trial and error

I add an image with the configuration of the libraries What am I leaving? configuration

maybe I shouldn't use jsoup and if something else .. okhttp? What I want to do is a small application to read the consumption of my gas company and attach readings, since my company does not have an app, but it does have a web

thank you and sorry for how stupid my question is

Janez Kuhar
  • 3,096
  • 2
  • 22
  • 39
Peter
  • 21
  • 1
  • 4

0 Answers0