i am working on a network communication project in android, but my app dose not work ! after some debugging, i find out that every network request has a null response from system.
i tried so many ways such as :
1) hard restart my phone
2) adding all network permissions to the manifest file
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
3) using local network ( my phone as a server )
4) letting all applications to connect to the network : setting > networked apps > ...
but ! nothing happened...
this is my similar problem link, but there is no answer in this topic:
can't connect to internet in ONLY in my android app. Each method to connect internet returns null
network is working on my phone because some apps like telegram and chrome are working well !
and there is a funny thing here, when i copy and past this code to the simple java project not android project, it works well !
because i wanted to find out where is the problem, i just copy 3 simple lines of codes to the simple android project, but still nothing happened!
manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dltests"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
layout file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:id="#+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
source file
package com.example.dltests;
import java.net.HttpURLConnection;
import java.net.URL;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView mTextView = (TextView) findViewById(R.id.hello);
try
{
URL mUrl = new URL("http://192.168.1.53:8080/some.zip");
HttpURLConnection mHttpURLConnection = (HttpURLConnection) mUrl.openConnection();
mTextView.setText(mHttpURLConnection.getContentLength());
}
catch (Exception e)
{
mTextView.setText("ERROR: " + e.getMessage());
}
}
}
and the result is :
ERROR: null
Android bars you from networking in the UI thread. What you need to do it spawn a separate thread to do the networking for you. Then you need either a receiver or handler to post/update the UI with the data.
1 - Create a new class:
import android.os.Handler;
import android.os.Message;
public class GetData extends Thread
{
// Holds url that data is stored on
private URL url
// Sets the url value
public GetData(URL newUrl)
{
url = newUrl;
}
// Runs when the thread is launched
public void run()
{
// Opens connection
HttpURLConnection con = (HttpURLConnection) url.openConnection();
// Sends back to UI using a Message
Message msg = MainActivity.MainActivityInterface.obtainMessage(MainActivity.getAndUpdate);
msg.obj = con.getContentLength(); // Adds the data
HomeScreen.homeScreenInterface.sendMessage(msg);
}
}
2 - Create handler in activity so UI can be updated as well as launch worker thread
import java.net.HttpURLConnection;
import java.net.URL;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.os.Handler;
import android.os.Message;
public class MainActivity extends Activity {
// Holds activity instance
public static MainActivity currentInstance;
// Variable that allows us to separate messages for handler
public static final getAndUpdate = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
currentInstance = this;
TextView mTextView = (TextView) findViewById(R.id.hello);
try
{
URL mUrl = new URL("http://192.168.1.53:8080/some.zip");
// Spawns worker thread
GetData gd = new GetData(mUrl);
gd.start();
}
catch (Exception e)
{
mTextView.setText("ERROR: " + e.getMessage());
}
}
// Deals with service responses
public static Handler MainActivityInterface = new Handler()
{
#Override
public void handleMessage(Message msg)
{
switch(msg.what)
{
case getAndUpdate:
currentInstance.mTextView.setText((String) msg.obj); // Gets message object and updates UI
break;
}
}
}
}
I hope this helps. Note that I have not tested it as I am very far away from my coding computer!
Related
I have a web view app that works perfectly fine on most android phones, but while testing, some said that the app even won't open for the first time after installation.
It keeps on showing the error as below :
"Keeps Stopping"
And in some mobile devices, it says "Runtime Exception" and crashes without even opening.
This was a debug APK, so in an attempt of trying to fix it, I even generated a signed APK. Still no luck.
Here is my whole Code:
Activity Main.XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:layout_width="match_parent"
android:id="#+id/webviewid"
android:layout_height="match_parent"
android:overScrollMode="never"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
</WebView>
</RelativeLayout>
AndroidManifest.Xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxxxxxxxxxxxx;">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" ></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" ></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_roundffd"
android:supportsRtl="true"
android:theme="#style/Theme_xxxxxx"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize">
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Mainactivity.java
package com.xxxxxxxxxxxxx;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.accessibilityservice.AccessibilityService;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import android.os.Handler;
import android.webkit.GeolocationPermissions;
import android.webkit.WebChromeClient;
import android.content.Context;
import android.net.ConnectivityManager;
public class MainActivity extends AppCompatActivity {
private WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webviewid);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://www.some.com/");
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setGeolocationEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
callback.invoke(origin, true, false);
}
});
}
// On double back press stuff starts --------------------------------------------------
private boolean doubleBackToExitPressedOnce = false;
#Override
protected void onResume() {
super.onResume();
// .... other stuff in my onResume ....
this.doubleBackToExitPressedOnce = false;
}
#Override
public void onBackPressed() {
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
if(webView.canGoBack()){
webView.goBack();
}
}
}
Please note that the app works completely fine, It installs and opens with no issues, but when it comes to some phones, I am getting this "Keeps Stopping" error.
As per some blogs, I even tried uninstalling updates from the Android Web View setting, yet still no use.
Any help or suggestion is greatly appreciated.
can you remove the 'smallestscreensize' in android:configChanges in manifest file and let us know.
I am attempting to capture sensor data in a textfile that I can extract from the 'external storage' of the phone when I connect it via USB to a PC so I can run the textfile through a python script for graphing purposes. I have not implemented the sensor part yet as I am unable to create files that I can copy over to the PC from the phone after they have been created.
I attempt to create a folder and it does not create the folder and I also attempt to create a file and it also fails and then it throws an exception that the file does not exist. I am at a loss as I have added the permission to the manifest file as you can see below. Is there anything that I am missing? I have done a lot of searching around and there does not seem to be any solution to my problem and the developer.android.com website does not explain anything regarding permissions outside of adding the lines I already added to the manifest file.
I do not own an SDcard so using the sdcard is not a possible solution to my problem.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mike.project_final">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
and here is my entire code that I have done so far which is throwing the errors.
package com.example.mike.project_final;
import android.content.Context;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.hardware.Sensor;
import android.view.View;
import android.widget.TextView;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
public class MainActivity extends AppCompatActivity implements SensorEventListener {
TextView xTV, yTV, zTV, writeTV;
SensorManager sManager;
Sensor sAccelerometer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
xTV = (TextView) findViewById(R.id.xTV);
yTV = (TextView) findViewById(R.id.yTV);
zTV = (TextView) findViewById(R.id.zTV);
writeTV = (TextView) findViewById(R.id.writeTV);
}
/* Checks if external storage is available for read and write */
public boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
public void createFile(View view) {
File root = android.os.Environment.getExternalStorageDirectory();
File dir = new File (root.getAbsolutePath() + "/project_test");
if (!dir.exists()){
dir.mkdir();
xTV.setText("Created");
}
else{
xTV.setText("Exists");
}
File file = new File(dir, "myData.txt");
try {
FileOutputStream f = new FileOutputStream(file);
PrintWriter pw = new PrintWriter(f);
pw.println("Hi , How are you");
pw.println("Hello");
pw.flush();
pw.close();
f.close();
} catch (Exception e) {
writeTV.setText(e.toString());
}
}
#Override
public void onAccuracyChanged(Sensor sensor, int accuracy){
//do nothing
}
#Override
public void onSensorChanged(SensorEvent event) {
}
}
Any help with how to setup the rest of the permissions if required will be really appreciated!
EDIT 1:
The issue with permissions have been solved, thank you. I now have an issue that the folder I create does not create as a folder but as a file as shown in the image below. What exactly am I doing wrong?
https://i.imgur.com/srKXJc1g.png
Unfortunately I don't have enough reputation to post images.
I am completely new to android.
I am trying to build a basic app to get an idea on "android applications reading data from a server".
To get an idea about http connection on android i created this app watching a video tutorial, i have two java classes.
HttpExample.java class,
package com.raveen.testingthree;
import android.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.widget.TextView;
public class HttpExample extends Activity {
TextView httpStuff;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.detectAll().penaltyLog().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
httpStuff = (TextView) findViewById(R.id.tvHttp);
GetMethodHttp test = new GetMethodHttp();
String returned;
try {
returned = test.getInternetData();
httpStuff.setText(returned);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
and getmethodhttp.java class,
package com.raveen.testingthree;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
public class GetMethodHttp {
public String getInternetData () throws Exception{
BufferedReader in = null;
String data = null;
try{
HttpClient client = new DefaultHttpClient();
URI website = new URI("http://www.google.com");
HttpGet request = new HttpGet();
request.setURI(website);
HttpResponse responce = client.execute(request);
in = new BufferedReader(new InputStreamReader(responce.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String newLine = System.getProperty("line.separator");
while((line = in.readLine()) != null){
sb.append(line + newLine);
}
in.close();
data = sb.toString();
return data;
} finally {
if (in != null){
try{
in.close();
return data;
} catch (Exception e){
e.printStackTrace();
}
}
}
}
}
this is my AndroidManifest,
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".HttpExample"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
and my layout xml,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/tvHttp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading Data"
android:textSize="20dp"
/>
</ScrollView>
</LinearLayout>
now when i run this on emulator or my android phone NOTHING IS DISPLAYED.. Just a blank white layout is visible.. what am i doing wrong here?
(i am using eclipse to program)
First of all you should not change the policy to force network calls on main thread instead use Async task.
If you want to read html contents then use jsoup which allows to parse html.
If you want to read data from webservice then try VOLLEY Library.This will save your time,works more efficiently and traceable.
I have a simple code which will show "Available" and "Unavailable" using asmack api, but whenever i click on the button it throws a message of not being connected to server. I am posting my code below.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.usingxmpp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.usingxmpp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/string_head" />
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/button1"
android:onClick="onClick1"
/>
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/button2"
android:onClick="onClick2"
/>
</LinearLayout>
string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Usingxmpp</string>
<string name="action_settings">Settings</string>
<string name="string_head">Hello world!</string>
<string name="button1">Avail</string>
<string name="button2">Unavail</string>
</resources>
MainActivity.java
package com.example.usingxmpp;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Presence;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
ConnectionConfiguration connfig = new ConnectionConfiguration("acer-PC",5222,"acer-pc");
XMPPConnection connection = new XMPPConnection(connfig);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try
{
connection.connect();
connection.login("rahul","rahul");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void onClick1(View v)
{
new Thread(new Runnable()
{
public void run()
{
try
{
Presence presence = new Presence(Presence.Type.available);
presence.setStatus("I am available");
connection.sendPacket(presence);
//String status = presence.getStatus();
Toast.makeText(getBaseContext(), "You are Available!", Toast.LENGTH_SHORT).show();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
).start();
}
public void onClick2(View v)
{
new Thread(new Runnable()
{
public void run()
{
try
{
Presence presence = new Presence(Presence.Type.unavailable);
presence.setStatus("I am unavailable");
connection.sendPacket(presence);
//String status = presence.getStatus();
Toast.makeText(getBaseContext(), "UnAvailable now!", Toast.LENGTH_SHORT).show();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
).start();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Logcat
12-02 14:41:40.809: W/System.err(5464): java.lang.IllegalStateException: Not connected to server.
12-02 14:41:40.839: W/System.err(5464): at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:194)
12-02 14:41:40.839: W/System.err(5464): at org.jivesoftware.smack.Connection.login(Connection.java:355)
12-02 14:41:40.839: W/System.err(5464): at com.example.usingxmpp.MainActivity$1.run(MainActivity.java:44)
12-02 14:41:40.839: W/System.err(5464): at java.lang.Thread.run(Thread.java:856)
When I press Avail button the above errors comes in logcat.
Please help me in solving this problem of connecting to server.
Thanks
(Note: Runnning this project on my device)
The problem is this code sequence:
connection.login("rahul","rahul");
connection.connect();
You need to be connected before you can login. Sounds reasonable, does it? Therefore you need to change the code to:
connection.connect();
connection.login("rahul","rahul");
It could be because your android xmpp client is not able to connect to your host (in your case acer-PC). I mentioned the IP address for host on which the xmpp server is installed and it worked for me. You have to be careful with IP address, you may directly use your local WIFI IP address, you will be able to connect to xmpp server from android device if both your PC & android device are using the same WIFI. In case if you are using External IP address you may have to do some additional configurations as discussed here in this link
I am trying to post a tweet via my android app. Reading tutorials on the internet, I've written the code mentioned below.
However, I get the following exception each time, when calling twitter.updateStatus():
TwitterException{exceptionCode=[, statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=3.0.3}
Following things have been tried:
a. Reading the latest posts on this and other sites to understand a code defect.
b. Read about the error and suggested solutions.
b. Rebuilding workspace.
Any inputs will be REALLY helpful ! Thanks in advance.
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.exampletweetdeep"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.exampletweetdeep.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java:
package com.example.exampletweetdeep;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity {
String consumerKey = "<<>>";
String consumerSecret = "<<>>";
String accessToken = "<<>>";
String accessSecret = "<<>>";
#Override
protected void onCreate(Bundle savedInstanceState) {
Log.i("Twitter activity", "First line");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i("Twitter activity", "Before building configuration");
ConfigurationBuilder confB = new ConfigurationBuilder();
confB.setDebugEnabled(true);
confB.setOAuthConsumerKey(consumerKey);
confB.setOAuthConsumerSecret(consumerSecret);
confB.setOAuthAccessToken(accessToken);
confB.setOAuthAccessTokenSecret(accessSecret);
Log.i("Twitter activity", "After building configuration");
TwitterFactory tF = new TwitterFactory(confB.build());
Twitter twitter = tF.getInstance();
try {
Status status = twitter.updateStatus("Testing from android");
Log.i("Twitter activity", "Done updating status");
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Upgrade your twitter4j library to twitter4j-core-3.0.5.jar. I was facing the same problem and solved it by upgrading the library.