Passing extras from Activity to Intent throws NullPointerException - java

This is a problem that forked off a different issue.
I'm passing two strings from my main activity to a child service, which is fine, but when the main activity dies, the service throws a NullPointerException trying to grab the two strings.
From MainActivity:
Intent i = new Intent(this, PebbleService.class);
i.putExtra("quote", quote[0]);
i.putExtra("author", quote[1]);
startService(i);
From PebbleService:
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
final String author = intent.getStringExtra("author");
final String quote = intent.getStringExtra("quote");
// Define AppMessage behavior
if (appMessageReciever == null) {
appMessageReciever = new PebbleKit.PebbleDataReceiver(WATCHAPP_UUID) {
#Override
public void receiveData(Context context, int transactionId, PebbleDictionary data) {
// Always ACK
PebbleKit.sendAckToPebble(context, transactionId);
// Send KEY_QUOTE to Pebble
PebbleDictionary out = new PebbleDictionary();
out.addString(KEY_QUOTE, quote);
out.addString(KEY_AUTHOR, author);
PebbleKit.sendDataToPebble(getApplicationContext(), WATCHAPP_UUID, out);
}
};
// Add AppMessage capabilities
PebbleKit.registerReceivedDataHandler(this, appMessageReciever);
}
return START_STICKY;
}
Error from Logcat:
05-26 10:29:52.972 4147-4147/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: net.thevgc.quotes, PID: 4147
java.lang.RuntimeException: Unable to start service net.thevgc.quotes.PebbleService#423eb138 with null: java.lang.NullPointerException
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2732)
at android.app.ActivityThread.access$2100(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at net.thevgc.quotes.PebbleService.onStartCommand(PebbleService.java:34)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2715)
            at android.app.ActivityThread.access$2100(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5086)
            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:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)

As per the documentation:
intent - ... This may be null if the service is being restarted
Therefore check for null intent:
public int onStartCommand(Intent intent, int flags, int startId) {
int cmd = super.onStartCommand(intent, flags, startId);
if (intent == null) return cmd;
final String author = intent.getStringExtra("author");
final String quote = intent.getStringExtra("quote");
...
}

Related

Fatal exception at main android during dropbox authentication [duplicate]

This question already exists:
Dropbox Core API is not working. I don't want to hardcode app key and secret?
Closed 7 years ago.
I am getting fatal exception error at main nullpointer exception. basically i have 2 activities login and main activity.you will enter app key and app secret in login activity then after authentication it will take you to main activity any help ??
login activity
public class login_activity extends AppCompatActivity {
public String APP_kEY ;
public String APP_SECRET;
public String accessToken;
EditText app_key_view;
EditText App_secret_view;
Button dropbox;
public DropboxAPI<AndroidAuthSession> mDBApi;
#Override
protected void onCreate(Bundle savedInstanceState) {
SharedPreferences pref = getSharedPreferences("login",MODE_PRIVATE);
APP_kEY = pref.getString("appkey",null);
APP_SECRET = pref.getString("appsecret",null);
accessToken = pref.getString("access",null);
if (accessToken != null){
AppKeyPair appkeys = new AppKeyPair(APP_kEY,APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appkeys);
session.setOAuth2AccessToken(accessToken);
Intent i = new Intent(login_activity.this,MainActivity.class);
startActivity(i);
finish();
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_activity);
app_key_view=(EditText)findViewById(R.id.app_key_text);
App_secret_view=(EditText)findViewById(R.id.app_secret_text);
dropbox = (Button)findViewById(R.id.link_dropbox);
//////////////////////////////////////////////////////////////
dropbox.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
APP_kEY = app_key_view.getText().toString();
APP_SECRET = App_secret_view.getText().toString();
AppKeyPair appKeys = new AppKeyPair(APP_kEY,APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeys);
mDBApi = new DropboxAPI<>(session);
mDBApi.getSession().startOAuth2Authentication(login_activity.this);
}
});
}
#Override
protected void onResume () {
super.onResume();
if(mDBApi.getSession().authenticationSuccessful()){
try {
mDBApi.getSession().finishAuthentication();
accessToken = mDBApi.getSession().getOAuth2AccessToken();
SharedPreferences.Editor editor = getSharedPreferences("login",MODE_PRIVATE).edit();
editor.putString("appkey",APP_kEY);
editor.putString("appsecret",APP_SECRET);
editor.putString("access",accessToken);
editor.commit();
Intent i = new Intent(login_activity.this,MainActivity.class);
startActivity(i);
finish();
}
catch (IllegalStateException e){
Log.i("DbAuthLog", "Error authenticationg", e);
}
}
}
Logcat
09-11 21:06:01.947 3842-3842/? I/art﹕ Late-enabling -Xcheck:jni
09-11 21:06:01.975 3842-3851/? I/art﹕ Debugger is no longer active
09-11 21:06:02.370 3842-3857/? I/art﹕ Background sticky concurrent mark sweep GC freed 2909(253KB) AllocSpace objects, 2(32KB) LOS objects, 0% free, 50MB/50MB, paused 36.891ms total 133.660ms
09-11 21:06:02.803 3842-3842/? D/AndroidRuntime﹕ Shutting down VM
09-11 21:06:02.803 3842-3842/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.ayzaz.timescopev1.timescope, PID: 3842
java.lang.RuntimeException: Unable to resume activity {com.example.ayzaz.timescopev1.timescope/com.example.ayzaz.timescopev1.timescope.login_activity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.dropbox.client2.session.Session com.dropbox.client2.DropboxAPI.getSession()' on a null object reference
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2986)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3017)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.dropbox.client2.session.Session com.dropbox.client2.DropboxAPI.getSession()' on a null object reference
at com.example.ayzaz.timescopev1.timescope.login_activity.onResume(login_activity.java:77)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1257)
at android.app.Activity.performResume(Activity.java:6076)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2975)
            at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3017)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
09-11 21:06:05.849 3842-3842/com.example.ayzaz.timescopev1.timescope I/Process﹕ Sending signal. PID: 3842 SIG: 9
onResume() always gets called after onCreate().
When onResume() begins, mDBApi is null, because this field is only ever assigned in the onClick() method.
You either need to assign mDBApi in onCreate() directly, or you need to check that it is not null before you try to use it.

Android Form Validation - How do I prevent a null field from crashing my application on button press?

I have a form which lets the user add entries into a raffle. However if the user leaves one of these fields blank and presses the submit button the app crashes. I tried to get around this by creating an if statement - if any of the fields are null, do nothing. Else, run the intent. However this still does not fix my problem. Pressing the button still causes a crash.
Here is my code:
public void addEntrySubmitButtonClick(View view) {
Intent addEntryIntent = getIntent();
int currentRaffleID = addEntryIntent.getIntExtra("raffleIndexInList", 0);
Raffle currentRaffle = Raffle.raffleArrayList.get(currentRaffleID);
String newEntryForename = String.valueOf(addEntryForename.getText());
String newEntrySurname = String.valueOf(addEntrySurname.getText());
int newEntryTelephoneNo = Integer.parseInt(String.valueOf(addEntryTelephoneNo.getText()));
int newEntryTicketCount = Integer.parseInt(String.valueOf(addEntryTicketCount.getText()));
int newEntryRaffleId = currentRaffle.getId();
if ((newEntryForename.equals(null)) || (newEntrySurname.equals(null)) || (String.valueOf(addEntryTelephoneNo).equals(null)) || (String.valueOf(addEntryTicketCount).equals(null))){
Intent failIntent = new Intent();
} else {
Entry newEntry = new Entry(newEntryForename, newEntrySurname, newEntryTelephoneNo, newEntryTicketCount, newEntryRaffleId);
// Get the list of raffles
for(Raffle currentEntryRaffle : Raffle.raffleArrayList) {
if((currentEntryRaffle.getId() == newEntryRaffleId) && ((currentEntryRaffle.getEntryArrayList().size()) < (currentEntryRaffle.getMaxTickets()))) {
int counter=0;
do {
currentEntryRaffle.getEntryArrayList().add(newEntry);
counter++;
} while(counter < newEntryTicketCount);
}
}
Intent returnIntent = new Intent();
setResult(RESULT_CANCELED, returnIntent);
finish();
}
Here is the logcat:
10-24 10:48:42.599 19481-19481/com.example.rafflemanager E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3628)
at android.view.View.performClick(View.java:4128)
at android.view.View$PerformClick.run(View.java:17142)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:4787)
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:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3623)
            at android.view.View.performClick(View.java:4128)
            at android.view.View$PerformClick.run(View.java:17142)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:213)
            at android.app.ActivityThread.main(ActivityThread.java:4787)
            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:809)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NumberFormatException: Invalid int: ""
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parseInt(Integer.java:359)
at java.lang.Integer.parseInt(Integer.java:332)
at com.example.rafflemanager.AddEntry.addEntrySubmitButtonClick(AddEntry.java:48)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at android.view.View$1.onClick(View.java:3623)
            at android.view.View.performClick(View.java:4128)
            at android.view.View$PerformClick.run(View.java:17142)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:213)
            at android.app.ActivityThread.main(ActivityThread.java:4787)
            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:809)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
            at dalvik.system.NativeStart.main(Native Method)
newEntryForename.equals(null)
The above expression will either evaluate to false or throw a NullPointerException. It is impossible to call a method on a null reference.
String.valueOf(addEntryTelephoneNo).equals(null)
The above expression will always evaluate to false. From String.valueOf javadoc:
Returns: if the argument is null, then a string equal to "null"; otherwise, the value of obj.toString() is returned.
What you want instead is simply
addEntryTelephoneNo == null
and similar for other cases.
Furthermore note that you are trying to parse the value before you have null-checked it:
int newEntryTelephoneNo = Integer.parseInt(String.valueOf(addEntryTelephoneNo.getText()));
Move that code to after the null check.
I'm writing this from a smartphone so I won't include any codesamples with this answer.
Anyway... First of all remove all String.valueOf() calls - they are redundant. Second, to see if a value is null, check for value == null, not value.equals(null). If value is null, it doesn't have the method equals(), and will thus lead to a NullReferenceException.
Also, don't call Integer.parseInt(value) before you have made sure that value isn't null.
Disabling the send button when the EditText is empty when using imeOption= actionSend
message.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
public void afterTextChanged(Editable s) {
if (s == null || s.length() == 0) {
send.setEnabled(false);
message.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
}
else {
send.setEnabled(true);
message.setImeOptions( /* whatever you previously had */ );
}
}
To check if a string is empty (null or length 0) use TextUtils.isEmpty(). Here's an example:
int newEntryTelephoneNo;
if (TextUtils.isEmpty(addEntryTelephoneNo.getText())) {
newEntryTelephoneNo = 0;
} else {
newEntryTelephoneNo = Integer.parseInt(addEntryTelephoneNo.getText());
}
The problem in your logcat is this :
Caused by: java.lang.NumberFormatException: Invalid int: ""
Without line numbers, I deduct that the problem comes from one line like this one :
int newEntryTelephoneNo = Integer.parseInt(String.valueOf(addEntryTelephoneNo.getText()));
Reading the following docs give us a hint : http://developer.android.com/reference/java/lang/Integer.html#parseInt(java.lang.String)
Throws
NumberFormatException if string cannot be parsed as an integer value.
The Integer.parseInt() seems not able to parse an empty String to an int (and it's normal, because a int can't be null).
So I think you should make something like that :
int newEntryTelephoneNo = 0;
if (!TextUtils.isEmpty(addEntryTelephoneNo.getText())) {
newEntryTelephoneNo = Integer.parseInt(addEntryTelephoneNo.getText());
}
Not about the main question
Also, as other answers and comment said, you have to use this to check the "nullity" of an object :
myObject == null
instead of
myObject.equals(null)
because you can't even call equals() or any other methods on a null instance.
The logcat clearly shows the exception occurs when the call to Integer.parseInt throws a NumberFormatException. This occurs when the string cannot be converted to an int. If you check the line numbers you will see exactly which conversion generated the exception.
Depending on your needs you probably want to both test for acceptable invalid entries like empty string and catch NumberFormatException due to invalid input so that you can inform the user of the invalid entry.
Here is the code you need:
public void addEntrySubmitButtonClick(View view) {
Intent addEntryIntent = getIntent();
int currentRaffleID = addEntryIntent.getIntExtra("raffleIndexInList", 0);
Raffle currentRaffle = Raffle.raffleArrayList.get(currentRaffleID);
String newEntryForename = String.valueOf(addEntryForename.getText());
String newEntrySurname = String.valueOf(addEntrySurname.getText());
int newEntryTelephoneNo = Integer.parseInt(String.valueOf(addEntryTelephoneNo.getText()));
int newEntryTicketCount = Integer.parseInt(String.valueOf(addEntryTicketCount.getText()));
int newEntryRaffleId = currentRaffle.getId();
if (newEntryForename==null || newEntrySurname == null || String.valueOf(addEntryTelephoneNo) == null || String.valueOf(addEntryTicketCount) == null){
Intent failIntent = new Intent();
} else {
Entry newEntry = new Entry(newEntryForename, newEntrySurname, newEntryTelephoneNo, newEntryTicketCount, newEntryRaffleId);
// Get the list of raffles
for(Raffle currentEntryRaffle : Raffle.raffleArrayList) {
if((currentEntryRaffle.getId() == newEntryRaffleId) && ((currentEntryRaffle.getEntryArrayList().size()) < (currentEntryRaffle.getMaxTickets()))) {
int counter=0;
do {
currentEntryRaffle.getEntryArrayList().add(newEntry);
counter++;
} while(counter < newEntryTicketCount);
}
}
Intent returnIntent = new Intent();
setResult(RESULT_CANCELED, returnIntent);
finish();
}
You have to replace .equals(null) with == null since calling a method on a null pointer will crash your app.

Error while Inflating class?

I migrated a project from Eclipse to Android Studio. In my project, I have added this library.
I have added the library as a dependency in my gradle file. I can import the library from my class.But it shows this
android.view.InflateException: Binary XML file line #8: Error inflating class com.digitalaria.gama.wheel.Wheel
while running the app.
Note - It worked fine while running it from Eclipse.
gradle
apply plugin: 'android'
dependencies {
// compile fileTree(dir: 'libs', include: '*.jar')
compile project(':RemoteIt Protocol')
compile project(':android-support-v7-appcompat')
compile files('libs/gama_wheel_v1.0.jar')
compile files('libs/PayPalAndroidSDK.jar')
}
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<com.digitalaria.gama.wheel.Wheel
android:id="#+id/wheel"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</com.digitalaria.gama.wheel.Wheel>
</LinearLayout>
Class
import com.digitalaria.gama.wheel.Wheel;
import com.digitalaria.gama.wheel.WheelAdapter;
public class Home extends MainActivity implements OnClickListener
{
private RemoteIt application;
private SharedPreferences preferences;
#Override
protected void onCreate(Bundle savedInstanceState)
{
this.application = (RemoteIt) this.getApplication();
this.preferences = this.application.getPreferences();
super.onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle(s);
this.checkOnCreate();
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View contentView = inflater.inflate(R.layout.home, null, false);
mDrawer.addView(contentView, 0);
init();
wheel();
}
private void wheel()
{
wheel.setOnItemClickListener(new WheelAdapter.OnItemClickListener()
{
#Override
public void onItemClick(WheelAdapter<?> parent, View view, int position, long id)
{
switch (position)
{
case 0:
Intent ac = new Intent(Home.this, ConnectionListActivity.class);
startActivity(ac);
break;
case 1:
Intent b = new Intent(Home.this, ControlActivity.class);
startActivity(b);
break;
case 2:
Intent c = new Intent(Home.this, FileExplorerActivity.class);
startActivity(c);
// this.toggleKeyboard();
break;
case 3:
Intent d = new Intent(Home.this, Presentation.class);
startActivity(d);
break;
case 4:
Intent e = new Intent(Home.this, Media.class);
startActivity(e);
break;
case 5:
Intent f = new Intent(Home.this, Shortcuts.class);
startActivity(f);
break;
case 6:
Intent g = new Intent(Home.this, Browser.class);
startActivity(g);
break;
}
}
});
}
private Wheel wheel;
private Resources res;
private int[] icons = {
R.drawable.conn, R.drawable.mouse, R.drawable.file, R.drawable.present, R.drawable.media, R.drawable.shortc, R.drawable.browser
};
private void init()
{
res = getApplicationContext().getResources();
wheel = (Wheel) findViewById(R.id.wheel);
wheel.setItems(getDrawableFromData(icons));
wheel.setWheelDiameter((int) getResources().getDimension(R.dimen.diameter));
}
private Drawable[] getDrawableFromData(int[] data)
{
Drawable[] ret = new Drawable[data.length];
for (int i = 0; i < data.length; i++)
{
ret[i] = res.getDrawable(data[i]);
}
return ret;
}
LogCat
Process: com.RemoteIt.client, PID: 1825
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.RemoteIt.client/com.RemoteIt.client.activity.Home}: android.view.InflateException: Binary XML file line #8: Error inflating class com.digitalaria.gama.wheel.Wheel
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
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:5001)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.digitalaria.gama.wheel.Wheel
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.RemoteIt.client.activity.Home.onCreate(Home.java:50)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            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:5001)
            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:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at com.RemoteIt.client.activity.Home.onCreate(Home.java:50)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            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:5001)
            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:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsupportedOperationException: Can't convert to integer: type=0x3
at android.content.res.TypedArray.getInteger(TypedArray.java:368)
at com.digitalaria.gama.wheel.WheelBehavior.<init>(WheelBehavior.java:117)
at com.digitalaria.gama.wheel.Wheel.<init>(Wheel.java:83)
at com.digitalaria.gama.wheel.Wheel.<init>(Wheel.java:68)
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at android.view.LayoutInflater.createView(LayoutInflater.java:594)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at com.RemoteIt.client.activity.Home.onCreate(Home.java:50)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            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:5001)
            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:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
Wheel.java
public final class Wheel extends android.widget.FrameLayout {
public static final int CCW = -1;
public static final int CW = 1;
private com.digitalaria.gama.wheel.WheelBehavior _wheelBehavior;
private android.view.ViewStub _backgroundViewDummy;
protected android.view.View _backgroundView;
protected boolean _hasBackgroundImage;
private android.widget.FrameLayout.LayoutParams params;
private int _reservedPositionLeft;
private int _reservedPositionTop;
private boolean isLayout;
private int _storedLeft;
private int _storedTop;
private int _storedRight;
private int _storedBottom;
private int _centerX;
private int _centerY;
public Wheel(android.content.Context context) { /* compiled code */ }
public Wheel(android.content.Context context, android.util.AttributeSet attrs) { /* compiled code */ }
public Wheel(android.content.Context context, android.util.AttributeSet attrs, int defStyle) { /* compiled code */ }
protected void onLayout(boolean changed, int l, int t, int r, int b) { /* compiled code */ }
public void addView(android.view.View child) { /* compiled code */ }
public void addView(android.view.View child, int index) { /* compiled code */ }
public void removeView(android.view.View child) { /* compiled code */ }
public void removeViewAt(int index) { /* compiled code */ }
public float getCenterX() { /* compiled code */ }
public float getCenterY() { /* compiled code */ }
public final void setOnItemClickListener(com.digitalaria.gama.wheel.WheelAdapter.OnItemClickListener listener) { /* compiled code */ }
public final com.digitalaria.gama.wheel.WheelAdapter.OnItemClickListener getOnItemClickListener() { /* compiled code */ }
public final void setOnWheelRotationListener(com.digitalaria.gama.wheel.WheelAdapter.OnWheelRotationListener listener) { /* compiled code */ }
public final com.digitalaria.gama.wheel.WheelAdapter.OnWheelRotationListener getOnWheelRotationListener() { /* compiled code */ }
public void setOnItemSelectionUpdatedListener(com.digitalaria.gama.wheel.WheelAdapter.OnItemSelectionUpdatedListener listener) { /* compiled code */ }
public void setPosition(int left, int top) { /* compiled code */ }
public void setSelectionAngle(int angle) { /* compiled code */ }
public void setItems(android.content.res.TypedArray items) { /* compiled code */ }
public void setItems(android.graphics.drawable.Drawable[] drawables) { /* compiled code */ }
public void setWheelDiameter(int diameter) { /* compiled code */ }
public void setWheelBackground(int inflatedId, int layoutResource) { /* compiled code */ }
public void setRotatedItem(boolean flag) { /* compiled code */ }
public void configureWheelBackground(int initRotationAngle, boolean rotatedItem) { /* compiled code */ }
public void configureWheelBackground(boolean rotatedItem) { /* compiled code */ }
protected boolean hasBackgroundImage() { /* compiled code */ }
public void setTouchArea(int from, int to) { /* compiled code */ }
public int nextItem() { /* compiled code */ }
public int previousItem() { /* compiled code */ }
public boolean isRotationFinished() { /* compiled code */ }
public void flingStartUsingAngle(float angle) { /* compiled code */ }
public void flingStartUsingVelocity(int vx, int vy, boolean scroolToSlot) { /* compiled code */ }
public void flingStartUsingVelocityWithDirection(int vx, int vy, int direction) { /* compiled code */ }
public int getSelectedItem() { /* compiled code */ }
public int getSelectedItem(boolean stopScroll) { /* compiled code */ }
public boolean setSelectedItem(int index) { /* compiled code */ }
public void setItemClickEventAtSelectionPosition(boolean enable) { /* compiled code */ }
public boolean getItemClickEventAtSelectionPosition() { /* compiled code */ }
public void setEnabled(boolean enabled) { /* compiled code */ }
public boolean isLayouted() { /* compiled code */ }
}
The relevant exception :
Caused by: java.lang.UnsupportedOperationException: Can't convert to integer: type=0x3
at android.content.res.TypedArray.getInteger(TypedArray.java:368)
at com.digitalaria.gama.wheel.WheelBehavior.<init>(WheelBehavior.java:117)
WheelBehavior.java, line 117
setWheelDiameter(arr.getInteger(R.styleable.Wheel_wheel_diameter, Configuration.DEFAULT_WHEEL_DIAMETER));
Here are the styleable attributes :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Wheel">
<attr name="wheel_rotation_duration" format="integer"/> <!-- default:400 -->
<attr name="wheel_diameter" format="integer"/> <!-- default:250 -->
<attr name="items" format="integer"/>
<attr name="item_selected_index" format="integer"/>
</declare-styleable>
</resources>
wheel_diameter must be defined somewhere in your project, with something else than a integer inside it. That's why it crashed. But according to your layout, it is not. Try a global search on the string wheel_diameter
I think my answer is a rave, but you can try to set layout_gravity="center" or layout_gravity="center_horizontal" cause I think the creator of the library tries to get this property.
Try to replace this code :
compile files('libs/gama_wheel_v1.0.jar')
compile files('libs/PayPalAndroidSDK.jar')
With this code :
compile fileTree(dir: 'libs', include: '*.jar')
Caused by: java.lang.UnsupportedOperationException: Can't convert to integer: type=0x3
at android.content.res.TypedArray.getInteger(TypedArray.java:368)
at com.digitalaria.gama.wheel.WheelBehavior.<init>(WheelBehavior.java:117)
at com.digitalaria.gama.wheel.Wheel.<init>(Wheel.java:83)
at com.digitalaria.gama.wheel.Wheel.<init>(Wheel.java:68)
I think you need to look into this one. Not sure if Wheel is something you made or downloaded, but it seems to be having a problem in its setup.

Android: Google play games services connection error ( java.lang.IllegalStateException: GoogleApiClient must be connected.)

I've programmed a game for android, everything works fine, but now I want my app to have Google play Games services (leaderboards and achievements). I used the Google example code to log in to the Google services (no errors in the script), but every time I want to connect with my App in debug mode, I get this error:
6-29 11:48:29.391 23779-23779/com.JFKGames.theepicbutton E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.JFKGames.theepicbutton, PID: 23779
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=9001, result=10004, data=null} to activity {com.JFKGames.theepicbutton/com.JFKGames.theepicbutton.MainActivity}: java.lang.IllegalStateException: GoogleApiClient must be connected.
at android.app.ActivityThread.deliverResults(ActivityThread.java:3446)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3489)
at android.app.ActivityThread.access$1300(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1258)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: GoogleApiClient must be connected.
at com.google.android.gms.internal.fq.a(Unknown Source)
at com.google.android.gms.games.Games.c(Unknown Source)
at com.google.android.gms.games.internal.api.LeaderboardsImpl.submitScore(Unknown Source)
at com.google.android.gms.games.internal.api.LeaderboardsImpl.submitScore(Unknown Source)
at com.JFKGames.theepicbutton.MainActivity.onActivityResult(MainActivity.java:79)
at android.app.Activity.dispatchActivityResult(Activity.java:5446)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3442)
            at android.app.ActivityThread.handleSendResult(ActivityThread.java:3489)
            at android.app.ActivityThread.access$1300(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1258)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5102)
            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:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
And the App crashes. Here's my code for the MainActivity where I want it to connect:
public class MainActivity extends BaseGameActivity implements
GameHelper.GameHelperListener, View.OnClickListener {
public static int REQUEST_LEADERBOARD = 1002;
boolean mExplicitSignOut = false;
boolean mInSignInFlow = false;
GoogleApiClient mClient() {
return null;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
setRequestedClients(BaseGameActivity.CLIENT_GAMES | BaseGameActivity.CLIENT_APPSTATE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button)findViewById(R.id.startbutton);
button.setOnClickListener (this);
Button highscorebutton = (Button)findViewById(R.id.highscorebutton);
highscorebutton.setOnClickListener(this);
findViewById(R.id.sign_in_button).setOnClickListener(this);
findViewById(R.id.sign_out_button).setOnClickListener(this);
}
public void onClick(View view) {
if(view.getId()==R.id.startbutton) {
startActivityForResult(new Intent(this, buttonActivity.class), 1);
} else if(view.getId()==R.id.highscorebutton) {
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(getApiClient(), getString(R.string.the_best_players)),REQUEST_LEADERBOARD);
} else if (view.getId() == R.id.sign_in_button) {
// start the asynchronous sign in flow
beginUserInitiatedSignIn();
}
else if (view.getId() == R.id.sign_out_button) {
// sign out.
signOut();
// show sign-in button, hide the sign-out button
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
findViewById(R.id.sign_out_button).setVisibility(View.GONE);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Games.Leaderboards.submitScore(getApiClient(), getString(R.string.the_best_players), resultCode);
if(requestCode==1) {
if(resultCode > leseHighscore()) {
schreibeHighscore(resultCode);
}
}
}
#Override
public void onSignInFailed() {
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
findViewById(R.id.sign_out_button).setVisibility(View.GONE);
}
#Override
public void onSignInSucceeded() {
View a = findViewById(R.id.highscorebutton);
a.setVisibility(View.VISIBLE);
View b = findViewById(R.id.button3);
b.setVisibility(View.VISIBLE);
findViewById(R.id.sign_in_button).setVisibility(View.GONE);
findViewById(R.id.sign_out_button).setVisibility(View.VISIBLE);
}
}
Thanks, GoogleWelt
According to the official documentation, "Before any operation is executed, the GoogleApiClient must be connected"
When the user in not connected(signed in) and clicks to show leaderboards or achievements, it results in the exception thrown. Modify your code for launching the leaderboard like this:
} else if(view.getId()==R.id.highscorebutton) {
if (isSignedIn())
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(getApiClient(), getString(R.string.the_best_players)), REQUEST_LEADERBOARD);
else showAlert("Please sign in to view leaderboards");
}
Use the same logic for showing achievements:
if (isSignedIn())
startActivityForResult(Games.Achievements.getAchievementsIntent(getApiClient()), REQUEST_ACHIEVEMENT);
else showAlert("Please sign in to view achievements");
Check the part where you are getting ApiClient i.e. getApiClient().
Write the code below to see if GoogleApiClient is Connected or not.
GoogleApiClient mGoogleApiClient;
if(mGoogleApiClient.isConnected()){
// good
}else{
//connect it
mGoogleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_OPTIONAL);
}

Fatal Error On main Thread

I am receiving this fatal Error, when I try to access one particular function zipIt().
It doesn't matter from where I try to access it I always receive this error. This function simply zips a folder but program don't even go inside this function.
Logcat is displayed below:
Process: com.test.shahid, PID: 14839
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3823)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5050)
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:1264)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1080)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3818)
            at android.view.View.performClick(View.java:4438)
            at android.view.View$PerformClick.run(View.java:18422)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5050)
            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:1264)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1080)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at java.io.File.fixSlashes(File.java:185)
at java.io.File.<init>(File.java:134)
at java.io.FileOutputStream.<init>(FileOutputStream.java:128)
at java.io.FileOutputStream.<init>(FileOutputStream.java:117)
at com.test.shahid.MainActivity.zipIt(MainActivity.java:170)
at com.test.shahid.MainActivity.dispatchTakePictureIntent(MainActivity.java:490)
at com.test.shahid.MainActivity.onClickPhoto(MainActivity.java:468)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at android.view.View$1.onClick(View.java:3818)
            at android.view.View.performClick(View.java:4438)
            at android.view.View$PerformClick.run(View.java:18422)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5050)
            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:1264)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1080)
            at dalvik.system.NativeStart.main(Native Method)
05-23 09:48:22.023 14839-14839/com.test.shahid I/Process﹕ Sending signal. PID: 14839 SIG: 9
Here is the function and variables associated with this function.
private static final File INPUT_FOLDER = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
private static final String ZIPPED_FOLDER = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES).toString();
protected void zipIt(File inputFolder, String zipFilePath) {
try {
FileOutputStream fileOutputStream = new FileOutputStream(zipFilePath);
ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
String myname =inputFolder.toString();
ZipEntry folderZipEntry = new ZipEntry(myname);
zipOutputStream.putNextEntry(folderZipEntry);
File[] contents = inputFolder.listFiles();
for (File f : contents) {
if (f.isFile())
zipFile(f, zipOutputStream);
}
zipOutputStream.closeEntry();
zipOutputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
protected void zipFile(File inputFile, ZipOutputStream zipOutputStream) {
try { // A ZipEntry represents a file entry in the zip archive
// We name the ZipEntry after the original file's name
ZipEntry zipEntry = new ZipEntry(inputFile.getName());
zipOutputStream.putNextEntry(zipEntry);
FileInputStream fileInputStream = new FileInputStream(inputFile);
byte[] buf = new byte[1024];
int bytesRead;
// Read the input file by chucks of 1024 bytes
// and write the read bytes to the zip stream
while ((bytesRead = fileInputStream.read(buf)) > 0) {
zipOutputStream.write(buf, 0, bytesRead);
}
// close ZipEntry to store the stream to the file
zipOutputStream.closeEntry();
System.out.println("Regular file :" + inputFile.getCanonicalPath() + " is zipped to archive :" + ZIPPED_FOLDER);
} catch (IOException e) {
e.printStackTrace();
}
}
Well this is from where i am calling this function. I called this function just to check otherwise i have called this function from button and from several other functions. But nothing works.
public void onSync(View v) throws JSONException, IOException {
zipIt(INPUT_FOLDER, ZIPPED_FOLDER);
if (!isConnected()) {
AlertDialog.Builder mBuilder = new Builder(this);
mBuilder.setMessage("Please Enable Wifi to use this service");
mBuilder.setTitle("Enable WIFI");
mBuilder.setCancelable(false);
mBuilder.setPositiveButton("Settings",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent i = new Intent(
Settings.ACTION_WIFI_SETTINGS);
startActivity(i);
}
}
);
mBuilder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// This code might cause problem so check when
// device is available
MainActivity.this.finish();
}
}
);
// create alert dialog
AlertDialog alertDialog = mBuilder.create();
// show it
alertDialog.show();
tvIsConnected.setText("You are NOT conncted");
// Intent myIntent = new
// Intent(Settings.ACTION_WIFI_SETTINGS);
// startActivity(myIntent);
return;
}
tvIsConnected.setBackgroundColor(0xFF00CC00);
tvIsConnected.setText("You are conncted");
handler.sendEmptyMessage(MSG_SYNC);
}
NullPointerException
Do you have "WriteExternalStorage" permision in your manifest?
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Did you check the file path?
Environment.getExternalStorageDirectory() + "/some_foulder/file.txt"

Categories

Resources