I have the following layout (virtually empty):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/set_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="content desc"
android:orientation="vertical" >
<TextView android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a TextView" />
</LinearLayout>
The Activity class contains the following:
public class TestActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
}
}
When I run this on my mobile device I get the following error:
SpannableStringBuilder
SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
I have tried this with and without the TextView and the error still remains, I must be doing something fundamentally wrong for such a basic layout to cause this.
Does anyone have any ideas on how I can get this to load without the error?
I have run into the same error entries in LogCat. In my case it's caused by the 3rd party keyboard I am using. When I change it back to Android keyboard, the error entry does not show up any more.
Because the error you're getting is not related to an EditText, then it's not related to your keyboard.
The errors you are getting are not a result of your code; you probably are testing on a Samsung device that has Samsung's TouchWiz.
I had the same errors, then I tested on a Nexus S (also by Samsung, but pure Android OS without TouchWiz) and I didn't get this error.
So, in your case, just ignore these errors while testing on a device! :)
Looking at your code, I'm not sure why you're getting that error, but I had this same error but with EditText fields.
Changing android:inputType="text" (or any of the other inputType text variations) to android:inputType="textNoSuggestions" (or android:inputType="textEmailAddress|textNoSuggestions", for example) fixed it for me.
You can also set this in Code with something like
mInputField.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
Looks like Android assumes by default that EditText fields will have suggestions. When they don't, it errors. Not 100% confident in that explanation, but the above mentioned changes fixed it for me.
http://developer.android.com/reference/android/text/Spanned.html#SPAN_EXCLUSIVE_EXCLUSIVE
Hope this helps!
On your android phone go to:
settings -> application manager -> all -> samsung keyboard and then click on "clear cache"
(delete all data collected by this application).
Try using the default Android keyboard it will disappear
Make clear you have pass a value in your MainAcitivity for the following methods onCreateOptionsMenu and onCreate
In some cases, the developer deletes the "return super.onCreateOptionsMenu(menu)" statement and changed to "return true".
This worked for me...on every device
<EditText
android:maxLines="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="15sp"
android:layout_centerVertical="true"
android:textColor="#000"
android:id="#+id/input_search"
android:background="#null"
android:inputType="text"
android:hint="Enter Address, City or Zip Code"
android:imeOptions="actionSearch"
/>
In Java code:
mSearchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
if(actionId == EditorInfo.IME_ACTION_SEARCH
|| actionId == EditorInfo.IME_ACTION_DONE
|| keyEvent.getAction() == KeyEvent.ACTION_DOWN
|| keyEvent.getAction() == KeyEvent.KEYCODE_ENTER){
//execute our method for searching
}
return false;
}
});
I had the same warning and found that removing an unused #id got rid of the warning. For me it was obvious as the #id was associated with a growing list of textViews linked to a database, so there was a warning for each entry.
Masood Moshref is right, this error occur because the option menu of Menu is not well prepared by lacking "return super.onCreateOptionsMenu(menu)" in onCreate() method.
To try to debug this error, first go to your android terminal / console and execute this command:
ps | grep THE_ERROR_PID_YOU_GET_(IT_IS_A_NUMBER)
then if the output comes out as your app... it is your app causing the error. Try to look for empty Strings that you pass into the layout.
I had this exact same problem and it was my fault as I was passing an empty String into my layout. After changing the "" to " " this error went away.
If you don't get your app from the console output, then it is something else causing it (probably, as others said, the android keyboard)
I have faced the same issue. I almost wasted almost couple of weeks to resolved this issue.
Finally I had on doubt on myself and tried to create another project by copy and paste some startup files like SplashScreen & LoginScreen.
But with the same code still i was getting SPAN_EXCLUSIVE_EXCLUSIVE.
Then i have removed the handler code from splash screen and tried again and Wow its working.
I am not getting SPAN_EXCLUSIVE_EXCLUSIVE issue in logcat.
I wondering, why it is? till the time did not get any other solution but by removing handler from splash screen it is working.
Try and update here if it is resolved or not.
Check if you have any element such as button or text view duplicated (copied twice) in the screen where this encounters. I did this unnoticed and had to face the same issue.
I ran into this problem too when I copied some text from the Internet. My solution is to trim the text/remove formatting before doing any further processing.
I had the same problem but with a listView.... i solved it because i was using a wrong R.id.listView that list View needed to have a value, in my case it was strings that i saved on listView2... so the right code was R.id.listView2
I had the same problem then i fixed it by following code!
text = (EditText)findViewById(R.id.TextVoiceeditText);
text.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
this error also occurs due to changed API URL. try hitting the URL you are using in postman and c if it's working properly.
rechecking the APIs solved my problem
try avoiding use of view in xml design.I too had the same probem but when I removed the view. its worked perfectly.
like example:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:inputType="number"
android:textColor="#fff" />
<view
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#f9d7db" />
also check and try changing by trial and error android:inputType="number" to android:inputType="text" or better not using it if not required .Sometimes keyboard stuck and gets error in some of the devices.
In my case, the EditText fields with inputType as text / textCapCharacters were casing this error. I noticed this in my logcat whenever I used backspace to completely remove the text typed in any of these fields.
The solution which worked for me was to change the inputType of those fields to textNoSuggestions as this was the most suited type and didn't give me any unwanted errors anymore.
in my case i click on recent apps shortcut on my cell phone and close all apps. This solution always work for me, because this error not related to code.
**DONT PUT SET TEXT IN TEXT WATCHER**etSearch.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable) {
visibleResultList = false
if (s.toString().length != 0) {
getSearchSuggetion(no_of_rec, 0, s.toString())
} else {
// etSearch.setText("")
}
Log.e("text_change","============"+s.toString())
}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
}
})
To solve this problem just add android:usesCleartextTraffic="true" in your AndroidManifest.xml file which is at ..\app\src\main\AndroidManifest.xml just like bellow...
Related
I'm trying to get a UDP stream from a GoPro camera.
https://github.com/KonradIT/GoProStream
I'm redoing this python code in android studio using vitamio.
But for some reason, as soon as I set the path, it crashes
_myVideoView.setVideoPath("udp://#10.5.5.100:8554");
But if I remove it, the app can launch but of course there is no video.
If someone encountered the same issue and found a solution, that would help me.
_myVideoView.setVideoPath("udp://#10.5.5.100:8554");
_myVideoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);
_myVideoView.setBufferSize(2048);
_myVideoView.requestFocus();
_myVideoView.setMediaController(new MediaController(this));
_myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayer) {
// optional need Vitamio 4.0
mediaPlayer.setPlaybackSpeed(1.0f);
}
});
_myVideoView.start();
I have done that for onCreate :
if(!io.vov.vitamio.LibsChecker.checkVitamioLibs(this)){
return;
}
Vitamio.initialize(this);
the videoview :
<io.vov.vitamio.widget.VideoView
android:id="#+id/VideoView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="50dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="50dp"
android:layout_marginBottom="50dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imageButtonLeft"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/WebView"
tools:visibility="visible" />
and the build graddle :
implementation project(path: ':vitamio')
ps : I've tried to put the compile line in graddle, but it can't find the method compile and the implement line seem to work just fine.
ps2 : I just tried but even http link from YouTube doesn't work, I've definitely made a mistake but dunno where
Found the solution...
I was just importing the project but I didn't build it beforehand
So there was no way it could work.
But I gave up later for other reasons and I would recommend lib vlc instead of vitamio for displaying video from udp streams.
GOAL: Use EditTextPreference to take a number input from an user.
PROBLEM: I'm using support.v7.preference and, from what I've understood, this library bring problems to creates a custom DialogPreference (HowTo use support.v7.preference with AppCompat and potential drawbacks). Anyway I tried to create a NumberPickerPreference extending DialogPreference but I got ClassCastException.
Also I found another approach: programmatically set the input type of an EditTextPreference object like below:
EditTextPreference pref = (EditTextPreference) findPreference("pref_edit_text");
if (pref != null) {
pref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
}
No way, I always get a ClassCastException .
Last approach I tried : modify the xml
android:inputType="numberDecimal"
android:digits="0123456789"
or android:numeric="integer"
No way again, on the Dialog I get the full keyboard, so the user can write everything.
Is there a way to properly enforce EditTextReference to take just number input?
You can do it by adding android: inputType = "numberPassword" to your XML file
Then you can set your custom keyboard programmatically in your java like this:
yourEditText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
The next thing you could do is to create a custom class:
private class YourNumericKeyboardMethod extends PasswordTransformationMethod {
#Override
public CharSequence getTransformation(CharSequence source, View view) {
return source;
}
}
The last step is to implement it to your EditText in order to make it display only the numbers:
yourEditText.setTransformationMethod(new YourNumericKeyboardMethod());
After all this steps you should get a keyboard that has only numbers from 0 to 9 on it
Try one of these:
android:inputType="numberSigned"
android:inputType="phone"
EDIT:
android:inputType="numberDecimal|numberSigned"
android:digits="0123456789"
EDIT:
There´s this lib that is supposed to make it work, if you´re willing to try:
https://github.com/Gericop/Android-Support-Preference-V7-Fix
Reading their github page you can find examples of custom inputs and their example code that looks similar to what you are doing now:
"The sample app shows an example of setting (via XML) and querying (programmatically) the input type of the EditTextPreference:
<EditTextPreference
android:inputType="phone"
android:key="edit_text_test" />
EditTextPreference etPref = (EditTextPreference) findPreference("edit_text_test");
if (etPref != null) {
int inputType = etPref.getEditText().getInputType();
// do something with inputType
}
Try to set inputType as the number.
android:inputType="number"
I have written an application for Android that has an issue (crash) when it is launched immediately (with in 5 seconds or so) after the phone is rebooted. Due to one reason or another, the OnCreate method is called for a second time. I thought this may have been the problem, but after researching this, I found out the android system may recall onCreate after start up as it is still starting system services - such as getting the "MCM".
In my application in the MainActivity I have a statically bound fragment that is bound through XML. The fragment has code in it that checks that location permissions were granted:
if (ActivityCompat.checkSelfPermission(this.getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this.getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
The problem is, this.getContext() returns null! It definitely has something to do with the fact onCreate is being called more than once, because when the phone is not booting and onCreate is only called once the application works perfectly!
Here is the only reference I make to the fragment in my onCreate method in the mainActivity:
android.support.v4.app.Fragment fragMap = getSupportFragmentManager().findFragmentById(R.id.mv_1);
if (fragMap instanceof FragmentMap)
{
theMap = (FragmentMap) fragMap;
}
Here is the fragment bound through XML:
<fragment
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/mv_1"
android:name="com.sunhillo.personneltrackerv002.FragmentMap"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="64dp"/>
Thank you very much for any help you can provide! I am still new to Android programming, and am attempting to learn the ins and outs!
If your ultimate aim is to access the location permissions, simply add these permissions in manifest file. And if you wish to perform this check via java, don't add this to individual fragments. Add this syntax only to the MainActivity java file that refers to the fragments. I hope this helps. :)
You should use launch mode Single Task or Single top which will avoid calling multiple onCreate and you should use getApplicationContext().
I have a Android Webview and when I click on a link to download a file (image of pdf etc) I got a error message.
Error message:
Cannot call determinedVisibility() - never saw a connection for the pid
Any idea what I do wrong? Who can help please!?
Just a bit of configuration:
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
I got the same error and Burhans solution was not helping me.
I think things went wrong when you´re trying to load different urls too fast.
Edit: Found a better solution credits go to user2652394
WebView must be loaded twice to load correctly
You have to do something like this:
webView.postDelayed(new Runnable() {
#Override
public void run() {
webView.loadUrl(landingpage);
}
}, 500);
I faced the same issue.
Was solved by giving a WebView a static height (ie 300dp) or specifying minHeight value.
This problem in my case produce by incorrect settings in layout properties. I had used:
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/webView"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="false"
android:layout_alignWithParentIfMissing="false" />
Instead of setting:
<WebView
android:id="#+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/textView" />
The problems had been solved, when I removed "layout_alignParent" settings.
Background
Here is the source code of the method in the browser engine that gives the error (BindingManagerImpl.java), from Chromium source:
#Override
public void determinedVisibility(int pid) {
ManagedConnection managedConnection;
synchronized (mManagedConnections) {
managedConnection = mManagedConnections.get(pid);
}
if (managedConnection == null) {
Log.w(TAG, "Cannot call determinedVisibility() - never saw a connection for the pid: "
+ "%d", pid);
return;
}
Analysis
It's a rendering warning from content.
Consecutive calls to loadUrl cause a race condition. The problem is that loadUrl("file://..") doesn't complete immediately, and so when you call loadUrl("javascript:..") it will sometimes execute before
the page has loaded.
Detail
For more detail see this stackoverflow answer.
This is how I fixed a similar issue:
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view,String url) {
return false;
}
});
mWebView.loadURL(...
Late to party, but might help some.
May sound silly as hell, but the mistake I made was not adding http:// in the beginning of the URL.
Check whether internet permission is properly set on the Manifest file. Make sure that the permission tag should be outside of your Application tag.
<uses-permission android:name="android.permission.INTERNET" />
Hope this might help some one.
I found a workaround by using onPageFinished method instead of shouldOverrideUrlLoading. It also provides the needed URL in the list of arguments.
The only trick is to set a check so that the main logic of the method (in my case making a Toast) is not triggered when onPageFinished gets called on the the page load itself.
mWebView.setDownloadListener(new DownloadListener() {
#Override
public void onDownloadStart(String url, String userAgent, String contentDisposition,
String mimetype, long contentLength) {
Log.d("download",url);
}
});
I faced the same problem. I can fix my issue by giving this code:
webView.postDelayed(new Runnable() {
#Override
public void run() {
webView.loadUrl(url);
}
}, 500);
instead of:
webview.loadUrl(url);
then, set the url starts with https://
There are lots of Resources$NotFoundException questions on Stack Overflow and I've reviewed them and tried the various suggestions to no avail.
I had a perfectly working layout to display some graphics with some buttons underneath and I modified some of the buttons and started to get this error. I couldn't see anything wrong with my changes but just to narrow it down I deleted ALL the buttons, so now I just have a LinearLayout with an ImageView and I'm still getting the error. My Java:
try {
setContentView(R.layout.graphics);
}
catch (Exception e) {
Log.d("DGraphActivity", "setContentView crash");
}
My 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="horizontal">
<ImageView
android:id="#+id/image2"
android:layout_width="0px"
android:layout_weight="2"
android:layout_height="match_parent"
android:scaleType="fitCenter">
</ImageView>
</LinearLayout>
The error says android.content.res.Resources$NotFoundException: Resource ID #0x7f030005.
In the R.java file that resource is identified with the graphics . . .
public static final class layout {
public static final int addcomment=0x7f030000;
public static final int areyousure=0x7f030001;
public static final int downarrow=0x7f030002;
public static final int downleftarrow=0x7f030003;
public static final int downrightarrow=0x7f030004;
public static final int graphics=0x7f030005;
public static final int infofromoperator=0x7f030006;
I deleted the gen folder and did a clean the project with no improvement. I also rebooted my PC and did an explicit close of the project. There's nothing obviously wrong with the graphics.xml file - it exists in the same folder with all my other XML files; it's not write-protected or hidden. Eclipse doesn't flag any errors or warnings for it.
Thanks in advance.
I got the answer to this on the android-developers Google groups, where I also posted this question. The insightful programmer was "Bob Smith", just to give credit credit where it's due.
My bug was that the resource it was seeking was not in the correct res folder. My app runs in landscape mode on a tablet. In the manifest everything is constrained to run that way (in fact in the code it's constrained to run on one particular tablet that the company ships with their product). All the resource and layout files live in layout-land. Bob didn't know any of this but he asked the key question: were my resource files really in the right res folder?
You can do : Project > Clean and REFRESH