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;
}
...
}
Related
In android studio, my code fails as soon as it reaches the following line.
sipStack = sipFactory.createSipStack(properties);
It gives me the following error.
W/System.err: android.javax.sip.PeerUnavailableException: The Peer SIP Stack: gov.nist.javax.sip.SipStackImpl could not be instantiated. Ensure the Path Name has been set.
...
Caused by: java.lang.NoSuchMethodException: gov.nist.javax.sip.SipStackImpl.<init> [class java.util.Properties]
Do you know what might be causing this error?
I'm using the following dependency for Jain-SIP.
compile group: 'javax.sip', name: 'android-jain-sip-ri', version: '1.3.0-91'
The code has no problem running in IntelliJ.
I'm using Android Studio with Ubuntu 18.04.2 LTS.
My MainActivity class is as follows.
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Shootist().init();
}
}
My Shootist class is as follows.
public class Shootist implements SipListener {
public void init() {
SipFactory sipFactory = SipFactory.getInstance();
sipFactory.setPathName("gov.nist");
SipStack sipStack = null;
String transport = "udp";
String peerHostPort = "127.0.01:5070";
Properties properties = new Properties();
properties.setProperty("android.javax.sip.OUTBOUT_PROXY", peerHostPort + "/" + transport);
properties.setProperty("android.javax.sip.STACK_NAME", "shootist");
properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", "shootistdebug.txt");
properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "DEBUG");
System.out.println("trying to create sip stack");
// create sip stack
try {
sipStack = sipFactory.createSipStack(properties);
System.out.println("sip stack created");
} catch (PeerUnavailableException e) {
e.printStackTrace();
}
}
#Override
public void processRequest(RequestEvent requestEvent) {
}
#Override
public void processResponse(ResponseEvent responseEvent) {
}
#Override
public void processTimeout(TimeoutEvent timeoutEvent) {
}
#Override
public void processIOException(IOExceptionEvent exceptionEvent) {
}
#Override
public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) {
}
#Override
public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) {
}
}
The entire error output is below.
07/23 13:55:28: Launching app
D/EGL_emulation: eglMakeCurrent: 0xe431a180: ver 2 0 (tinfo 0xe430f220)
I/System.out: trying to create sip stack
W/testapplicatio: Accessing hidden method Lgov/nist/javax/sip/SipStackImpl;-><init>(Ljava/util/Properties;)V (blacklist, reflection, denied)
W/System.err: android.javax.sip.PeerUnavailableException: The Peer SIP Stack: gov.nist.javax.sip.SipStackImpl could not be instantiated. Ensure the Path Name has been set.
at android.javax.sip.SipFactory.createStack(SipFactory.java:324)
at android.javax.sip.SipFactory.createSipStack(SipFactory.java:152)
at com.example.jainsiptestapplication.Shootist$override.init(Shootist.java:35)
at com.example.jainsiptestapplication.Shootist$override.access$dispatch(Unknown Source:107)
at com.example.jainsiptestapplication.Shootist.init(Unknown Source:12)
at com.example.jainsiptestapplication.MainActivity.onCreate(MainActivity.java:13)
at android.app.Activity.performCreate(Activity.java:7783)
at android.app.Activity.performCreate(Activity.java:7772)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3235)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3396)
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5264)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5172)
at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ClientTransactionHandler.executeTransaction(ClientTransactionHandler.java:57)
at android.app.ActivityThread.handleRelaunchActivityLocally(ActivityThread.java:5223)
at android.app.ActivityThread.access$3400(ActivityThread.java:220)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2019)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7319)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:934)
Caused by: java.lang.NoSuchMethodException: gov.nist.javax.sip.SipStackImpl.<init> [class java.util.Properties]
at java.lang.Class.getConstructor0(Class.java:2332)
at java.lang.Class.getConstructor(Class.java:1728)
at android.javax.sip.SipFactory.createStack(SipFactory.java:305)
... 25 more
Hot swapped changes, activity restarted
D/OpenGLRenderer: Setting buffer count to 3, min_undequeued 1, extraBuffers 0
D/EGL_emulation: eglMakeCurrent: 0xe431a180: ver 2 0 (tinfo 0xe430f220)
D/OpenGLRenderer: Setting buffer count to 3, min_undequeued 1, extraBuffers 0
D/EGL_emulation: eglMakeCurrent: 0xe431a180: ver 2 0 (tinfo 0xe430f220)
I/chatty: uid=10154(com.example.jainsiptestapplication) RenderThread identical 1 line
D/EGL_emulation: eglMakeCurrent: 0xe431a180: ver 2 0 (tinfo 0xe430f220)
The main issue is
sipFactory.setPathName("gov.nist");
should be
sipFactory.setPathName("android.gov.nist");
Initialisation is slightly different with android. Perhaps you can start with this example https://github.com/usnistgov/jsip/tree/master/src/examples/android/simplecallsetup and built on top of it.
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?)
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 7 years ago.
I am new to Java and android development. I am interested to build an app that can sync a folder from my android phone (Nexus5) to Amazon Web service (AWS). I am trying to build based on an open source project. But, I get the following error for this snippet and unable to locate my mistake. Your feedback will be highly useful at this point.
private void loadFileList(File path) {
this.currentPath = path;
List<String> r = new ArrayList<String>();
if (path.exists()) {
if (path.getParentFile() != null) r.add(PARENT_DIR);
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String filename) {
File sel = new File(dir, filename);
if (!sel.canRead()) return false;
if (selectDirectoryOption) return sel.isDirectory();
else {
boolean endsWith = fileEndsWith != null ? filename.toLowerCase().endsWith(fileEndsWith) : true;
return endsWith || sel.isDirectory();
}
}
{
FileDialog a = FileDialog.this;
//a.super();
}
};
String[] fileList1 = path.list(filter);
for (String file : fileList1) { <-- Error in this line
r.add(file);
}
}
fileList = (String[]) r.toArray(new String[0]);
}
Error:
11-30 01:03:23.880 24102-24102/pavan.syncfile E/AndroidRuntime: FATAL EXCEPTION: main
11-30 01:03:23.880 24102-24102/pavan.syncfile E/AndroidRuntime: Process: pavan.syncfile, PID: 24102
11-30 01:03:23.880 24102-24102/pavan.syncfile E/AndroidRuntime: java.lang.NullPointerException: Attempt to get length of null array
11-30 01:03:23.880 24102-24102/pavan.syncfile E/AndroidRuntime: at pavan.syncfile.FileDialog.loadFileList(FileDialog.java:149)
11-30 01:03:23.880 24102-24102/pavan.syncfile E/AndroidRuntime: at pavan.syncfile.FileDialog.<init>(FileDialog.java:45)
11-30 01:03:23.880 24102-24102/pavan.syncfile E/AndroidRuntime: at pavan.syncfile.SendFile$1.onClick(SendFile.java:56)
11-30 01:03:23.880 24102-24102/pavan.syncfile E/AndroidRuntime: at android.view.View.performClick(View.java:5198)
11-30 01:03:23.880 24102-24102/pavan.syncfile E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:21147)
11-30 01:03:23.880 24102-24102/pavan.syncfile E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
11-30 01:03:23.880 24102-24102/pavan.syncfile E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
11-30 01:03:23.880 24102-24102/pavan.syncfile E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
11-30 01:03:23.880 24102-24102/pavan.syncfile E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
11-30 01:03:23.880 24102-24102/pavan.syncfile E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
11-30 01:03:23.880 24102-24102/pavan.syncfile E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
11-30 01:03:23.880 24102-24102/pavan.syncfile E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
The intent of this line
String[] fileList1 = path.list(filter); is to list the subfiles in the directory.
Here you are getting fileList1[] are null as there is not subfiles in the path folder matching the filter.
You can add a null check before this line
for (String file : fileList1) { <-- Error in this line
r.add(file);
}
i.e
if(fileList1!=null)
{
for (String file : fileList1) { <-- Error in this line
r.add(file);
}
}
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();
I've added the following (http://loopj.com/android-async-http/) to my /libs folder and have also put it in the module settings as a library and ticked the export button. In the actual file there are no errors given that it can't find the class and when I do import com.loopj and so-forth it completes it for me and shows me the available options.
However, when I run it on my phone it gives the following errors:
12-02 23:00:08.943 8209-8209/mobi.vassilev.beam E/dalvikvm﹕ Could not find class 'com.loopj.android.http.AsyncHttpClient', referenced from method mobi.vassilev.beam.GoogleLoginActivity.requestAPIKeyFromOAuthToken
12-02 23:00:09.183 8209-8209/mobi.vassilev.beam E/﹕ file /data/data/com.nvidia.NvCPLSvc/files/driverlist.txt: not found!
12-02 23:00:10.453 8382-8382/? E/ObjectHelper﹕ Can't find method:setCompatibilityInfo
12-02 23:00:10.598 8209-8209/mobi.vassilev.beam E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.loopj.android.http.AsyncHttpClient
at mobi.vassilev.beam.GoogleLoginActivity.requestAPIKeyFromOAuthToken(GoogleLoginActivity.java:118)
at mobi.vassilev.beam.GoogleLoginActivity.access$200(GoogleLoginActivity.java:24)
at mobi.vassilev.beam.GoogleLoginActivity$OnTokenAcquired.run(GoogleLoginActivity.java:105)
at android.accounts.AccountManager$11.run(AccountManager.java:1335)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:5751)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
at dalvik.system.NativeStart.main(Native Method)
12-02 23:00:10.633 513-548/? E/EmbeddedLogger﹕ App crashed! Process: mobi.vassilev.beam
and the extract of code (not complete obv as the URL is fake, but that shouldn't affect anything):
private void requestAPIKeyFromOAuthToken(String token) {
AsyncHttpClient client = new AsyncHttpClient(); // <-- this is line 118
RequestParams params = new RequestParams("token", token);
client.post("https://myrailsapp.com/api/v1/auth/verify", params, new AsyncHttpResponseHandler() {
#Override
public void onSuccess(String response) {
Log.w("OAUTH", "Got API key from server: " + response);
finish();
}
#Override
public void onFailure(Throwable e) {
Log.w("OAUTH", "Error getting API key");
Toast.makeText(getApplicationContext(), R.string.connection_error_message, Toast.LENGTH_LONG).show();
e.printStackTrace();
}
});
}
Would anyone know a solution to this problem?
Thank you very much,
Daniel
In Android Studio, you have to add your jar into the lib folder, add the dependency into the build.gradle file and call gradlew clean from console. The gradlew is in your project directory.
Check this thread for more details: Android Studio: Add jar as library?