saurabh gupta
saurabh gupta

Reputation: 520

ClassDefNotFound Error in Android when AWS connection is made

I have been working on a android project to connect to the tables stored at my EC2 instances. I have made the connection code separately and tested it. It is showing the output as desired but the issue is that when i try to integrate the code to an Android Project it throws the error "ClassDefNotFound" Error of some Hive libraries.

MainActivity.java

package com.example.blockbuster;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;

public class MainActivity extends ActionBarActivity {

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

        searchButton = (Button)findViewById(R.id.search_button);
    }

    public void clickSearch(View view){
        Intent intent = new Intent(this,PopulateOnUi.class);
        startActivity(intent);
    }

}

PopulateOnUi.java

package com.example.blockbuster;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;

public class PopulateOnUi extends ActionBarActivity {

    ListView listview;
    TextView tv1;
    String data = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_populate_on_ui);
        String[] values = new String[]{"data1","data2","data3","data4", "data5"};
        String data = null;
        //////////////////////////////////////////////////////////
        String driverName = "com.amazon.hive.jdbc3.HS2Driver";
        try {
            Class.forName(driverName);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            //      System.exit(1);
        }
        try {
            Connection con = DriverManager.getConnection("jdbc:hive2://xx.xxx.xxx.xx:10000/default", "", "");
            Statement stmt = con.createStatement();
            String tableName = "msd";
            // show tables
            String sql = "show tables '" + tableName + "'";
            //System.out.println("Running: " + sql);
            ResultSet res = stmt.executeQuery(sql);
            if (res.next()) {
                //  System.out.println(res.getString(1));
                data = res.getString(1);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        //////////////////////////////////////////////////////////////////
        tv1 = (TextView)findViewById(R.id.textView1);
        tv1.setText(data);
        //listview = (ListView)findViewById(R.id.listView1);

        //  ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
        //              android.R.layout.simple_list_item_1,android.R.id.text1,data);
        //      listview.setAdapter(adapter);
    }
}

I have added all the jars that were required by the connectionHive part in the build path of the android project and also the permissions "uses-permission android:name="android.permission.INTERNET"" Logs file. Can anyone spot the error?

Upvotes: 0

Views: 59

Answers (1)

Mark B
Mark B

Reputation: 200501

If you read the error message it specifically says it can't find the class javax.security.sasl.Sasl. This class isn't packaged with Android and you will need to include it in your application. This looks like a likely place to start.

You might also try reading the other similar questions that have been asked here, like this one: Is there SASL implementation that works on Android?

Upvotes: 1

Related Questions