Using multithreading: Android FATAL EXCEPTION: pool-1-thread-2 [closed] on newest questions tagged multithreading – Stack Overflow
I’m having trouble with an android app I’m trying to get working. Any help is greatly appreciated.
Heres the logcat output
07-01 18:11:03.080: D/com.localsocial.localtweets.MainActivity(1938): bootstrap
07-01 18:11:03.090: I/OAuthConsumer(1938): convertToAccessToken(XXXX)
07-01 18:11:03.119: W/AccessTokenHolder(1938): setCredentials failed
07-01 18:11:03.119: W/AccessTokenHolder(1938): java.lang.NullPointerException
07-01 18:11:03.119: W/AccessTokenHolder(1938): at com.localsocial.oauth.scribe.AccessTokenHolder.setCredentials(AccessTokenHolder.java:76)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at com.localsocial.oauth.scribe.AccessTokenHolder.<init>(AccessTokenHolder.java:56)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at com.localsocial.oauth.scribe.OAuthConsumerImpl.convertToAccessToken(OAuthConsumerImpl.java:77)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at com.localsocial.oauth.OAuthConsumerImpl.convertToAccessToken(OAuthConsumerImpl.java:85)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at com.localsocial.LocalSocialImpl.getAccessToken(LocalSocialImpl.java:137)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at com.localsocial.localtweets.MainActivity.authorised(MainActivity.java:357)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at com.localsocial.localtweets.MainActivity.bootstrap(MainActivity.java:325)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at com.localsocial.localtweets.MainActivity.onActivityResult(MainActivity.java:219)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at android.app.Activity.dispatchActivityResult(Activity.java:3908)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at android.app.ActivityThread.deliverResults(ActivityThread.java:2528)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2574)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at android.app.ActivityThread.access$2000(ActivityThread.java:117)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:961)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at android.os.Handler.dispatchMessage(Handler.java:99)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at android.os.Looper.loop(Looper.java:130)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at java.lang.reflect.Method.invokeNative(Native Method)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at java.lang.reflect.Method.invoke(Method.java:507)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-01 18:11:03.119: W/AccessTokenHolder(1938): at dalvik.system.NativeStart.main(Native Method)
07-01 18:11:03.119: D/com.localsocial.localtweets.MainActivity(1938): not authorised
07-01 18:11:03.160: D/com.localsocial.localtweets.MainActivity(1938): trying to load access token
07-01 18:11:03.160: D/com.localsocial.localtweets.MainActivity(1938): notauth exception
07-01 18:11:03.170: W/System.err(1938): com.localsocial.remote.exception.UnauthorizedException
07-01 18:11:03.170: W/System.err(1938): at com.localsocial.LocalSocialImpl.loadAccessToken(LocalSocialImpl.java:154)
07-01 18:11:03.170: W/System.err(1938): at com.localsocial.localtweets.MainActivity.bootstrap(MainActivity.java:329)
07-01 18:11:03.170: W/System.err(1938): at com.localsocial.localtweets.MainActivity.onActivityResult(MainActivity.java:219)
07-01 18:11:03.170: W/System.err(1938): at android.app.Activity.dispatchActivityResult(Activity.java:3908)
07-01 18:11:03.170: W/System.err(1938): at android.app.ActivityThread.deliverResults(ActivityThread.java:2528)
07-01 18:11:03.180: W/System.err(1938): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2574)
07-01 18:11:03.180: W/System.err(1938): at android.app.ActivityThread.access$2000(ActivityThread.java:117)
07-01 18:11:03.180: W/System.err(1938): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:961)
07-01 18:11:03.180: W/System.err(1938): at android.os.Handler.dispatchMessage(Handler.java:99)
07-01 18:11:03.180: W/System.err(1938): at android.os.Looper.loop(Looper.java:130)
07-01 18:11:03.190: W/System.err(1938): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-01 18:11:03.190: W/System.err(1938): at java.lang.reflect.Method.invokeNative(Native Method)
07-01 18:11:03.190: W/System.err(1938): at java.lang.reflect.Method.invoke(Method.java:507)
07-01 18:11:03.190: W/System.err(1938): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-01 18:11:03.190: W/System.err(1938): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-01 18:11:03.190: W/System.err(1938): at dalvik.system.NativeStart.main(Native Method)
07-01 18:11:03.190: I/OAuthConsumer(1938): convertToAccessToken(XXXX)
07-01 18:11:03.219: W/AccessTokenHolder(1938): setCredentials failed
07-01 18:11:03.219: W/AccessTokenHolder(1938): java.lang.NullPointerException
07-01 18:11:03.219: W/AccessTokenHolder(1938): at com.localsocial.oauth.scribe.AccessTokenHolder.setCredentials(AccessTokenHolder.java:76)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at com.localsocial.oauth.scribe.AccessTokenHolder.<init>(AccessTokenHolder.java:56)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at com.localsocial.oauth.scribe.OAuthConsumerImpl.convertToAccessToken(OAuthConsumerImpl.java:77)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at com.localsocial.oauth.OAuthConsumerImpl.convertToAccessToken(OAuthConsumerImpl.java:85)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at com.localsocial.LocalSocialImpl.getAccessToken(LocalSocialImpl.java:137)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at com.localsocial.localtweets.MainActivity.authorised(MainActivity.java:357)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at com.localsocial.localtweets.MainActivity.bootstrap(MainActivity.java:334)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at com.localsocial.localtweets.MainActivity.onActivityResult(MainActivity.java:219)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at android.app.Activity.dispatchActivityResult(Activity.java:3908)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at android.app.ActivityThread.deliverResults(ActivityThread.java:2528)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2574)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at android.app.ActivityThread.access$2000(ActivityThread.java:117)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:961)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at android.os.Handler.dispatchMessage(Handler.java:99)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at android.os.Looper.loop(Looper.java:130)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at java.lang.reflect.Method.invokeNative(Native Method)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at java.lang.reflect.Method.invoke(Method.java:507)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-01 18:11:03.219: W/AccessTokenHolder(1938): at dalvik.system.NativeStart.main(Native Method)
07-01 18:11:03.219: I/com.localsocial.localtweets.MainActivity(1938): onResume()
07-01 18:11:03.250: I/OAuthConsumer(1938): rebuildService(bt0023769FD3B5)
07-01 18:11:03.250: I/LocalSocialApi10a(1938): <ctor>() current=http://www.mylocalsocial.com
07-01 18:11:03.250: I/LocalSocialApi10a(1938): getRequestTokenEndpoint() : address=bt0023769FD3B5
07-01 18:11:03.289: I/LocalSocialApi10a(1938): getRequestTokenEndpoint() => http://www.mylocalsocial.com/oauth/request_token?scope=bt0023769FD3B5,v1
07-01 18:11:03.289: I/LocalSocialApi10a(1938): getAccessTokenEndpoint() => http://www.mylocalsocial.com/oauth/access_token
07-01 18:11:07.879: D/dalvikvm(1938): GC_FOR_MALLOC freed 1195K, 56% free 2969K/6663K, external 2002K/2137K, paused 55ms
07-01 18:11:10.230: D/dalvikvm(1938): GC_FOR_MALLOC freed 83K, 54% free 3080K/6663K, external 2002K/2137K, paused 19ms
07-01 18:11:10.230: I/dalvikvm-heap(1938): Grow heap (frag case) to 7.455MB for 131088-byte allocation
07-01 18:11:10.259: D/dalvikvm(1938): GC_FOR_MALLOC freed 14K, 54% free 3194K/6855K, external 2002K/2137K, paused 19ms
07-01 18:11:10.270: D/com.localsocial.localtweets.MainActivity(1938): bootstrap
07-01 18:11:10.280: I/OAuthConsumer(1938): convertToAccessToken(XXXX)
07-01 18:11:10.290: I/RestImpl(1938): <ctor>()
07-01 18:11:10.290: I/OAuthConsumer(1938): convertToAccessToken(XXXX)
07-01 18:11:10.300: I/RetryingRest(1938): <ctor>()
07-01 18:11:10.300: I/Server(1938): <ctor>()
07-01 18:11:10.310: I/Server(1938): <ctor>()
07-01 18:11:10.319: I/OAuthConsumer(1938): doRequest(com.localsocial.oauth.scribe.AccessTokenHolder@4054f400,/v1/tags/com_localsocial_tulsi-Twitter-bt0023769FD3B5-bt0023769FD3B5.json,null)
07-01 18:11:11.339: W/RetryingRest(1938): check(http=GET,path=/v1/tags/com_localsocial_tulsi-Twitter-bt0023769FD3B5-bt0023769FD3B5.json,query=null,body=null,e=com.localsocial.remote.exception.NoSuchObjectException: No tag exists! : <response=com.localsocial.remote.http.HttpResponse@40557738>,retries=3)
07-01 18:11:11.339: W/RetryingRest(1938): check rethrowing NoSuchObjectException
07-01 18:11:11.339: E/com.localsocial.localtweets.MainActivity(1938): Error getting twitter : No tag exists!
07-01 18:11:11.339: W/dalvikvm(1938): threadid=14: thread exiting with uncaught exception (group=0x40015560)
07-01 18:11:11.339: E/AndroidRuntime(1938): FATAL EXCEPTION: pool-1-thread-2
07-01 18:11:11.339: E/AndroidRuntime(1938): java.lang.NullPointerException
07-01 18:11:11.339: E/AndroidRuntime(1938): at com.localsocial.localtweets.MainActivity.getMyTwitter(MainActivity.java:576)
07-01 18:11:11.339: E/AndroidRuntime(1938): at com.localsocial.localtweets.MainActivity$5.run(MainActivity.java:556)
07-01 18:11:11.339: E/AndroidRuntime(1938): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
07-01 18:11:11.339: E/AndroidRuntime(1938): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
07-01 18:11:11.339: E/AndroidRuntime(1938): at java.lang.Thread.run(Thread.java:1019)
07-01 18:11:11.349: I/com.localsocial.localtweets.MainActivity(1938): onPause()
07-01 18:11:11.349: D/com.localsocial.localtweets.MainActivity(1938): stopScan
07-01 18:11:11.390: W/ProximityScannerImpl(1938): stop :: discovery already in progress
07-01 18:11:13.380: I/Process(1938): Sending signal. PID: 1938 SIG: 9
Heres the main class. There are two other classes but I don’t think they’re the problem. Can attach if anyone needs to see them.
public class MainActivity extends ListActivity {
// logging
private boolean d = true;
private final String TAG = getClass().getName();
// listview
private LayoutInflater mInflater;
//private Vector<String> devices = new Vector<String>();
private Vector<LocalTweetsItem> devices = new Vector<LocalTweetsItem>();
private CustomAdapter adapter;
// executor
protected final Executor m_executor = Executors.newCachedThreadPool();
// handler
protected final Handler m_handler = new Handler();
// dialog codes
private static final int REQUEST_ENABLE_BT = 0;
private static final int REQUEST_CODE_AUTH_TWITTER = 1;
private static final int DIALOG_FINISH_NO_BT = 2;
private static final int DIALOG_FINISH_AUTH_ERROR = 3;
// Twitter
public Network twitter;
public boolean triedNetwork = false;
// LocalSocial
private LocalSocial m_localsocial;
private NeighbourhoodObserver m_nobby = null;
private Neighbourhood m_neighbourhood;
// LocalSocial config
private final static String CALLBACK = "LocalTweets://callback";
private final static String NAME = "LocalTweets";
private final static String KEY = "UpLHN9YbMcBHMVnWNcyouev0LegFdGlPsaA0S4b9";
private final static String SECRET = "RqMe7ntR7hxgNomZqxq1FcgEWEmAQRtNAAcBtbiz";
private SimpleAppConfiguration m_sac = new SimpleAppConfiguration(CALLBACK, NAME, KEY, SECRET, null);
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mInflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
adapter = new CustomAdapter(this, R.layout.main, R.id.device, devices);
setListAdapter(adapter);
getListView().setTextFilterEnabled(true);
// *** LocalSocial Config ***
Platform platform = new Platform();
platform.setContext(getApplication());
LoggerFactory.load(platform);
m_sac.setPlatformContext(platform);
LocalSocialFactory.setDefaultConfig(LocalSocialFactory.populate(m_sac));
m_localsocial = LocalSocialFactory.getLocalSocial();
if (d) Log.d(TAG, "LocalSocial configured");
// ***
}
public void onListItemClick(ListView parent, View v, int position, long id) {
CustomAdapter adapter = (CustomAdapter) parent.getAdapter();
LocalTweetsItem lt_item = adapter.getItem(position);
if (null != lt_item.getNetwork()) {
Uri uri = Uri.parse("http://mobile.twitter.com/" + lt_item.getTitle());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
} else {
Toast.makeText(this, String.format(getString(R.string.toast_no_twitter_for_device), lt_item.getTitle()), Toast.LENGTH_LONG).show();
}
}
private class CustomAdapter extends ArrayAdapter<LocalTweetsItem> {
public CustomAdapter(Context context, int resource,
int textViewResourceId, List<LocalTweetsItem> lt_items) {
super(context, resource, textViewResourceId, lt_items);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
TextView device_name = null;
LocalTweetsItem lt_item = getItem(position);
if (null == convertView) {
convertView = mInflater.inflate(R.layout.item, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
}
holder = (ViewHolder) convertView.getTag();
device_name = holder.getItem();
device_name.setText(lt_item.getName());
Log.d("Device", "Trying to get name..." + lt_item.getName() + " of the device " + lt_item.getDevice().getAddress());
return convertView;
}
}
/**
* Wrapper for row data.
*/
private class ViewHolder {
private View row;
private TextView item = null;
public ViewHolder(View row) {
this.row = row;
}
public TextView getItem() {
if (null == item) {
item = (TextView) row.findViewById(R.id.device);
}
return item;
}
}
@Override
protected void onStart() {
Log.i(TAG, "onStart()");
super.onStart();
bootstrap();
}
@Override
protected void onPause() {
Log.i(TAG, "onPause()");
stopScan();
super.onPause();
}
@Override
protected void onResume() {
Log.i(TAG, "onResume()");
super.onResume();
}
/**
* Called when a launched activity exits
*/
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_ENABLE_BT:
if (resultCode != RESULT_OK || !bluetoothEnabled()) {
showDialog(DIALOG_FINISH_NO_BT);
return;
}
bootstrap();
break;
case REQUEST_CODE_AUTH_TWITTER:
Log.d(TAG, "Auth twitter result = " + resultCode);
if (resultCode == RESULT_OK) {
Log.d(TAG, "Network added");
String location = getLocation(data.getStringExtra("result"));
loadAndPublishNetwork(location);
if (d) Log.d(TAG, "Twitter account name = " + twitter.m_name);
} else if (resultCode == RESULT_CANCELED) {
Log.d(TAG, "Auth cancelled");
finishAuthFailed(this.getString(R.string.twitter_auth_cancelled));
} else if (resultCode == TwitterAuthActivity.RESULT_LOCALSOCIAL_ERROR) {
Log.d(TAG, "LocalSocial Error :-/");
finishAuthFailed(this.getString(R.string.twitter_auth_fail));
} else {
Log.d(TAG, "Auth failed unknown code : " + resultCode);
finishAuthFailed(this.getString(R.string.twitter_auth_fail));
}
break;
default:
break;
}
}
private void finishAuthFailed(String msg) {
triedNetwork = true;
Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
// TODO is it the right thing to do?
startScan();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
/**
* Called when a menu item is clicked
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.discovery_status:
Intent discoverableIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);
break;
case R.id.scan_status:
startScan();
break;
}
return true;
}
/**
* Dialogs
*
* @param id dialog id
*/
protected Dialog onCreateDialog(int id) {
Dialog dialog;
switch (id) {
case DIALOG_FINISH_NO_BT:
dialog = createRetryExitDialog(this.getString(R.string.no_bluetooth_warning));
break;
case DIALOG_FINISH_AUTH_ERROR:
dialog = createRetryExitDialog(this.getString(R.string.ls_auth_error));
break;
default:
Log.e(TAG, "Unknown dialog : " + id);
dialog = null;
}
return dialog;
}
private AlertDialog createRetryExitDialog(String msg) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(msg)
.setCancelable(false)
.setPositiveButton("Retry", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
bootstrap();
}
})
.setNegativeButton("Exit", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
return builder.create();
}
/**
* LocalSocial bootstrap
*/
protected void bootstrap() {
if (d) Log.d(TAG, "bootstrap");
if (!bluetoothEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
} else {
if (isOnline()) {
if (!authorised()) {
if (d) Log.d(TAG, "not authorised");
try {
if (d) Log.d(TAG, "trying to load access token");
m_localsocial.loadAccessToken();
} catch (UnauthorizedException e) {
if (d) Log.d(TAG, "notauth exception");
e.printStackTrace();
}
if (!authorised()) {
authorise();
return;
}
}
boolean forceReAuth = false; //For Testing
if ((forceReAuth || null == twitter) && !triedNetwork) {
doGetMyTwitter(forceReAuth);
return;
}
startScan();
} else {
Toast.makeText(this, this.getString(R.string.toast_offline_warning), Toast.LENGTH_LONG).show();
}
}
}
/*
* Check if authorised with LocalSocial
*/
private boolean authorised() {
try {
return m_localsocial.getAccessToken() != null;
} catch (UnauthorizedException e) {
return false;
}
}
/**
* Check if a device supports Bluetooth
*
* @return true if device provides Bluetooth support and it is enabled
*/
private boolean bluetoothEnabled() {
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
throw new LocalSocialError("no bluetooth support");
}
return mBluetoothAdapter.isEnabled();
}
/**
* Check if a device is connected to a network
*
* @return true if connected, false otherwise
*/
public boolean isOnline() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
return (netInfo != null && netInfo.isConnectedOrConnecting());
}
/**
* Authorise with LocalSocial
*/
private void authorise() {
doAuthorise();
}
/**
* Authorise with LocalSocial
*/
public void doAuthorise() {
m_executor.execute(new Runnable() {
public void run() {
try {
OAuthConsumer m_consumer = m_localsocial.getOAuthConsumer();
RequestToken rt = m_consumer.generateRequestToken();
Verifier v = m_consumer.authorise(rt);
AccessToken at = m_consumer.exchange(rt, v);
LocalSocial.Credentials creds = LocalSocialFactory.createCredentials(at);
m_localsocial.saveAccessToken(at);
m_localsocial.getConfig().setCredentials(creds);
m_handler.post(new Runnable() {
public void run() {
bootstrap();
}
});
}
catch (Exception e) {
//ToDo Need to handle ls runtime errors fuck sake
e.printStackTrace();
}
}
});
}
private void startScan() {
Log.d(TAG, "startScan");
if (null != m_localsocial) {
m_localsocial.getNeighbourhood().observeNeighbourhood(getNeighbourhoodObserver());
m_localsocial.getNeighbourhood().startScan();
}
}
private void stopScan() {
Log.d(TAG, "stopScan");
if (null != m_localsocial) {
m_localsocial.getNeighbourhood().removeObserver(getNeighbourhoodObserver());
m_localsocial.getNeighbourhood().startScan();
}
}
private void restartScan() {
Log.d(TAG, "restartScan");
if (null != m_localsocial && !m_localsocial.getNeighbourhood().isCurrentlyScanning()) {
stopScan();
startScan();
}
}
/*
* NeighbourhoodObserver
*/
protected NeighbourhoodObserver getNeighbourhoodObserver() {
if (null == m_nobby) {
m_nobby = new NeighbourhoodObserverAdapter() {
final Map<String, Device> m_inRange = new HashMap<String, Device>();
@Override
public void discovered(final Device device) {
if (d) Log.d("Scan", "discovered : " + device.getAddress());
device.setTimeout(60000);
synchronized (m_inRange) {
String mac = device.getAddress();
if (!m_inRange.containsKey(mac)) {
m_inRange.put(mac, device);
m_executor.execute(new Runnable() {
public void run() {
try {
getNetworkInfo(device);
} catch (LocalSocialError lse) {
lse.printStackTrace();
} catch (LocalSocialException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
LocalTweetsItem lt_item = new LocalTweetsItem(device);
try {
Network try_twitter = getTwitterInfo(device.getAddress());
lt_item.setNetwork(try_twitter);
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (d) Log.d("Device", "discovered " + lt_item.getDevice().getAddress());
devices.add(lt_item);
adapter.notifyDataSetChanged();
}
}
}
public void scanModeChanged(String address, int mode) {
if (d) Log.d("Scan", "scan mode changed to " + mode + " for " + address);
}
@Override
public void inRange(Device device) {
if (d) Log.d("Scan", "inRange : " + device.getAddress());
}
@Override
public void outOfRange(final Device device) {
if (d) Log.d("Scan", "outOfRange : " + device.getAddress());
LocalTweetsItem to_remove = null;
Iterator<LocalTweetsItem> it = devices.iterator();
while (it.hasNext()) {
LocalTweetsItem curr = it.next();
if (curr.getDevice().getAddress() == device.getAddress()) {
to_remove = curr;
}
}
m_inRange.remove(device.getAddress());
devices.remove(to_remove);
adapter.notifyDataSetChanged();
}
};
}
return m_nobby;
}
// Twitter related
/**
* Starts TwitterAuthActivity
*/
private void startTwitterAuth() {
Intent intent = new Intent(MainActivity.this, TwitterAuthActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("URL", "/auth/twitter");
intent.putExtra("NETWORK", "twitter");
intent.putExtra("API", m_localsocial.getConfig().getBase());
startActivityForResult(intent, REQUEST_CODE_AUTH_TWITTER);
}
private String getLocation(String u) {
URI uri = URI.create(u);
String t = uri.getPath();
if (uri.getQuery() != null) {
t += "?" + uri.getQuery();
}
return t;
}
public void doGetMyTwitter(final boolean forceReAuth) {
m_executor.execute(new Runnable() {
public void run() {
try {
getMyTwitter(forceReAuth);
} catch (UnauthorizedException e) {
Log.e(TAG, "error" + e.getMessage());
} catch (IOException e) {
Log.e(TAG, "error" + e.getMessage());
}
}
});
}
public void getMyTwitter(final boolean fo
See Answers
source: http://stackoverflow.com/questions/11284422/android-fatal-exception-pool-1-thread-2
Using multithreading: using-multithreading
Recent Comments