I'm trying to check an EditText value, but the application crashes.
How can I handle my EditText?
String stra_txt = edit_1.getText().toString();
boolean first = false;
if (stra_txt.equals("1") || stra_txt.equals("0"))
{
first = true;
}
else
{
first = false;
}
if(first = true)
zheg();
else
{System.exit(0);}
this code does not work too:
String stra_txt = edit_1.getText().toString();
if (stra_txt.equals("1") || stra_txt.equals("0"))
{
zheg();
}
else
{
System.exit(0);
}
upd.
I've found solution:
if (edit_1.getText().toString().equals("")){
finish();
}
else
{
zheg();
}
Use try Catch Block its get actual error or app crash
try
{
String stra_txt = edit_1.getText().toString();
boolean first = false;
boolean second = false;
if (stra_txt.equals("1") || stra_txt.equals("0"))
{
first = true;
}
else
{
first = false;
}
if(first = true)
zheg();
else
{System.exit(0);}
}
catch (Exception e)
{
e.printStackTrace();
}
Check whether you have linked your EditText id with XML
EditText edit_1 = (EditText) findViewById(R.id.edit_1);
if you have given this, then there must be a problem with zheg() method.
Please post your logs here.
Try this code
if(edit_1 != null){
String stra_txt = edit_1.getText().toString();
if ((stra_txt.equals("1") || stra_txt.equals("0")){
zheg();
}else{
// System.exit(0);
finish();
}
}
if this prevents your app from getting crashed then probably you may not be initializing the view. Add this line before the above code:
edit_1 = (EditText)findViewById(YOUR_VIEW_ID);
Related
I am using the following TCPListener in Xamarin.Android that has served me well in the past, but only have one problem with it...
In the following piece of code within startListener() (Full code below)
while (!NS.DataAvailable && sta)
{
System.Threading.Thread.Sleep(50);
if (cntr > 20)
{
TCPC.Close();
NS = null;
break;
}
cntr++;
}
The TCPClient gets closed if the NetworkSteam has not data to Send(Reply) or Receive for a period of time, which is not a problem and do need it to close this.
Problem is that I can set this "timeout" between changing Thread.Sleep(50) value and cntr > 20 value, but becomes very difficult to predict how long this timeout needs to be depending on what data was received, as I need to perform long running operations on the data before sending the reply (long running as in could be 3sec or 30sec), if I set it too short then it closes my TCP client before I am able to reply, if I set it too long the port is blocked for many seconds after sending the reply and I cannot send the next command until this timeout has expired. Is there a better way to handle this timeout, or a better implementation not using TCPListener
private static void startListener()
{
ListenStarted = true;
TCPL = new TcpListener(IPAddress.Any, 8012);
try
{
TCPL.Start();
sta = true;
}
catch (Exception e)
{
//Log Error
}
while (sta)
{
try
{
TCPC = TCPL.AcceptTcpClient();
TCPC.NoDelay = true;
NS = TCPC.GetStream();
while (NS.CanRead && NS.CanWrite && sta)
{
StringBuilder sb = new StringBuilder();
int cntr = 0;
while (!NS.DataAvailable && sta)
{
System.Threading.Thread.Sleep(50);
if (cntr > 20)
{
TCPC.Close();
NS = null;
break;
}
cntr++;
}
if (NS == null)
break;
while (NS.DataAvailable && sta)
{
int bte = NS.ReadByte();
if (bte == -1)
break;
if ((char)bte != (char)0x03)
{
sb.Append((char)bte);
}
else
{
processDataSets(sb);
break;
}
}
}
}
catch (Exception e)
{
sta = false;
}
}
ListenStarted = false;
NS = null;
}
I am new to android can someone help me please, following is the code i tried to run for scanning the fingerprint but it gives an error whenever i click the button it says force to close what should i do help me please.
Intent fingerPrintCaptureImageIntent = new Intent(
Intent.ACTION_SEND);
fingerPrintCaptureImageIntent
.putExtra("source", "registration");
// fingerPrintCaptureImageIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
// fingerPrintCaptureImageIntent.setComponent(new
// ComponentName("com.integratedbiometrics.SimpleScan",
// "com.integratedbiometrics.SimpleScan.SimpleScanActivity"));
PackageManager packageManager = getActivity()
.getPackageManager();
List<ResolveInfo> activities = packageManager
.queryIntentActivities(fingerPrintCaptureImageIntent, 0);
boolean isIntentSafe = activities.size() > 0;
if (isIntentSafe) {
try {
startActivityForResult( fingerPrintCaptureImageIntent, Constants.FINGER_PRINT_REQUEST_CODE_FOR_REGISTRATION);
}
catch (Exception e) {
Log.d("TAG",e.getMessage());
e.printStackTrace();
}
} else {
Log.i("No Such Activity Found",
"No Such Activity Found To Open.");
}
And the onActivityResult method is :
if (requestCode == Constants.FINGER_PRINT_REQUEST_CODE_FOR_REGISTRATION
&& resultCode == Activity.RESULT_OK) {
if (data.hasExtra("cancel")) {
// do nothing ...
} else if (data.hasExtra("file_name")) {
String fileName = data.getStringExtra("file_name");
((TextView) getActivity().findViewById(
R.id.fingerprintTakenInfoText)).setText(fileName + "");
if (fileName != null) {
try {
String fingerData = Utility
.ReadFingerDataFromExternalStorage(fileName);
parentActivity.registrationEntity.fingerPrints = fingerData;
fingerPrintDataFileName = fileName;
((TextView) getActivity().findViewById(
R.id.fingerprintTakenInfoText))
.setBackgroundColor(getResources().getColor(
R.color.green));
((TextView) getActivity().findViewById(
R.id.fingerprintTakenInfoText))
.setText("Finger print taken.");
} catch (Exception exp) {
((TextView) getActivity().findViewById(
R.id.fingerprintTakenInfoText))
.setText("Reading finger print data from file failed.");
}
}
}
On Calling my App secugen , I have got exception . The error is
My SecuGen app is crashed . Can you help me ?
This is a strange one and I hope that someone can at least give me a direction to look in.
My Android application uses GoogleMap API v2. In the app, I run an activity off OnClickInfoWindowListener on one of the markers. In detail, when I click on the particular marker, an InfoWindow of that marker appears. Next when I click on the InfoWindow, it launches another activity.
The problem is that when I return to GoogleMap from that activity, the particular marker which launched the activity, is not responsive. By responsive, I mean when I click on it, I do not get an InfoWindow. There is no such problem with the other markers. To fix the problem, I either move or zoom on the map or click on another marker to show its InfoWindow, then the original marker works normally. I cannot see any red stuff on the LogCat.
I also run the map off a ListView and there is no problem (that I can see).
Any suggestions on what to look at are very welcome!
Edit 1 :
This part is the InfoWindowClickListener setup ...
// Set up info Window Click Listener
googleMap
.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker mkr) {
// Default open file
// menu option : edit file information
// menu option : delete
Log.d(TAG, "InfoWindow Click detected.");
final GeoFileData gfd = getFromHashMap(mkr);
if (editGeoFile) {
editGeoFile = false;
editFileInfo(gfd);
} else if (deleteGeoFile) {
deleteGeoFile = false;
deleteFile(gfd, mkr);
} else {
openFile(gfd);
}
}
});
The openFile routine which launches the Activity
// Public and Routines used by the main loop
private void openFile (GeoFileData gfd) {
int typeIndex = gfd.getTypeIndex();
switch(typeIndex) {
case 0 :
case 1 :
case 2 :
case 3 :
// Spen file by default
Intent notePadIntent = new Intent(getBaseContext(), NotePad.class);
Bundle b = new Bundle();
b.putParcelable(MAIN_NOTEPAD_GFD, gfd);
notePadIntent.putExtras(b);
startActivityForResult(notePadIntent, SPEN_NOTEPAD_CODE);
break;
default :
Log.w(TAG, "Unknown file.");
Toast.makeText(this, getString(R.string.toast_unknown_file), Toast.LENGTH_LONG).show();
break;
}
}
The starting part of the launched activity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_spen_notepad);
Bundle extras = getIntent().getExtras();
if (extras != null) {
inputGfd = extras.getParcelable(PreznsActivity.MAIN_NOTEPAD_GFD);
}
extras.clear();
mContext = this;
// Spen
boolean isSpenFeatureEnabled = false;
Spen spenPackage = new Spen();
try {
spenPackage.initialize(this);
isSpenFeatureEnabled = spenPackage.isFeatureEnabled(Spen.DEVICE_PEN);
} catch (SsdkUnsupportedException e) {
if( SDKUtils.processUnsupportedException(this, e) == true) {
return;
}
} catch (Exception e1) {
Toast.makeText(mContext, "Cannot initialize Spen.",
Toast.LENGTH_SHORT).show();
e1.printStackTrace();
finish();
}
FrameLayout spenViewContainer =
(FrameLayout) findViewById(R.id.spenViewContainer);
RelativeLayout spenViewLayout =
(RelativeLayout) findViewById(R.id.spenViewLayout);
// PenSettingView
mPenSettingView =
new SpenSettingPenLayout(mContext, new String(),
spenViewLayout);
if (mPenSettingView == null) {
Toast.makeText(mContext, "Cannot create new PenSettingView.",
Toast.LENGTH_SHORT).show();
finish();
}
// EraserSettingView
mEraserSettingView =
new SpenSettingEraserLayout(mContext, new String(),
spenViewLayout);
if (mEraserSettingView == null) {
Toast.makeText(mContext, "Cannot create new EraserSettingView.",
Toast.LENGTH_SHORT).show();
finish();
}
// TextSettingView
mTextSettingView = new SpenSettingTextLayout(mContext, new String(), new HashMap<String, String>(), spenViewLayout);
if (mTextSettingView == null) {
Toast.makeText(mContext, "Cannot craeate new TextSettingView.", Toast.LENGTH_SHORT).show();
finish();
}
spenViewContainer.addView(mPenSettingView);
spenViewContainer.addView(mEraserSettingView);
spenViewContainer.addView(mTextSettingView);
// SpenSurfaceView
mSpenSurfaceView = new SpenSurfaceView(mContext);
if (mSpenSurfaceView == null) {
Toast.makeText(mContext, "Cannot create new SpenSurfaceView.",
Toast.LENGTH_SHORT).show();
finish();
}
spenViewLayout.addView(mSpenSurfaceView);
mPenSettingView.setCanvasView(mSpenSurfaceView);
mEraserSettingView.setCanvasView(mSpenSurfaceView);
mTextSettingView.setCanvasView(mSpenSurfaceView);
//
Display display = getWindowManager().getDefaultDisplay();
mScreenRect = new Rect();
display.getRectSize(mScreenRect);
// SpenNoteDoc
try {
mSpenNoteDoc =
new SpenNoteDoc(mContext, mScreenRect.width(), mScreenRect.height());
} catch (IOException e) {
Toast.makeText(mContext, "Cannot create new NoteDoc",
Toast.LENGTH_SHORT).show();
e.printStackTrace();
finish();
} catch (Exception e) {
e.printStackTrace();
finish();
}
// NoteDoc
mSpenPageDoc = mSpenNoteDoc.appendPage();
mSpenPageDoc.setBackgroundColor(0xFFD6E6F5);
mSpenPageDoc.clearHistory();
// PageDoc
mSpenSurfaceView.setPageDoc(mSpenPageDoc, true);
initSettingInfo();
// Listener
mSpenSurfaceView.setTouchListener(mPenTouchListener);
mSpenSurfaceView.setColorPickerListener(mColorPickerListener);
mSpenSurfaceView.setTextChangeListener(mTextChangeListener);
mSpenSurfaceView.setReplayListener(mReplayListener);
mSpenPageDoc.setHistoryListener(mHistoryListener);
mEraserSettingView.setEraserListener(mEraserListener);
mSpenSurfaceView.setFlickListener(mFlickListener);
// Button
mTextObjBtn = (ImageView) findViewById(R.id.textObjBtn);
mTextObjBtn.setOnClickListener(mTextObjBtnClickListener);
mPenBtn = (ImageView) findViewById(R.id.penBtn);
mPenBtn.setOnClickListener(mPenBtnClickListener);
mEraserBtn = (ImageView) findViewById(R.id.eraserBtn);
mEraserBtn.setOnClickListener(mEraserBtnClickListener);
mUndoBtn = (ImageView) findViewById(R.id.undoBtn);
mUndoBtn.setOnClickListener(undoNredoBtnClickListener);
mUndoBtn.setEnabled(mSpenPageDoc.isUndoable());
mRedoBtn = (ImageView) findViewById(R.id.redoBtn);
mRedoBtn.setOnClickListener(undoNredoBtnClickListener);
mRedoBtn.setEnabled(mSpenPageDoc.isRedoable());
mImgObjBtn = (ImageView) findViewById(R.id.imgObjBtn);
mImgObjBtn.setOnClickListener(mImgObjBtnClickListener);
mAddPageBtn = (ImageView) findViewById(R.id.addPageBtn);
mAddPageBtn.setOnClickListener(mAddPageBtnClickListener);
mTxtView = (TextView) findViewById(R.id.spen_page);
mTxtView.setText("Page" + mSpenNoteDoc.getPageIndexById(mSpenPageDoc.getId()));
selectButton(mPenBtn);
String filePath = inputGfd.getFileDirectory();
mFilePath = new File(filePath);
if (!mFilePath.exists()) {
if (!mFilePath.mkdirs()) {
Toast.makeText(mContext, "Save Path Creation Error", Toast.LENGTH_SHORT).show();
return;
}
}
mSpenPageDoc.startRecord();
File loadFile = new File(inputGfd.getFileDirectory(), inputGfd.getFileName());
if (loadFile.exists()) {
loadNoteFile();
} else {
Log.w(TAG, "File does not exist!");
}
if(isSpenFeatureEnabled == false) {
mToolType = SpenSurfaceView.TOOL_FINGER;
mSpenSurfaceView.setToolTypeAction(mToolType,
SpenSurfaceView.ACTION_STROKE);
Toast.makeText(mContext,
"Device does not support Spen. \n You can draw stroke by finger",
Toast.LENGTH_SHORT).show();
}
}
One of the returns for the activity
private boolean saveNoteFile(final boolean isClose) {
// file save
// note file
String saveFilePath = inputGfd.getFileDirectory() + File.separator;
String fileName = inputGfd.getFileName();
if (!fileName.equals("")) {
saveFilePath += fileName;
saveNoteFile(saveFilePath);
if (isClose)
finish();
} else {
Toast
.makeText(mContext, "Invalid filename !!!", Toast.LENGTH_LONG)
.show();
}
return true;
}
and finally the destroy routine,
#Override
protected void onDestroy() {
Log.d(TAG, "NotePad onDestroy()");
super.onDestroy();
if (mSpenNoteDoc != null && mSpenPageDoc.isRecording()) {
mSpenPageDoc.stopRecord();
}
if (mPenSettingView != null) {
mPenSettingView.close();
}
if (mEraserSettingView != null) {
mEraserSettingView.close();
}
if (mTextSettingView != null) {
mTextSettingView.close();
}
if(mSpenSurfaceView != null) {
if (mSpenSurfaceView.getReplayState() == SpenSurfaceView.REPLAY_STATE_PLAYING) {
mSpenSurfaceView.stopReplay();
}
mSpenSurfaceView.closeControl();
mSpenSurfaceView.close();
mSpenSurfaceView = null;
}
if(mSpenNoteDoc != null) {
try {
if (isDiscard)
mSpenNoteDoc.discard();
else
mSpenNoteDoc.close();
} catch (Exception e) {
e.printStackTrace();
}
mSpenNoteDoc = null;
}
};
Thanks!
This is likely a bug in Google Maps Android API v2 itself.
I encounter it in my app. When you open "Declusterification" demo, click on yellow marker with 10 in the center and a new marker (red default) appears in the same spot, this new marker cannot be interacted with to show info window without moving the map.
If you happen to figure out SSCCE for it, I suggest posting it on gmaps-api-issues. I'll support it. If I do find simple example to show this issue, I'll also post an update here.
To close up this question.
GoogleMap markers exhibit the anomalies mentioned in this thread and currently the issue has been fed back to Google. There are two apparent "workarounds" to the problem but how effective they are is not clear:
1st workaround : work within the limitations of .clear(). An activated marker cannot be deactivated with .clear().
2nd workaround : after returning from the activity, perform a camera update. This apparently resets the activation of the marker.
i am using check box for saving data in database .if it is checked then app redirecting to other screen by saving data after that if i click on device back button then app showing it is not checked.how can i fix this issue?
here i am placing code
public void joinLisn(){
String shareProfileType2=Constants.PROFILE_SHARE_ALL;
String accessToken = null;
DatabaseHelper helper = new DatabaseHelper(getApplicationContext());
DatabaseUtility dao = new DatabaseUtility(helper);
try {
accessToken = dao.getAccessToken();
} catch (Exception e1) {
handler.sendEmptyMessage(1);
return;
}
if(accessToken == null || accessToken.length() == 0){
handler.sendEmptyMessage(1);
return;
}
Map<String , String> params = new HashMap<String,String>();
params.put(Constants.ACCESS_TOKEN_PARAM, accessToken);
params.put(Constants.LISN_ID_PARAM, id);
params.put(Constants.PROFILE_TYPE_PARAM,shareProfileType2);
Status status = null;
try {
status = Utils.joinLisn(params, this);
} catch (NullPointerException e) {
handler.sendEmptyMessage(12);
return;
} catch (JSONException e) {
handler.sendEmptyMessage(11);
return;
}
if(status == null){
handler.sendEmptyMessage(1);
} else if(status.getStatus().equalsIgnoreCase(Constants.SUCCESS)){
try {
Intent lisnDetailIntent = new Intent(this, LisnDetailTabView.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bundle bundleObj = new Bundle();
bundleObj.putString("id", id);
bundleObj.putString("RSVP","In");
lisnDetailIntent.putExtras(bundleObj);
startActivityForResult(lisnDetailIntent,0);
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
handler.sendEmptyMessage(8);
} catch(Exception ex) {}
} else{
handler.sendEmptyMessage(2);
return;
}
}
Override the onbackpressed to trigger your function to save the states.
public void onBackPressed() {
//Do your db saving here
super.onBackPressed();
}
If your app is redirecting to other app, your app will be put to background. Make use of onSaveInstanceState and onRestoreInstanceState to save and restore the checkbox state.
I'm trying to check if the user has enabled/disabled data roaming. All I found so far is that you can check whether or not the user is currently IN roaming, using TelephonyManager.isNetworkRoaming() and NetworkInfo.isRoaming(), but they are not what I need.
Based on Nippey's answer, the actual piece of code that worked for me is:
public Boolean isDataRoamingEnabled(Context context) {
try {
// return true or false if data roaming is enabled or not
return Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.DATA_ROAMING) == 1;
}
catch (SettingNotFoundException e) {
// return null if no such settings exist (device with no radio data ?)
return null;
}
}
You can request the state of the Roaming-Switch via
ContentResolver cr = ContentResolver(getCurrentContext());
Settings.Secure.getInt(cr, Settings.Secure.DATA_ROAMING);
See: http://developer.android.com/reference/android/provider/Settings.Secure.html#DATA_ROAMING
public static final Boolean isDataRoamingEnabled(final Context application_context)
{
try
{
if (VERSION.SDK_INT < 17)
{
return (Settings.System.getInt(application_context.getContentResolver(), Settings.Secure.DATA_ROAMING, 0) == 1);
}
return (Settings.Global.getInt(application_context.getContentResolver(), Settings.Global.DATA_ROAMING, 0) == 1);
}
catch (Exception exception)
{
return false;
}
}
Updated function to account for API deprecation. It is now replaced with:
http://developer.android.com/reference/android/provider/Settings.Global.html#DATA_ROAMING
public static boolean IsDataRoamingEnabled(Context context) {
try {
// return true or false if data roaming is enabled or not
return Settings.Global.getInt(context.getContentResolver(), Settings.Global.DATA_ROAMING) == 1;
}
catch (SettingNotFoundException e) {
return false;
}
}