I am trying to do an XMPP Connection with Smack 4.1.0 rc1 from https://github.com/igniterealtime/Smack
I followed this guide: https://github.com/igniterealtime/Smack/wiki/Smack-4.1-Readme-and-Upgrade-Guide importing the Gradle.
Source code:
package com.example.xmpp_app;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
import java.io.IOException;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create the configuration for this new connection
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setUsernameAndPassword("test#example.com", "password123");
configBuilder.setResource("test");
configBuilder.setServiceName("example.com");
AbstractXMPPConnection connection = new XMPPTCPConnection(configBuilder.build());
// Connect to the server
try {
connection.connect();
} catch (SmackException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XMPPException e) {
e.printStackTrace();
}
// Log into the server
try {
connection.login();
} catch (XMPPException e) {
e.printStackTrace();
} catch (SmackException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// Disconnect from the server
connection.disconnect();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
build gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.xmpp_app"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile "org.igniterealtime.smack:smack-java7:4.1.0-rc1"
// Optional for XMPPTCPConnection
compile "org.igniterealtime.smack:smack-tcp:4.1.0-rc1"
// Optional for XMPP-IM (RFC 6121) support (Roster, Threaded Chats, …)
compile "org.igniterealtime.smack:smack-im:4.1.0-rc1"
// Optional for XMPP extensions support
compile "org.igniterealtime.smack:smack-extensions:4.1.0-rc1"
}
ERROR:
03-20 20:34:33.830 1005-1005/com.example.xmpp_app I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
03-20 20:34:33.830 1005-1005/com.example.xmpp_app W/dalvikvm﹕ VFY: unable to resolve virtual method 11345: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
03-20 20:34:33.850 1005-1005/com.example.xmpp_app D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
03-20 20:34:33.850 1005-1005/com.example.xmpp_app I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
03-20 20:34:33.850 1005-1005/com.example.xmpp_app W/dalvikvm﹕ VFY: unable to resolve virtual method 11351: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
03-20 20:34:33.850 1005-1005/com.example.xmpp_app D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
03-20 20:34:33.920 1005-1005/com.example.xmpp_app I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
03-20 20:34:33.920 1005-1005/com.example.xmpp_app W/dalvikvm﹕ VFY: unable to resolve virtual method 9039: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
03-20 20:34:33.950 1005-1005/com.example.xmpp_app D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
03-20 20:34:34.100 1005-1005/com.example.xmpp_app I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
03-20 20:34:34.110 1005-1005/com.example.xmpp_app W/dalvikvm﹕ VFY: unable to resolve virtual method 364: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
03-20 20:34:34.110 1005-1005/com.example.xmpp_app D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
03-20 20:34:34.150 1005-1005/com.example.xmpp_app I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
03-20 20:34:34.150 1005-1005/com.example.xmpp_app W/dalvikvm﹕ VFY: unable to resolve virtual method 386: Landroid/content/res/TypedArray;.getType (I)I
03-20 20:34:34.150 1005-1005/com.example.xmpp_app D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
03-20 20:34:35.790 1005-1005/com.example.xmpp_app D/dalvikvm﹕ GC_FOR_ALLOC freed 221K, 9% free 3164K/3452K, paused 105ms, total 115ms
03-20 20:34:38.420 1005-1005/com.example.xmpp_app D/dalvikvm﹕ GC_FOR_ALLOC freed 295K, 10% free 3382K/3744K, paused 90ms, total 93ms
03-20 20:34:40.250 1005-1005/com.example.xmpp_app D/dalvikvm﹕ GC_FOR_ALLOC freed 349K, 11% free 3531K/3952K, paused 80ms, total 85ms
03-20 20:34:40.310 1005-1005/com.example.xmpp_app E/dalvikvm﹕ Could not find class 'javax.naming.directory.InitialDirContext', referenced from method org.jivesoftware.smack.util.dns.javax.JavaxResolver.<clinit>
03-20 20:34:40.310 1005-1005/com.example.xmpp_app W/dalvikvm﹕ VFY: unable to resolve new-instance 1688 (Ljavax/naming/directory/InitialDirContext;) in Lorg/jivesoftware/smack/util/dns/javax/JavaxResolver;
03-20 20:34:40.320 1005-1005/com.example.xmpp_app D/dalvikvm﹕ VFY: replacing opcode 0x22 at 0x000c
03-20 20:34:40.360 1005-1005/com.example.xmpp_app I/dalvikvm﹕ Could not find method javax.naming.directory.DirContext.getAttributes, referenced from method org.jivesoftware.smack.util.dns.javax.JavaxResolver.lookupSRVRecords
03-20 20:34:40.360 1005-1005/com.example.xmpp_app W/dalvikvm﹕ VFY: unable to resolve interface method 12701: Ljavax/naming/directory/DirContext;.getAttributes (Ljava/lang/String;[Ljava/lang/String;)Ljavax/naming/directory/Attributes;
03-20 20:34:40.370 1005-1005/com.example.xmpp_app D/dalvikvm﹕ VFY: replacing opcode 0x72 at 0x0011
03-20 20:34:40.370 1005-1005/com.example.xmpp_app D/dalvikvm﹕ DexOpt: unable to opt direct call 0x319e at 0x0e in Lorg/jivesoftware/smack/util/dns/javax/JavaxResolver;.<clinit>
03-20 20:34:40.410 1005-1005/com.example.xmpp_app W/dalvikvm﹕ Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lorg/jivesoftware/smack/util/dns/javax/JavaxResolver;
03-20 20:34:41.330 1005-1005/com.example.xmpp_app I/dalvikvm﹕ Could not find method javax.security.sasl.Sasl.createSaslClient, referenced from method org.jivesoftware.smack.sasl.javax.SASLJavaXMechanism.authenticateInternal
03-20 20:34:41.330 1005-1005/com.example.xmpp_app W/dalvikvm﹕ VFY: unable to resolve static method 12731: Ljavax/security/sasl/Sasl;.createSaslClient ([Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljavax/security/auth/callback/CallbackHandler;)Ljavax/security/sasl/SaslClient;
03-20 20:34:41.340 1005-1005/com.example.xmpp_app D/dalvikvm﹕ VFY: replacing opcode 0x77 at 0x001a
03-20 20:34:41.340 1005-1005/com.example.xmpp_app W/dalvikvm﹕ VFY: unable to resolve exception class 1708 (Ljavax/security/sasl/SaslException;)
03-20 20:34:41.350 1005-1005/com.example.xmpp_app W/dalvikvm﹕ VFY: unable to find exception handler at addr 0x21
03-20 20:34:41.350 1005-1005/com.example.xmpp_app W/dalvikvm﹕ VFY: rejected Lorg/jivesoftware/smack/sasl/javax/SASLJavaXMechanism;.authenticateInternal ()V
03-20 20:34:41.350 1005-1005/com.example.xmpp_app W/dalvikvm﹕ VFY: rejecting opcode 0x0d at 0x0021
03-20 20:34:41.350 1005-1005/com.example.xmpp_app W/dalvikvm﹕ VFY: rejected Lorg/jivesoftware/smack/sasl/javax/SASLJavaXMechanism;.authenticateInternal ()V
03-20 20:34:41.350 1005-1005/com.example.xmpp_app W/dalvikvm﹕ Verifier rejected class Lorg/jivesoftware/smack/sasl/javax/SASLJavaXMechanism;
03-20 20:34:41.370 1005-1005/com.example.xmpp_app W/dalvikvm﹕ Exception Ljava/lang/VerifyError; thrown while initializing Lorg/jivesoftware/smack/SmackInitialization;
03-20 20:34:41.370 1005-1005/com.example.xmpp_app W/dalvikvm﹕ Exception Ljava/lang/VerifyError; thrown while initializing Lorg/jivesoftware/smack/ConnectionConfiguration;
03-20 20:34:41.380 1005-1005/com.example.xmpp_app D/AndroidRuntime﹕ Shutting down VM
03-20 20:34:41.380 1005-1005/com.example.xmpp_app W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb1a3bba8)
03-20 20:34:41.540 1005-1005/com.example.xmpp_app D/dalvikvm﹕ GC_FOR_ALLOC freed 438K, 14% free 3576K/4112K, paused 59ms, total 64ms
03-20 20:34:41.580 1005-1005/com.example.xmpp_app E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.xmpp_app, PID: 1005
java.lang.VerifyError: org/jivesoftware/smack/sasl/javax/SASLJavaXMechanism
at org.jivesoftware.smack.sasl.javax.SASLJavaXSmackInitializer.initialize(SASLJavaXSmackInitializer.java:28)
at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.java:232)
at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitialization.java:193)
at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:163)
at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:148)
at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:116)
at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration.java:38)
at com.example.xmpp_app.MainActivity.onCreate(MainActivity.java:29)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
03-20 20:39:44.485 1005-1005/com.example.xmpp_app I/Process﹕ Sending signal. PID: 1005 SIG: 9
Could someone help me with this problem, please? I am just trying to check if the connection works..
Replace smack-java7 with smack-android in your build.gradle. This is documented in Smack's README.
This is an upgrade of my last FCM XMPP Connection Server application. Now, this project uses the latest version at this time of the Smack library (4.1.8). I think that the library for android is pretty the same for the java server.
https://github.com/carlosCharz/fcmxmppserverv2
This is my sample java project to showcase the Firebase Cloud Messaging (FCM) XMPP Connection Server. This server sends data to a client app via the FCM CCS Server using the XMPP protocol.
https://github.com/carlosCharz/fcmxmppserver
And also I've created a video in youtube where I explain what the changes are.
https://www.youtube.com/watch?v=KVKEj6PeLTc
Hope you find it useful.
Here is a code snippet for the implementation:
public class CcsClient implements StanzaListener {
//Other code
public void connect() throws XMPPException, SmackException, IOException {
XMPPTCPConnection.setUseStreamManagementResumptionDefault(true);
XMPPTCPConnection.setUseStreamManagementDefault(true);
XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();
config.setServiceName("FCM XMPP Client Connection Server");
config.setHost(Util.FCM_SERVER);
config.setPort(Util.FCM_PORT);
config.setSecurityMode(SecurityMode.ifpossible);
config.setSendPresence(false);
config.setSocketFactory(SSLSocketFactory.getDefault());
// Launch a window with info about packets sent and received
config.setDebuggerEnabled(mDebuggable);
// Create the connection
connection = new XMPPTCPConnection(config.build());
// Connect
connection.connect();
// Enable automatic reconnection
ReconnectionManager.getInstanceFor(connection).enableAutomaticReconnection();
// Handle reconnection and connection errors
connection.addConnectionListener(new ConnectionListener() {
#Override
public void reconnectionSuccessful() {
logger.log(Level.INFO, "Reconnection successful ...");
// TODO: handle the reconnecting successful
}
#Override
public void reconnectionFailed(Exception e) {
logger.log(Level.INFO, "Reconnection failed: ",
e.getMessage());
// TODO: handle the reconnection failed
}
#Override
public void reconnectingIn(int seconds) {
logger.log(Level.INFO, "Reconnecting in %d secs", seconds);
// TODO: handle the reconnecting in
}
#Override
public void connectionClosedOnError(Exception e) {
logger.log(Level.INFO, "Connection closed on error");
// TODO: handle the connection closed on error
}
#Override
public void connectionClosed() {
logger.log(Level.INFO, "Connection closed");
// TODO: handle the connection closed
}
#Override
public void authenticated(XMPPConnection arg0, boolean arg1) {
logger.log(Level.INFO, "User authenticated");
// TODO: handle the authentication
}
#Override
public void connected(XMPPConnection arg0) {
logger.log(Level.INFO, "Connection established");
// TODO: handle the connection
}
});
// Handle incoming packets (the class implements the StanzaListener)
connection.addAsyncStanzaListener(this,
stanza -> stanza.hasExtension(Util.FCM_ELEMENT_NAME, Util.FCM_NAMESPACE));
// Log all outgoing packets
connection.addPacketInterceptor(stanza -> logger.log(Level.INFO,
"Sent: {}", stanza.toXML()), stanza -> true);
connection.login(fcmServerUsername, mApiKey);
logger.log(Level.INFO, "Logged in: " + fcmServerUsername);
}
}
Try to connect server with XMPPConnection class.
How to connect:
XMPPConnection con = new XMPPTCPConnection("igniterealtime.org");
con.connect();
Related
Hello so this is my code, somehow i still get error down there i described error , any help would be appreciated, I am not really expert with import of this and especially emulator itself.
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
public class MyAdapter extends RecyclerView.Adapter<FoodViewHolder>{
//1st error on this line (MyAdapter.onBindViewHolder(MyAdapter.java:17)
private Context mContext;
private List<FoodData> myFoodList;
public MyAdapter(Context mContext, List<FoodData> myFoodList) {
this.mContext = mContext;
this.myFoodList = myFoodList;
}
#Override
public FoodViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View mView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.recycler_row_item,viewGroup,false);
return new FoodViewHolder(mView);
}
#Override
public void onBindViewHolder(#NonNull final FoodViewHolder foodViewHolder, int i) {
foodViewHolder.imageView.setImageResource(myFoodList.get(i).getItemImage());
// 2nd error on this line (MyAdapter.onBindViewHolder(MyAdapter.java:39)
foodViewHolder.mTitle.setText(myFoodList.get(i).getItemName());
foodViewHolder.mDescription.setText(myFoodList.get(i).getItemDescription());
foodViewHolder.mPrice.setText(myFoodList.get(i).getItemPrice());
foodViewHolder.mCardView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(mContext, DetailActivity.class);
intent.putExtra("Image",myFoodList.get(foodViewHolder.getAdapterPosition()).getItemImage());
intent.putExtra("Description",myFoodList.get(foodViewHolder.getAdapterPosition()).getItemDescription());
mContext.startActivity(intent);
}
});
}
#Override
public int getItemCount() {
return myFoodList.size();
}
}
class FoodViewHolder extends RecyclerView.ViewHolder {
ImageView imageView;
TextView mTitle , mDescription, mPrice;
CardView mCardView;
public FoodViewHolder(View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.ivImage);
mTitle = itemView.findViewById(R.id.tvTitle);
mDescription = itemView.findViewById(R.id.tvDescription);
mPrice = itemView.findViewById(R.id.tvPrice);
mCardView = itemView.findViewById(R.id.myCardView);
}
}
Hello guys I'm beginner in android studio .someone tell me how can i solve this error's .
thanks in advance.
// Errors
03-10 08:14:36.172 59-59/? E/baseband-redis: Redis baseband write connect error: Connection refused
--------- beginning of /dev/log/main
03-10 08:14:36.276 59-59/? E/baseband-redis: Redis baseband write connect error: Connection refused
03-10 08:14:36.376 59-59/? E/baseband-redis: Redis baseband write connect error: Connection refused
03-10 08:14:36.480 59-59/? E/baseband-redis: cannot connect, exit
03-10 08:14:37.876 192-192/? E/network_profile_handler: init_all_network_profile_state: wlan: eth1 `phone:rmnet0`
03-10 08:14:49.644 192-380/? E/network_profile_handler: Error. network interface data NULL
03-10 08:14:52.424 199-199/? E/PhonePolicy: Could not preload class for phone policy:
com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback
03-10 08:14:52.452 390-390/? E/setdpi: Setting DPI to 320
03-10 08:14:52.984 381-382/? E/SurfaceFlinger: setOrientation with orientation=0
03-10 08:14:52.984 381-382/? E/SurfaceFlinger: setOrientation orientation=0
03-10 08:14:52.984 381-382/? E/FramebufferNativeWindow: setOrientation with fbDev=0xb8eec2b8 fbDev-
>setOrientation=0x0 orientation=0
03-10 08:14:55.764 408-408/system_process E/BatteryService: usbOnlinePath not found
03-10 08:14:55.764 408-408/system_process E/BatteryService: batteryHealthPath not found
03-10 08:14:55.764 408-408/system_process E/BatteryService: batteryTemperaturePath not found
03-10 08:15:03.056 408-460/system_process E/libsuspend: Error opening /sys/power/autosleep: No such file or directory
03-10 08:15:03.056 408-460/system_process E/libsuspend: Error opening /sys/power/wakeup_count: Permission denied
03-10 08:15:03.056 408-460/system_process E/libsuspend: failed to initialize autosuspend
03-10 08:15:03.408 201-433/? E/WVMExtractor: Failed to open libwvm.so
03-10 08:15:03.604 408-468/system_process E/EventHub: could not get driver version for /dev/input/mouse1, Not a typewriter
03-10 08:15:03.760 408-468/system_process E/EventHub: could not get driver version for /dev/input/mouse0, Not a typewriter
03-10 08:15:03.776 201-201/? E/WVMExtractor: Failed to open libwvm.so
03-10 08:15:03.860 408-468/system_process E/EventHub: could not get driver version for /dev/input/mice, Not a typewriter
03-10 08:15:03.916 408-425/system_process E/MobileDataStateTracker: default: Ignoring feature request because could not acquire PhoneService
03-10 08:15:03.916 408-425/system_process E/MobileDataStateTracker: default: Could not enable APN type "default"
03-10 08:15:03.932 408-493/system_process E/WifiStateMachine: Failed to reload STA firmware java.lang.IllegalStateException: command '2 softap fwreload eth1 STA' failed with '400 2 Softap operation failed (Success)'
03-10 08:15:03.940 408-503/system_process E/WifiHW: Unable to open connection to supplicant on "eth1": No such file or directory
03-10 08:15:05.388 408-493/system_process E/WifiConfigStore: Error parsing configurationjava.io.FileNotFoundException: /data/misc/wifi/ipconfig.txt: open failed: ENOENT (No such file or directory)
03-10 08:15:05.408 408-493/system_process E/WifiStateMachine: Failed to set country code us
03-10 08:15:05.408 408-493/system_process E/WifiStateMachine: Failed to set frequency band 0
03-10 08:15:05.976 408-654/system_process E/GpsLocationProvider: no AGPS interface in agps_data_conn_open
03-10 08:15:07.128 568-687/com.android.inputmethod.latin E/ActivityThread: Failed to find provider info for com.android.inputmethod.latin.dictionarypack
03-10 08:15:07.132 568-687/com.android.inputmethod.latin E/BinaryDictionaryGetter: Could not find a dictionary pack
03-10 08:15:07.988 408-495/system_process E/ConnectivityService: no dns provided for WIFI - using 8.8.8.8
03-10 08:15:07.992 408-495/system_process E/ConnectivityService: exception setting default dns interface: java.lang.IllegalArgumentException: command '10 resolver setifdns eth1' failed with '500 10 Wrong number of arguments to resolver setifdns'
03-10 08:15:09.520 408-493/system_process E/WifiStateMachine: Failed to set country code us
03-10 08:15:10.500 201-201/? E/WVMExtractor: Failed to open libwvm.so
03-10 08:15:10.600 201-433/? E/WVMExtractor: Failed to open libwvm.so
03-10 08:15:10.836 201-201/? E/WVMExtractor: Failed to open libwvm.so
03-10 08:15:10.924 201-433/? E/WVMExtractor: Failed to open libwvm.so
03-10 08:15:11.156 201-201/? E/WVMExtractor: Failed to open libwvm.so
03-10 08:15:29.628 381-382/? E/SocketStream: readFully was waiting for 716352 bytes, got 30660
03-10 08:15:29.628 381-382/? E/SocketStream: readFully was waiting for 685692 bytes, got 39420
03-10 08:15:29.628 381-382/? E/SocketStream: readFully was waiting for 646272 bytes, got 43800
03-10 08:15:29.636 381-382/? E/SocketStream: readFully was waiting for 602472 bytes, got 143080
03-10 08:15:29.652 381-382/? E/SocketStream: readFully was waiting for 459392 bytes, got 153300
03-10 08:15:29.652 381-382/? E/SocketStream: readFully was waiting for 306092 bytes, got 161920
03-10 08:15:30.716 1050-1050/? E/dalvikvm: Could not find class 'androidx.core.view.ViewCompat$2', referenced from method androidx.core.view.ViewCompat.addOnUnhandledKeyEventListener
03-10 08:15:30.716 1050-1050/? E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method androidx.core.view.ViewCompat.dispatchApplyWindowInsets
03-10 08:15:30.764 1050-1050/? E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method androidx.core.view.ViewCompat.onApplyWindowInsets
03-10 08:15:30.772 1050-1050/? E/dalvikvm: Could not find class 'android.view.View$OnUnhandledKeyEventListener', referenced from method androidx.core.view.ViewCompat.removeOnUnhandledKeyEventListener
03-10 08:15:30.784 1050-1050/? E/dalvikvm: Could not find class 'androidx.core.view.ViewCompat$1', referenced from method androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener
03-10 08:15:30.936 1050-1050/? E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method androidx.appcompat.widget.AppCompatImageHelper.hasOverlappingRendering
03-10 08:15:30.996 1050-1050/? E/dalvikvm: Could not find class 'android.view.textclassifier.TextClassificationManager', referenced from method androidx.appcompat.widget.AppCompatTextClassifierHelper.getTextClassifier
03-10 08:15:31.980 1050-1050/? E/dalvikvm-heap: Out of memory on a 33177612-byte allocation.
03-10 08:15:32.108 1050-1050/? A/libc: Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 1050 (deshtourstplace)
03-10 08:15:34.584 408-467/system_process E/InputDispatcher: channel '537d5654 com.allexamquestions.xyz.himachalpradeshtourstplace/com.allexamquestions.xyz.himachalpradeshtourstplace.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
public class MyAdapter extends RecyclerView.Adapter<FoodViewHolder>{
replace with
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.FoodViewHolder>{
//1st error on this line
(MyAdapter.onBindViewHolder(MyAdapter.java:17)
You have to initialize the constructor of RecyclerView.Adapter. By calling super(); you override the constructor.
public class MyAdapter extends RecyclerView.Adapter<FoodViewHolder>{
//1st error on this line (MyAdapter.onBindViewHolder(MyAdapter.java:17)
private Context mContext;
private List<FoodData> myFoodList;
public MyAdapter(Context mContext, List<FoodData> myFoodList) {
super();
this.mContext = mContext;
this.myFoodList = myFoodList;
}
...
}
I'm working on a proof-of-concept app so that I can implement the feature in a larger app I'm making. I'm a bit new to Java and Android Dev but hopefully this shouldn't be too simple or complex of a question.
Basically, I'm trying to read in a list of strings from a CSV file and make it usable in displaying the list on the app's Main Activity.
I'm using an external class for reading in CSV's. Here's the class code:
CSVFile.java
package com.yourtechwhiz.listdisplay;
import android.util.Log;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class CSVFile {
InputStream inputStream;
public CSVFile(InputStream inputStream){
this.inputStream = inputStream;
}
public List read(){
List resultList = new ArrayList();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
try {
String csvLine;
while ((csvLine = reader.readLine()) != null) {
String[] row = csvLine.split(",");
resultList.add(row);
Log.d("VariableTag", row[0].toString());
}
}
catch (IOException ex) {
throw new RuntimeException("Error in reading CSV file: "+ex);
}
finally {
try {
inputStream.close();
}
catch (IOException e) {
throw new RuntimeException("Error while closing input stream: "+e);
}
}
return resultList;
}
}
Here's my main activity code:
MainActivity.java
package com.yourtechwhiz.listdisplay;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
// Array of strings that's used to display on screen
String[] mobileArray = {"Android","IPhone","WindowsMobile","Blackberry",
"WebOS","Ubuntu","Windows7","Max OS X"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
prepArray();
//Display List on Activity
ArrayAdapter adapter = new ArrayAdapter<String>(this,
R.layout.activity_listview, mobileArray);
ListView listView = (ListView) findViewById(R.id.mobile_list);
listView.setAdapter(adapter);
}
//Get list of strings from CSV ready to use
private void prepArray() {
InputStream inputStream = getResources().openRawResource(R.raw.strings);
CSVFile csvFile = new CSVFile(inputStream);
List myList = csvFile.read();
//This is where it has an error
//Set first array in myList to this new array myArray
String[] myArray = myList.get(0);
}
}
I'm not actually to the point of setting the mobileArray array yet. Right now I'm just trying to "extract" the information out of the List object myList...
Can someone explain to me how this is done? Maybe I'm just not understanding the List type completely. It seems like when resultList is returned in the CSVFile read method, it's returned as an List object consisting of String array objects. But I can't seem to get it to work like that.
Any help is appreciated!
FINAL EDIT (working code)
private void prepArray() {
try{
CSVReader reader = new CSVReader(new InputStreamReader(getResources().openRawResource(R.raw.strings)));//Specify asset file name
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
// nextLine[] is an array of values from the line
System.out.println(nextLine[0] + nextLine[1] + "etc...");
Log.d("VariableTag", nextLine[0]);
}
}catch(Exception e){
e.printStackTrace();
Toast.makeText(this, "The specified file was not found", Toast.LENGTH_SHORT).show();
}
}
EDIT
Now my prepArray function looks like the following:
private void prepArray() {
try{
String csvfileString = this.getApplicationInfo().dataDir + File.separatorChar + "strings.csv"
File csvfile = new File(csvfileString);
CSVReader reader = new CSVReader(new FileReader("csvfile.getAbsolutePath()"));
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
// nextLine[] is an array of values from the line
System.out.println(nextLine[0] + nextLine[1] + "etc...");
}
}catch(FileNotFoundException e){
e.printStackTrace();
Toast.makeText(this, "The specified file was not found", Toast.LENGTH_SHORT).show();
}
}
Still produces the FileNotFoundException.
EDIT 2/3
Here's the log that's produced when I run the app on an actual phone with the strings.csv in a subfolder of strings (src\main\assets\strings\strings.csv) with the change you requested to the code:
03/27 17:44:01: Launching app
$ adb push C:\Users\Roy\AndroidStudioProjects\ListDisplay\app\build\outputs\apk\app-debug.apk /data/local/tmp/com.yourtechwhiz.listdisplay
$ adb shell pm install -r "/data/local/tmp/com.yourtechwhiz.listdisplay"
pkg: /data/local/tmp/com.yourtechwhiz.listdisplay
Success
$ adb shell am start -n "com.yourtechwhiz.listdisplay/com.yourtechwhiz.listdisplay.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Connecting to com.yourtechwhiz.listdisplay
D/HyLog: I : /data/font/config/sfconfig.dat, No such file or directory (2)
D/HyLog: I : /data/font/config/dfactpre.dat, No such file or directory (2)
D/HyLog: I : /data/font/config/sfconfig.dat, No such file or directory (2)
W/ActivityThread: Application com.yourtechwhiz.listdisplay is waiting for the debugger on port 8100...
I/System.out: Sending WAIT chunk
I/dalvikvm: Debugger is active
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
Connected to the target VM, address: 'localhost:8609', transport: 'socket'
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1498)
I/dalvikvm: Could not find method android.view.Window$Callback.onProvideKeyboardShortcuts, referenced from method android.support.v7.view.WindowCallbackWrapper.onProvideKeyboardShortcuts
W/dalvikvm: VFY: unable to resolve interface method 16152: Landroid/view/Window$Callback;.onProvideKeyboardShortcuts (Ljava/util/List;Landroid/view/Menu;I)V
D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
W/dalvikvm: VFY: unable to resolve interface method 16154: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
W/dalvikvm: VFY: unable to resolve interface method 16158: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
W/dalvikvm: VFY: unable to resolve virtual method 455: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
W/dalvikvm: VFY: unable to resolve virtual method 477: Landroid/content/res/TypedArray;.getType (I)I
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0008
I/dalvikvm: Could not find method android.widget.FrameLayout.startActionModeForChild, referenced from method android.support.v7.widget.ActionBarContainer.startActionModeForChild
W/dalvikvm: VFY: unable to resolve virtual method 16589: Landroid/widget/FrameLayout;.startActionModeForChild (Landroid/view/View;Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
D/dalvikvm: VFY: replacing opcode 0x6f at 0x0002
I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method android.support.v7.content.res.AppCompatResources.getColorStateList
W/dalvikvm: VFY: unable to resolve virtual method 269: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable
W/dalvikvm: VFY: unable to resolve virtual method 418: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity
W/dalvikvm: VFY: unable to resolve virtual method 420: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
W/dalvikvm: VFY: unable to resolve instanceof 140 (Landroid/graphics/drawable/RippleDrawable;) in Landroid/support/v7/widget/AppCompatImageHelper;
D/dalvikvm: VFY: replacing opcode 0x20 at 0x000c
W/System.err: java.io.FileNotFoundException: /csvfile.getAbsolutePath(): open failed: ENOENT (No such file or directory)
W/System.err: at libcore.io.IoBridge.open(IoBridge.java:462)
W/System.err: at java.io.FileInputStream.<init>(FileInputStream.java:78)
W/System.err: at java.io.FileInputStream.<init>(FileInputStream.java:105)
W/System.err: at java.io.FileReader.<init>(FileReader.java:66)
W/System.err: at com.yourtechwhiz.listdisplay.MainActivity.prepArray(MainActivity.java:43)
W/System.err: at com.yourtechwhiz.listdisplay.MainActivity.onCreate(MainActivity.java:26)
W/System.err: at android.app.Activity.performCreate(Activity.java:5287)
W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2145)
W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2231)
W/System.err: at android.app.ActivityThread.access$700(ActivityThread.java:139)
W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1401)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err: at android.os.Looper.loop(Looper.java:137)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5082)
W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:598)
W/System.err: at dalvik.system.NativeStart.main(Native Method)
W/System.err: Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
W/System.err: at libcore.io.Posix.open(Native Method)
W/System.err: at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
W/System.err: at libcore.io.IoBridge.open(IoBridge.java:446)
W/System.err: ... 19 more
I/Adreno-EGL: <qeglDrvAPI_eglInitialize:385>: EGL 1.4 QUALCOMM build: ()
OpenGL ES Shader Compiler Version: E031.24.00.01
Build Date: 12/27/13 Fri
Local Branch: qualcomm_only
Remote Branch:
Local Patches:
Reconstruct Branch:
D/OpenGLRenderer: Enabling debug mode 0
D/OpenGLRenderer: GL error from OpenGLRenderer: 0x502
E/OpenGLRenderer: GL_INVALID_OPERATION
Try OpenCSV - it will make your life easier.
First, add this package to your gradle dependencies as follows
implementation 'com.opencsv:opencsv:4.6'
Then you can either do
import com.opencsv.CSVReader;
import java.io.IOException;
import java.io.FileReader;
...
try {
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
// nextLine[] is an array of values from the line
System.out.println(nextLine[0] + nextLine[1] + "etc...");
}
} catch (IOException e) {
}
or
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
List myEntries = reader.readAll();
Edit after comment
try {
File csvfile = new File(Environment.getExternalStorageDirectory() + "/csvfile.csv");
CSVReader reader = new CSVReader(new FileReader(csvfile.getAbsolutePath()));
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
// nextLine[] is an array of values from the line
System.out.println(nextLine[0] + nextLine[1] + "etc...");
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(this, "The specified file was not found", Toast.LENGTH_SHORT).show();
}
If you want to package the .csv file with the application and have it install on the internal storage when the app installs, create an assets folder in your project src/main folder (e.g., c:\myapp\app\src\main\assets\), and put the .csv file in there, then reference it like this in your activity:
String csvfileString = this.getApplicationInfo().dataDir + File.separatorChar + "csvfile.csv"
File csvfile = new File(csvfileString);
The following snippet reads a CSV file from the raw resources folder (which will be packed into your .apk file upon compilation).
Android by default does not create the raw folder. Create a raw folder under res/raw in your project and copy your CSV File into it. Keep the name of the CSV file lower case and convert it into text format when asked. My CSV file name is welldata.csv.
In the snippet, WellData is the model class (with constructor, getter and setter) and wellDataList is the ArrayList to store the data.
private void readData() {
InputStream is = getResources().openRawResource(R.raw.welldata);
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, Charset.forName("UTF-8")));
String line = "";
try {
while ((line = reader.readLine()) != null) {
// Split the line into different tokens (using the comma as a separator).
String[] tokens = line.split(",");
// Read the data and store it in the WellData POJO.
WellData wellData = new WellData();
wellData.setOwner(tokens[0]);
wellData.setApi(tokens[1]);
wellData.setLongitude(tokens[2]);
wellData.setLatitude(tokens[3]);
wellData.setProperty(tokens[4]);
wellData.setWellName(tokens[5]);
wellDataList.add(wellData);
Log.d("MainActivity" ,"Just Created " + wellData);
}
} catch (IOException e1) {
Log.e("MainActivity", "Error" + line, e1);
e1.printStackTrace();
}
}
This worked for me in Kotlin. You will need to place the myfile.csv file in the res/raw folder, creating the folder if it isn't there.
val inputStream: InputStream = resources.openRawResource(R.raw.myfile)
val reader = BufferedReader(InputStreamReader(inputStream, Charset.forName("UTF-8")))
reader.readLines().forEach {
//get a string array of all items in this line
val items = it.split(",")
//do what you want with each item
}
New coder for Android Studio. I've been researching how to read CSV files and this works best for my needs. (s0, s1, etc. Strings were defined at the beginning of my program).
File fileDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File fileToGet = new File(fileDirectory,"aFileName.csv");
try {
BufferedReader br = new BufferedReader(new FileReader(fileToGet));
String line;
while ((line = br.readLine()) !=null) {
String[] tokens = line.split(",");
s0=tokens[0].toString(); s1=tokens[1].toString(); s2=tokens[2].toString();
s3=tokens[3].toString(); s4=tokens[4].toString(); s5=tokens[5].toString();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Here is a simple way, which worked for me.
MainActivity.java
// Do not forget to call readWeatherData() in onCreate or wherever you need to :)
// Defining ordered collection as WeatherSample class
private List<WeatherSample> weatherSamples = new ArrayList<>();
private void readWeatherData() {
// Read the raw csv file
InputStream is = getResources().openRawResource(R.raw.data);
// Reads text from character-input stream, buffering characters for efficient reading
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, Charset.forName("UTF-8"))
);
// Initialization
String line = "";
// Initialization
try {
// Step over headers
reader.readLine();
// If buffer is not empty
while ((line = reader.readLine()) != null) {
Log.d("MyActivity","Line: " + line);
// use comma as separator columns of CSV
String[] tokens = line.split(",");
// Read the data
WeatherSample sample = new WeatherSample();
// Setters
sample.setMonth(tokens[0]);
sample.setRainfall(Double.parseDouble(tokens[1]));
sample.setSumHours(Integer.parseInt(tokens[2]));
// Adding object to a class
weatherSamples.add(sample);
// Log the object
Log.d("My Activity", "Just created: " + sample);
}
} catch (IOException e) {
// Logs error with priority level
Log.wtf("MyActivity", "Error reading data file on line" + line, e);
// Prints throwable details
e.printStackTrace();
}
}
WeatherSample.java
public class WeatherSample {
private String month;
private double rainfall;
private int sumHours;
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
public double getRainfall() {
return rainfall;
}
public void setRainfall(double rainfall) {
this.rainfall = rainfall;
}
public int getSumHours() {
return sumHours;
}
public void setSumHours(int sumHours) {
this.sumHours = sumHours;
}
#Override
public String toString() {
return "WeatherSample{" +
"month='" + month + '\'' +
", rainfall=" + rainfall +
", sumHours=" + sumHours +
'}';
}
}
As for your source CSV file, first create directory:
app -> res (Right click) -> New -> Android resource directory -> Resource type (raw) -> OK
Then copy and paste your .csv file into that newly appeared directory:
raw (Right click) -> Show in Explorer
Here is the source file I used for the project:
data.csv
If you still have some error, here is a link to the full project:
Source Code
Hope it helps, have fun :)
With a file named filename.csv in the folder res/raw:
private void gettingItemsFromCSV() {
BufferedInputStream bufferedInputStream = new BufferedInputStream(getResources().openRawResource(R.raw.filename));
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(bufferedInputStream));
try {
String line;
while ((line = bufferedReader.readLine()) != null) {
Log.i("Test123", line);
}
} catch (Exception e) {
e.printStackTrace();
}
}
In the latest Android 11 version, you need to do something like this:
val reader = CSVReader(
getApplication<Application>().applicationContext.assets.open("file-name.csv")
.reader()
)
val myEntries: List<Array<String>> = reader.readAll()
In build.gradle(app level):
dependencies {
...
// CSV reader
implementation 'com.opencsv:opencsv:4.6'
}
In AndroidManifest.xml:
<application
android:requestLegacyExternalStorage="true"
...
i have a strange logcat message while creating app for Android .I'm calling a webservice and creating a listview in the process. I' m currently using retrofit2 for this.
public ArrayList<AgencyModel> DownloadAgencyData() {
RestApi.getUnicsAgencyApi().getStreams().enqueue(new Callback<ArrayList<AgencyModel>>() {
#Override
public void onFailure(Call<ArrayList<AgencyModel>> arg0, Throwable arg1) {
// TODO Auto-generated method stub
Log.e("Error in parsing", arg0.toString());
}
#Override
public void onResponse(Call<ArrayList<AgencyModel>> AgencyModelData,
Response<ArrayList<AgencyModel>> response) {
// TODO Auto-generated method stub
mstreamData = new ArrayList<AgencyModel>();
// ADD TO List here!!!!!!!!
// Log.e("Response", "" + response.body().size());
if(response.isSuccessful()){
mstreamData.addAll(response.body());
}
}
});
return mstreamData;
}
The builder class is as follows:
public class RestApi {
private static String ENDPOINT_URL = "http://192.168.1.102/UnicsApplication/";
private static UnicsAgencyApi sUnicsAgencyApi;
private static Retrofit retrofit;
public static UnicsAgencyApi getUnicsAgencyApi() {
if (sUnicsAgencyApi == null) {
retrofit = new Retrofit.Builder().baseUrl(ENDPOINT_URL).addConverterFactory(GsonConverterFactory.create())
.build();
sUnicsAgencyApi = retrofit.create(UnicsAgencyApi.class);
}
return sUnicsAgencyApi;
}
public interface UnicsAgencyApi {
//#GET("api/uconnectservice/AllAgency")
#GET("api/uconnectservice")
Call<ArrayList<AgencyModel>> getStreams();
}
}
The Complete logcat message it get is as follows:
01-03 16:55:54.592: W/ResourceType(2794): CREATING STRING CACHE OF 36 bytes
01-03 16:55:54.912: I/ActivityManager(2794): Timeline: Activity_idle id: android.os.BinderProxy#41a364b0 time:190796801
01-03 16:56:06.152: D/LIST STATUS(2794): AgencyList is null
01-03 16:56:06.182: W/dalvikvm(2794): VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
01-03 16:56:06.182: W/dalvikvm(2794): VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
01-03 16:56:06.182: I/dalvikvm(2794): Could not find method java.nio.file.Files.newOutputStream, referenced from method okio.Okio.sink
01-03 16:56:06.182: W/dalvikvm(2794): VFY: unable to resolve static method 3073: Ljava/nio/file/Files;.newOutputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/OutputStream;
01-03 16:56:06.182: D/dalvikvm(2794): VFY: replacing opcode 0x71 at 0x000a
01-03 16:56:06.192: W/dalvikvm(2794): VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
01-03 16:56:06.192: W/dalvikvm(2794): VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
01-03 16:56:06.192: I/dalvikvm(2794): Could not find method java.nio.file.Files.newInputStream, referenced from method okio.Okio.source
01-03 16:56:06.192: W/dalvikvm(2794): VFY: unable to resolve static method 3072: Ljava/nio/file/Files;.newInputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/InputStream;
01-03 16:56:06.192: D/dalvikvm(2794): VFY: replacing opcode 0x71 at 0x000a
01-03 16:56:16.192: E/Error in parsing(2794): retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall#41bdff80
I was hoping anybody could guide or explain why this is happening.
For clarity sake here is my JAVA model
package com.nickSoft.Models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class AgencyModel {
#SerializedName("AgencyName")
#Expose
private String agencyName;
#SerializedName("AgencyLocation")
#Expose
private String agencyLocation;
#SerializedName("AgencyPhoneNumber")
#Expose
private String agencyPhoneNumber;
#SerializedName("AgencyGPSCoordinates")
#Expose
private String agencyGPSCoordinates;
#SerializedName("AgencyHours")
#Expose
private String agencyHours;
public String getAgencyName() {
return agencyName;
}
public void setAgencyName(String agencyName) {
this.agencyName = agencyName;
}
public String getAgencyLocation() {
return agencyLocation;
}
public void setAgencyLocation(String agencyLocation) {
this.agencyLocation = agencyLocation;
}
public String getAgencyPhoneNumber() {
return agencyPhoneNumber;
}
public void setAgencyPhoneNumber(String agencyPhoneNumber) {
this.agencyPhoneNumber = agencyPhoneNumber;
}
public String getAgencyGPSCoordinates() {
return agencyGPSCoordinates;
}
public void setAgencyGPSCoordinates(String agencyGPSCoordinates) {
this.agencyGPSCoordinates = agencyGPSCoordinates;
}
public String getAgencyHours() {
return agencyHours;
}
public void setAgencyHours(String agencyHours) {
this.agencyHours = agencyHours;
}
}
and here is the JSON coming in from webservice:
[{"AgencyName":"Head-Office/Branch","AgencyLocation":"Immeuble Grand Carrefour Rue Marie Gocker,Yaounde","AgencyPhoneNumber":"+237222229610/691698762","AgencyGPSCoordinates":"GPS Position","AgencyHours":"8:00-16:00"},{"AgencyName":"Yaounde-Marche-Centrale Branch","AgencyLocation":"Immeuble Grand Carrefour Rue Marie Gocker,Yaounde","AgencyPhoneNumber":"+237222041661/22229604/91697426","AgencyGPSCoordinates":"GPS Position","AgencyHours":"8:00-16:00"},{"AgencyName":"Bamenda Branch","AgencyLocation":"Evidence Building, City Chemist Roundabout,Bamenda","AgencyPhoneNumber":"+237222041665/233364170/691697553","AgencyGPSCoordinates":"GPS Position","AgencyHours":"8:00-16:00"},{"AgencyName":"Deido Branch","AgencyLocation":"Face Boulangerie COAF, Douala","AgencyPhoneNumber":"+237222041660/633402641/691697494","AgencyGPSCoordinates":"GPS Position","AgencyHours":"8:00-16:00"},{"AgencyName":"Bafut Branch","AgencyLocation":"Midland Centre, 3 Corners Njinteh, Bafut","AgencyPhoneNumber":"+237675025263/691698716","AgencyGPSCoordinates":"GPS Position","AgencyHours":"8:00-16:00"},{"AgencyName":"Buea Branch","AgencyLocation":"University Junction, Molyko, Buea","AgencyPhoneNumber":" +237222041664/333323322/691698625","AgencyGPSCoordinates":"GPS Position","AgencyHours":"8:00-16:00"},{"AgencyName":"Bonaberi Branch","AgencyLocation":"Cimetière, Immeuble Pharmacie Bonaberi, Douala","AgencyPhoneNumber":"+237222041663/333392710/691697617","AgencyGPSCoordinates":"GPS Position","AgencyHours":"8:00-16:00"},{"AgencyName":"Biyem-Assi Branch","AgencyLocation":"Carrefour Biyem-assi ,Yaounde","AgencyPhoneNumber":"+237222041662/222316710/691698667","AgencyGPSCoordinates":"GPS Position","AgencyHours":"8:00-16:00"},{"AgencyName":"Limbe Branch","AgencyLocation":"Down Beach, Sappa Road, Limbe","AgencyPhoneNumber":"+237222041690/222041693/691698628","AgencyGPSCoordinates":"GPS Position","AgencyHours":"8:00-16:00"},{"AgencyName":"Kribi Branch","AgencyLocation":"Adjacent Auto Ecole Française Rue Petit Paris, Kribi","AgencyPhoneNumber":"+237222041691/222041692/691698632","AgencyGPSCoordinates":"GPS Position","AgencyHours":"8:00-16:00"},{"AgencyName":"Akwa Branch","AgencyLocation":"Boulevard de la Liberté, Douala","AgencyPhoneNumber":"+237222041670/691698663","AgencyGPSCoordinates":"GPS Position","AgencyHours":"8:00-16:00"},{"AgencyName":"Dakar Branch","AgencyLocation":"Marché Bilongué, Douala","AgencyPhoneNumber":"+237691698627","AgencyGPSCoordinates":"GPS Position","AgencyHours":"8:00-16:00"},{"AgencyName":"Bambili Branch","AgencyLocation":"Three Corners, Bambili","AgencyPhoneNumber":"+237222054199/691697441","AgencyGPSCoordinates":"GPS Position","AgencyHours":"8:00-16:00"},{"AgencyName":"Tchinga Branch","AgencyLocation":"Ave du 27 Août 1940,Yaounde","AgencyPhoneNumber":"691907381","AgencyGPSCoordinates":"GPS Position","AgencyHours":"8:00-16:00"},{"AgencyName":"Kumba Branch","AgencyLocation":"Kumba","AgencyPhoneNumber":"+237222041664","AgencyGPSCoordinates":"GPS Position","AgencyHours":"8:00-16:00"}]
Any guidance is greatly appreciated.
I am trying to make a simple weather app. Everytime I try and access the Yahoo weather api to return a JSON object, I get this exception. To do the task without the api, I copy pasted the JSON object into a separate string and have been working with that string as the JSON object.
This is my asynch task:
public class WeatherInfoThread extends AsyncTask{
#Override
protected String doInBackground(Void... params) {
String resultString = null;
try {
url = new URL("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22"+location+"%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys");
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
connection = url.openConnection();
} catch (IOException e) {
e.printStackTrace();
}
try {
inputStream = connection.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
try {
jsonInfo = bufferedReader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
resultString = jsonInfo;
try {
weatherinfo = new JSONObject(testString);
// Log.d(JSON_INFO,weatherinfo.toString()+"df");
JSONObject channel = weatherinfo.getJSONObject("query").getJSONObject("results").getJSONObject("channel");
JSONObject item = channel.getJSONObject("item");
currentTemp = item.getJSONObject("condition");
cCurrentInt = currentTemp.getInt("code");
forecast = item.getJSONArray("forecast");
cOne = forecast.getJSONObject(1).getString("text");
cTwo = forecast.getJSONObject(2).getString("text");
cThree = forecast.getJSONObject(3).getString("text");
cFour = forecast.getJSONObject(4).getString("text");
cFive = forecast.getJSONObject(5).getString("text");
dOne = forecast.getJSONObject(1).getString("day");
dTwo = forecast.getJSONObject(2).getString("day");
dThree = forecast.getJSONObject(3).getString("day");
dFour = forecast.getJSONObject(4).getString("day");
dFive = forecast.getJSONObject(5).getString("day");
// Log.d(JSON_INFO,forecast.get(1).toString()+"ddf");
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
This is the error I got:
12-16 16:48:06.677 10523-10549/com.example.aakashmahesh.weatherapp E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at libcore.net.http.HttpConnection.(HttpConnection.java:70)
at libcore.net.http.HttpConnection.(HttpConnection.java:50)
at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:461)
at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)
at com.example.aakashmahesh.weatherapp.MainActivity$WeatherInfoThread.doInBackground(MainActivity.java:269)
at com.example.aakashmahesh.weatherapp.MainActivity$WeatherInfoThread.doInBackground(MainActivity.java:250)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
at libcore.io.Posix.getaddrinfo(Native Method)
at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55)
at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at libcore.net.http.HttpConnection.(HttpConnection.java:70)
at libcore.net.http.HttpConnection.(HttpConnection.java:50)
at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:461)
at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)
at com.example.aakashmahesh.weatherapp.MainActivity$WeatherInfoThread.doInBackground(MainActivity.java:269)
at com.example.aakashmahesh.weatherapp.MainActivity$WeatherInfoThread.doInBackground(MainActivity.java:250)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: libcore.io.ErrnoException: getaddrinfo failed: EACCES (Permission denied)
at libcore.io.Posix.getaddrinfo(Native Method)
at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55)
at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at libcore.net.http.HttpConnection.(HttpConnection.java:70)
at libcore.net.http.HttpConnection.(HttpConnection.java:50)
at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:461)
at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)
at com.example.aakashmahesh.weatherapp.MainActivity$WeatherInfoThread.doInBackground(MainActivity.java:269)
at com.example.aakashmahesh.weatherapp.MainActivity$WeatherInfoThread.doInBackground(MainActivity.java:250)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
12-16 16:48:06.677 1370-17136/system_process W/ActivityManager: Force finishing activity com.example.aakashmahesh.weatherapp/.MainActivity
12-16 16:48:06.737 1370-17136/system_process D/dalvikvm: GC_FOR_ALLOC freed 647K, 12% free 16559K/18695K, paused 10ms, total 10ms
12-16 16:48:06.767 10523-10523/com.example.aakashmahesh.weatherapp D/libEGL: loaded /system/lib/egl/libEGL_emulation.so
12-16 16:48:06.767 10523-10523/com.example.aakashmahesh.weatherapp D/libEGL: loaded /system/lib/egl/libGLESv1_CM_emulation.so
12-16 16:48:06.767 10523-10523/com.example.aakashmahesh.weatherapp D/libEGL: loaded /system/lib/egl/libGLESv2_emulation.so
[ 12-16 16:48:06.767 10523:10523 D/ ]
HostConnection::get() New Host Connection established 0xb8071030, tid 10523
read the error, will you?
Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?) at
May be you did not write the permission to access Internet in Manifest file
Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
I'm trying to create a google glass application that uses the CamFind api to recognize objects from the camera. I've gotten maven to install, but it won't assemble the "master jar", so I'm adding dependencies to the gradle build path. I've gotten it to compile without any errors (granted there are 8 warnings), but it won't complete the call to the api without erroring out.
Here's the relevant code:
package com.akqa.glass.recipie;
import android.util.Log;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
// For if I'm using Unirest - don't it's not working...
//import org.apache.http.HttpResponse;
//import org.shaded.apache.http.HttpHeaders;
public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
private static final String TAG = JSONParser.class.getSimpleName();
// constructor
public JSONParser() {
}
public JSONObject getCamFindJSON(String type, String input) {
Log.d("PARSER", "Inside Parser");
/*
* Request processing from API
*/
if(type == "request"){
try {
HttpResponse<JsonNode> response = Unirest.post("https://camfind.p.mashape.com/image_requests")
.header("X-Mashape-Key", "Fhn5jZi5ixmshwnJMy7CGyj5yDCnp15DTQZjsniuwpVHfYHvFJ")
.field("image_request[image]", new File(input))
.field("image_request[locale]", "en_US")
.asJson();
} catch (UnirestException e) {
e.printStackTrace();
}
}
/*
* Receive response from API
*/
else if(type == "response"){
// These code snippets use an open-source library. http://unirest.io/java
try {
HttpResponse<JsonNode> response = Unirest.get("https://camfind.p.mashape.com/image_responses/" + input)
.header("X-Mashape-Key", "Fhn5jZi5ixmshwnJMy7CGyj5yDCnp15DTQZjsniuwpVHfYHvFJ")
.asJson();
} catch (UnirestException e) {
e.printStackTrace();
}
}
/*
* Parse Response into readable JSON
*/
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "n");
Log.d("Raw Data", line);
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
e.printStackTrace();
} catch (Exception e) {
Log.e("JSON Parse", "Unknown Error");
e.printStackTrace();
}
// return JSON String
return jObj;
}
}
And here's the relevant gradle build path:
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('C:/Users/torti_000/Documents/Recip.ie/libs/unirest-java-1.3.26.jar')
compile 'org.apache.httpcomponents:httpclient:4.3.5'
// compile 'org.apache.httpcomponents:httpclient-android:4.3.3'
compile 'org.apache.httpcomponents:httpmime:4.3.5'
compile 'org.apache.httpcomponents:httpasyncclient:4.0.2'
}
Finally, here's the logcat output (I'm pretty sure it's the first line that's causing all the problems):
11-25 14:21:59.589 6847-7099/com.akqa.glass.recipie E/dalvikvm﹕ Could not find class 'org.apache.http.impl.client.CloseableHttpClient', referenced from method com.mashape.unirest.http.Unirest.shutdown
11-25 14:21:59.589 6847-7099/com.akqa.glass.recipie W/dalvikvm﹕ VFY: unable to resolve check-cast 451 (Lorg/apache/http/impl/client/CloseableHttpClient;) in Lcom/mashape/unirest/http/Unirest;
11-25 14:21:59.589 6847-7099/com.akqa.glass.recipie D/dalvikvm﹕ VFY: replacing opcode 0x1f at 0x0006
11-25 14:21:59.605 6847-7099/com.akqa.glass.recipie I/dalvikvm﹕ Could not find method org.apache.http.client.methods.HttpRequestBase.releaseConnection, referenced from method com.mashape.unirest.http.HttpClientHelper.request
11-25 14:21:59.605 6847-7099/com.akqa.glass.recipie W/dalvikvm﹕ VFY: unable to resolve virtual method 1095: Lorg/apache/http/client/methods/HttpRequestBase;.releaseConnection ()V
11-25 14:21:59.605 6847-7099/com.akqa.glass.recipie D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0012
11-25 14:21:59.605 6847-7099/com.akqa.glass.recipie I/dalvikvm﹕ Could not find method org.apache.http.client.methods.HttpRequestBase.releaseConnection, referenced from method com.mashape.unirest.http.HttpClientHelper.request
11-25 14:21:59.605 6847-7099/com.akqa.glass.recipie W/dalvikvm﹕ VFY: unable to resolve virtual method 1095: Lorg/apache/http/client/methods/HttpRequestBase;.releaseConnection ()V
11-25 14:21:59.605 6847-7099/com.akqa.glass.recipie D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0021
11-25 14:21:59.613 6847-7099/com.akqa.glass.recipie I/dalvikvm﹕ Could not find method org.apache.http.client.config.RequestConfig.custom, referenced from method com.mashape.unirest.http.options.Options.refresh
11-25 14:21:59.613 6847-7099/com.akqa.glass.recipie W/dalvikvm﹕ VFY: unable to resolve static method 1069: Lorg/apache/http/client/config/RequestConfig;.custom ()Lorg/apache/http/client/config/RequestConfig$Builder;
11-25 14:21:59.613 6847-7099/com.akqa.glass.recipie D/dalvikvm﹕ VFY: replacing opcode 0x71 at 0x0020
11-25 14:21:59.613 6847-7099/com.akqa.glass.recipie D/dalvikvm﹕ DexOpt: unable to opt direct call 0x070c at 0x49 in Lcom/mashape/unirest/http/options/Options;.refresh
11-25 14:21:59.613 6847-7099/com.akqa.glass.recipie W/dalvikvm﹕ Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lcom/mashape/unirest/http/options/Options;
11-25 14:21:59.620 6847-7099/com.akqa.glass.recipie W/dalvikvm﹕ threadid=11: thread exiting with uncaught exception (group=0x4162bbd8)
11-25 14:21:59.620 6847-7101/com.akqa.glass.recipie D/PARSER﹕ Inside Parser
11-25 14:21:59.620 6847-7101/com.akqa.glass.recipie I/dalvikvm﹕ Rejecting re-init on previously-failed class Lcom/mashape/unirest/http/options/Options; v=0x0
11-25 14:21:59.620 6847-7099/com.akqa.glass.recipie E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
Process: com.akqa.glass.recipie, PID: 6847
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:314)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:240)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.NoClassDefFoundError: org.apache.http.client.config.RequestConfig
at com.mashape.unirest.http.options.Options.refresh(Options.java:45)
at com.mashape.unirest.http.options.Options.<clinit>(Options.java:34)
at com.mashape.unirest.http.HttpClientHelper.prepareRequest(HttpClientHelper.java:153)
at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:133)
at com.mashape.unirest.request.BaseRequest.asJson(BaseRequest.java:68)
at com.akqa.glass.recipie.JSONParser.getCamFindJSON(JSONParser.java:42)
at com.akqa.glass.recipie.RecipIE$CamFindRequest.doInBackground(RecipIE.java:288)
at com.akqa.glass.recipie.RecipIE$CamFindRequest.doInBackground(RecipIE.java:275)
at android.os.AsyncTask$2.call(AsyncTask.java:302)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:240)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
11-25 14:21:59.628 6847-7101/com.akqa.glass.recipie W/dalvikvm﹕ threadid=12: thread exiting with uncaught exception (group=0x4162bbd8)
11-25 14:21:59.628 6847-7101/com.akqa.glass.recipie I/Process﹕ Sending signal. PID: 6847 SIG: 9
The way to solve this is to compile all the dependencies into the mega jar as stated in the instructions. I couldn't do that, so I am using retrofit instead. I'll later update this with a link to a blog post about how to use retrofit with Mashape APIs.