code :
public void extractPhoneNumber(String input){
Iterator<PhoneNumberMatch> existsPhone= PhoneNumberUtil.getInstance().findNumbers(input, "IN").iterator();
while (existsPhone.hasNext()){
System.out.println("Phone == " + existsPhone.next().number());
Log.d("existsPhone",":"+existsPhone.next().rawString());
gotPhone.setText(existsPhone.next().rawString());
}
}
Log :
2019-06-11 16:23:43.059 11176-11176/com.example.cardscaning E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.cardscaning, PID: 11176
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cardscaning/com.example.cardscaning.Activity.ProcessImage}: java.util.NoSuchElementException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2678)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2743)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1490)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6165)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
Caused by: java.util.NoSuchElementException
at com.google.i18n.phonenumbers.PhoneNumberMatcher.next(PhoneNumberMatcher.java:710)
at com.google.i18n.phonenumbers.PhoneNumberMatcher.next(PhoneNumberMatcher.java:43)
at com.example.cardscaning.Activity.ProcessImage.extractPhoneNumber(ProcessImage.java:291)
at com.example.cardscaning.Activity.ProcessImage.onCreate(ProcessImage.java:97)
at android.app.Activity.performCreate(Activity.java:6687)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2631)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2743)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1490)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6165)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
Inside log I can get desire result but exception occurs when I am adding this line gotPhone.setText(existsPhone.next().rawString())
Desirable outcome is able use extracted number.
You are calling next() thrice in one iteration forcing the Iterator to move to an element that doesn't exist.
Instead of:
while (existsPhone.hasNext()){
System.out.println("Phone == " + existsPhone.next().number());
Log.d("existsPhone",":"+existsPhone.next().rawString());
//...
}
Use something like:
while (existsPhone.hasNext()){
PhoneNumberMatch phone = existsPhone.next();
System.out.println("Phone == " + phone.number());
Log.d("existsPhone",":"+phone.rawString());
//....
}
I have a Xamarin android project and am currently using Visual Studio 2015.
Inside of my MainActivity.cs, I have the following code:
Com.Alk.Sdk.SharedLibraryLoader.LoadLibrary("alksdk", this);
which then goes into:
// Metadata.xml XPath method reference: path="/api/package[#name='com.alk.sdk']/class[#name='SharedLibraryLoader']/method[#name='loadLibrary' and count(parameter)=2 and parameter[1][#type='java.lang.String'] and parameter[2][#type='android.content.Context']]"
[Register ("loadLibrary", "(Ljava/lang/String;Landroid/content/Context;)Z", "")]
public static unsafe bool LoadLibrary (string p0, global::Android.Content.Context p1)
{
if (id_loadLibrary_Ljava_lang_String_Landroid_content_Context_ == IntPtr.Zero)
id_loadLibrary_Ljava_lang_String_Landroid_content_Context_ = JNIEnv.GetStaticMethodID (class_ref, "loadLibrary", "(Ljava/lang/String;Landroid/content/Context;)Z");
IntPtr native_p0 = JNIEnv.NewString (p0);
try {
JValue* __args = stackalloc JValue [2];
__args [0] = new JValue (native_p0);
__args [1] = new JValue (p1);
bool __ret = JNIEnv.CallStaticBooleanMethod (class_ref, id_loadLibrary_Ljava_lang_String_Landroid_content_Context_, __args);
return __ret;
} finally {
JNIEnv.DeleteLocalRef (native_p0);
}
}
The problem I am having is that when it calls the JNIEnv.CallStaticBooleanMethod, it throws this exception:
[ERROR] FATAL UNHANDLED EXCEPTION: Java.Lang.UnsatisfiedLinkError: dlopen failed: "/data/data/com.pai.rp/app_lib/libalksdk.so" has unexpected e_machine: 3
--- End of managed Java.Lang.UnsatisfiedLinkError stack trace ---
java.lang.UnsatisfiedLinkError: dlopen failed: "/data/data/com.pai.rp/app_lib/libalksdk.so" has unexpected e_machine: 3
at java.lang.Runtime.load0(Runtime.java:908)
at java.lang.System.load(System.java:1542)
at com.alk.sdk.SharedLibraryLoader.loadLibrary(SharedLibraryLoader.java:44)
at com.pai.rp.MainActivity.n_onCreate(Native Method)
at com.pai.rp.MainActivity.onCreate(MainActivity.java:30)
at android.app.Activity.performCreate(Activity.java:6973)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3064)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1659)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6823)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1557)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
From what I've been able to research I've found that
e_machine: 3 indicates the expected arch is Intel 80386 (ELF Headers).
When using a Google Nexus 10 emulator it seems to work, however when
I use the Galaxy Tab E (ARM) through USB debugging, it crashes and gives me
this error.
So the question is, how do I correct this?
Sometimes on my android live wallpaper I get this exception on RESIZE: IllegalArgumentException: Bad position 8/0
latest libgdx
java.lang.IllegalArgumentException: Bad position 8/0
at java.nio.Buffer.position(Buffer.java:249)
at com.badlogic.gdx.graphics.glutils.VertexArray.bind(VertexArray.java:118)
at com.badlogic.gdx.graphics.Mesh.bind(Mesh.java:391)
at com.badlogic.gdx.graphics.Mesh.bind(Mesh.java:382)
at com.badlogic.gdx.graphics.Mesh.render(Mesh.java:490)
at com.badlogic.gdx.graphics.Mesh.render(Mesh.java:460)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.flush(SpriteBatch.java:977)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.setProjectionMatrix(SpriteBatch.java:1049)
at hu.lacas.newalienlwp.Renderer.resizeBatch(Renderer.kt:844)
at hu.lacas.newalienlwp.Renderer.access$resizeBatch(Renderer.kt:44)
at hu.lacas.newalienlwp.Renderer$resize$1.run(Renderer.kt:828)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
The source code
#override fun resize(width: Int, height: Int) {
camera.viewportHeight = Gdx.graphics.height.toFloat()
camera.viewportWidth = Gdx.graphics.width.toFloat()
mOrientation = if (camera.viewportHeight < camera.viewportWidth) LiveWallpaper.ORIENTATION_LANDSCAPE else LiveWallpaper.ORIENTATION_PORTRAIT
camera.fieldOfView = (if (mOrientation != LiveWallpaper.ORIENTATION_LANDSCAPE) 27 else 20).toFloat()
camera.update()
handler.postDelayed({
resizeBatch()
}, 900)
}
private fun resizeBatch() {
val viewportWidth = Gdx.graphics.width
val viewportHeight = Gdx.graphics.height
if (camera2D == null) camera2D = OrthographicCamera()
camera2D?.setToOrtho(false, viewportWidth.toFloat(), viewportHeight.toFloat())
camera2D?.update()
spriteBatch!!.projectionMatrix = camera2D?.combined
Objects.textureRegionScanlineFullScreen.setRegion(0, 0, Gdx.graphics.width, Gdx.graphics.height)
}
it looks like the problem is here:
--> spriteBatch!!.projectionMatrix = camera2D?.combined
This exception is just comes up sometimes... So not really understand what is going on. I created that handler with 900ms because when this is not there the exception is shown more.. Whats is going on?
Libgdx not loaded the matrix yet?
I need your help here.
I'm trying to implement simple blending of two images using OpenCV's seamlessClone() function. I'm getting an exception which says:
error: (-215) CV_MAT_TYPE(mtype) == m.type()
Here is the source code for it:
public class SeamlessClone extends AppCompatActivity {
public static final String TAG = "Seamless Clone demo";
static {
if (!OpenCVLoader.initDebug()) {
// Handle initialization error
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_seamless_clone);
Bitmap destinationBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.lightning);
Log.d(TAG, "bitmap: " + destinationBitmap.getWidth() + "x" + destinationBitmap.getHeight());
Mat destination = new Mat(destinationBitmap.getHeight(),
destinationBitmap.getWidth(), CvType.CV_8UC4);
Utils.bitmapToMat(destinationBitmap, destination);
Bitmap sourceBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.airplane);
Log.d(TAG, "bitmap: " + sourceBitmap.getWidth() + "x" + sourceBitmap.getHeight());
Mat source = new Mat(sourceBitmap.getHeight(),
sourceBitmap.getWidth(), CvType.CV_8UC4);
Utils.bitmapToMat(sourceBitmap, source);
Mat mask = new Mat(source.rows(),source.cols(),source.depth(),Scalar.all(255));
Point point = new Point(destination.cols()/2,destination.rows()/2);
Mat result = new Mat(destinationBitmap.getHeight(),
destinationBitmap.getWidth(), CvType.CV_8UC4);
Photo.seamlessClone(source, destination, mask, point, result, Photo.NORMAL_CLONE);
Utils.matToBitmap(result, destinationBitmap);
ImageView imageView = (ImageView) findViewById(R.id.clone_result);
imageView.setImageBitmap(destinationBitmap);
}
}
And following is the error log from the logcat:
E/OpenCV/StaticHelper: OpenCV error: Cannot load info library for OpenCV
E/cv::error(): OpenCV Error: Assertion failed (CV_MAT_TYPE(mtype) == m.type()) in void cv::_OutputArray::create(int, const int*, int, int, bool, int) const, file /Volumes/Linux/builds/master_pack-android/opencv/modules/core/src/matrix.cpp, line 2297
E/org.opencv.photo: photo::seamlessClone_10() caught cv::Exception: /Volumes/Linux/builds/master_pack-android/opencv/modules/core/src/matrix.cpp:2297: error: (-215) CV_MAT_TYPE(mtype) == m.type() in function void cv::_OutputArray::create(int, const int*, int, int, bool, int) const
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.hemisphere.opencvexample, PID: 1905
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hemisphere.opencvexample/com.example.hemisphere.opencvexample.SeamlessClone}:
CvException [org.opencv.core.CvException: cv::Exception: /Volumes/Linux/builds/master_pack-android/opencv/modules/core/src/matrix.cpp:2297: error: (-215) CV_MAT_TYPE(mtype) == m.type() in function void cv::_OutputArray::create(int, const int*, int, int, bool, int) const
]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
at android.app.ActivityThread.access$800(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
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:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: CvException [org.opencv.core.CvException: cv::Exception: /Volumes/Linux/builds/master_pack-android/opencv/modules/core/src/matrix.cpp:2297: error: (-215) CV_MAT_TYPE(mtype) == m.type() in function void cv::_OutputArray::create(int, const int*, int, int, bool, int) const
]
at org.opencv.photo.Photo.seamlessClone_0(Native Method)
at org.opencv.photo.Photo.seamlessClone(Photo.java:581)
at com.example.hemisphere.opencvexample.SeamlessClone.onCreate(SeamlessClone.java:72)
at android.app.Activity.performCreate(Activity.java:6010)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
... 10 more
Am I doing something wrong in the code?
Thanks in Advance!
I had the same error using OpenCV with Objective-C++.
I was opening my source, destination and mask images as PNG. You need to get ride of the Alpha setting.
To do so, convert your images with OpenCV cvtColor function (CV_RGBA2RGB code) before trying to perform the clone function.
Maybe this is your problem too?
Please try to run in with 3 channels (CvType.CV_8UC3) instead of 4, hope fully it will works.
The error is:
Unable to resume activity: java.lang.NullPointerException
Here is the stack trace:
0 java.lang.RuntimeException: Unable to resume activity {com.sortitapps.movies/com.sortitapps.movies.SettingsActivity}: java.lang.NullPointerException
1 at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2944)
2 at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2973)
3 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2408)
4 at android.app.ActivityThread.access$600(ActivityThread.java:165)
5 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
6 at android.os.Handler.dispatchMessage(Handler.java:107)
7 at android.os.Looper.loop(Looper.java:194)
8 at android.app.ActivityThread.main(ActivityThread.java:5391)
9 at java.lang.reflect.Method.invokeNative(Native Method)
10 at java.lang.reflect.Method.invoke(Method.java:525)
11 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
12 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
13 at dalvik.system.NativeStart.main(Native Method)
14 Caused by: java.lang.NullPointerException
15 at com.sortitapps.movies.SettingsActivity.onResume(SettingsActivity.java:149)
16 at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1259)
17 at android.app.Activity.performResume(Activity.java:5200)
18 at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2931)
And here is the code. Line 149 is adapter.notifyDataSetChanged();:
#Override
public void onResume()
{
super.onResume(); // Always call the superclass method first
SharedPreferences settings = getSharedPreferences("prefs", 0);
int numberDesktop = settings.getInt("desktop", 0);
Log.i("Desktop purchased:", String.valueOf(numberDesktop));
int numberScans = settings.getInt("scanning", 0);
Log.i("Number of scans:", String.valueOf(numberScans));
if (settingsitems.contains("Unlock Desktop Apps") &&
numberDesktop == 2)
{
settingsitems.remove("Unlock Desktop Apps");
}
String freeapp = getResources().getString(R.string.free_app);
if (settingsitems.contains("Unlock Premium Features") &&
freeapp.equals("Yes") &&
numberScans > 10)
{
settingsitems.remove("Unlock Premium Features");
}
adapter.notifyDataSetChanged();
}
Do I need to initialize the adapter again when coming resuming?
Most certainly adapter is null.
Your code doesn't show how the adapter got initialized, so it could be that it wasn't initialized with a value, or it was set to null after that.