Android Logcat strange errors - android-studio

I am new to Android app developing. While running my app on Genymotion (I have tried with multiple devices), the gradle builds without error, but the emulator says "Unfortunately, Fictiopedia has stopped.", and the Logcat shows lots of errors I can't understand. It's an app that creates its own words by randomly displaying meaningful parts of actual English words and their definition accordingly. (I deleted a large part of the code with words and their definition to make it fit in this question box)
Thanks for helping.
Here, what the Logcat displays and my code:
LOGCAT:
12-27 11:09:05.099 1946-1946/? E/libprocessgroup: failed to make and chown /acct/uid_10059: Read-only file system
12-27 11:09:05.099 1946-1946/? W/Zygote: createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT?
12-27 11:09:05.099 1946-1946/? I/art: Late-enabling -Xcheck:jni
12-27 11:09:05.143 1946-1956/? I/art: Debugger is no longer active
12-27 11:09:05.360 1946-1946/? I/InstantRun: starting instant run server: is main process
12-27 11:09:05.454 1946-1946/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
12-27 11:09:05.690 1946-1946/? W/ResourceType: Failure getting entry for 0x7f060054 (t=5 e=84) (error -75)
12-27 11:09:05.691 1946-1946/? W/ResourceType: Failure getting entry for 0x7f060054 (t=5 e=84) (error -75)
12-27 11:09:05.692 1946-1946/? D/AndroidRuntime: Shutting down VM
--------- beginning of crash
12-27 11:09:05.693 1946-1946/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.lauramessner.fictiopedia, PID: 1946
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lauramessner.fictiopedia/com.example.lauramessner.fictiopedia.MainActivity}: android.view.InflateException: Binary XML file line #0: Error inflating class ImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
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: android.view.InflateException: Binary XML file line #0: Error inflating class ImageView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.lauramessner.fictiopedia.MainActivity.onCreate(MainActivity.java:26)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
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: android.content.res.Resources$NotFoundException: Resource ID #0x7f060054
at android.content.res.Resources.getValue(Resources.java:1266)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:330)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:195)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:188)
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:58)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:78)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at com.example.lauramessner.fictiopedia.MainActivity.onCreate(MainActivity.java:26) 
at android.app.Activity.performCreate(Activity.java:5990) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
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) 
12-27 11:09:10.334 1946-1946/? I/Process: Sending signal. PID: 1946 SIG: 9
MY CODE:
package com.example.lauramessner.fictiopedia;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
public void happen(View b){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView pref = (TextView) findViewById(R.id.pref);
final TextView root = (TextView) findViewById(R.id.root);
final TextView suff = (TextView) findViewById(R.id.suff);
final TextView predef = (TextView) findViewById(R.id.predef);
final TextView rootdef = (TextView) findViewById(R.id.rootdef);
final TextView suffdef = (TextView) findViewById(R.id.suffdef);
final String[] prefixes = {"", "A", "An", "Ab", "Ad", "Ambi", "Ana", "Ante", "Anti", "Apo", "Auto","Bene"};
final String[] roots = {"", "ami", "ann", "anthrop", "aqua"};
final String[] suffixes = {"", "agog", "agogue", "cide", "ectomy"};
ImageButton pushMe = findViewById(R.id.pushMe);
pushMe.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final int rando = (int) (Math.random());
suff.setText(prefixes[rando]);
root.setText(roots[rando]);
pref.setText(suffixes[rando]);
if (pref.getText().toString().contains("")) {
predef.setText("");
}
if (pref.getText().toString().contains("A")) {
predef.setText("not ");
}
if (pref.getText().toString().contains("An")) {
predef.setText("without ");
}
if (pref.getText().toString().contains("Ab")) {
predef.setText("away from ");
}
if (pref.getText().toString().contains("Ad")) {
predef.setText("toward ");
}
if (pref.getText().toString().contains("Ambi")) {
predef.setText("both ");
}
if (pref.getText().toString().contains("Ana")) {
predef.setText("again ");
}
if (pref.getText().toString().contains("Ante")) {
predef.setText("before ");
}
if (pref.getText().toString().contains("Anti")) {
predef.setText("against ");
}
if (pref.getText().toString().contains("Apo")) {
predef.setText("away from ");
}
if (pref.getText().toString().contains("Auto")) {
predef.setText("self ");
}
if (pref.getText().toString().contains("Bene")) {
predef.setText("good ");
}
if (root.getText().toString().contains("")) {
rootdef.setText("");
}
if (root.getText().toString().contains("ami")) {
rootdef.setText("love");
}
if (root.getText().toString().contains("ann")) {
rootdef.setText("year");
}
if (root.getText().toString().contains("anthrop")) {
rootdef.setText("human");
}
if (root.getText().toString().contains("aqua")) {
rootdef.setText("water");
}
if (suff.getText().toString().contains("")) {
suffdef.setText("");
}
if (suff.getText().toString().contains("agog")) {
suffdef.setText("Leader ");
}
if (suff.getText().toString().contains("agogue")) {
suffdef.setText("Leader ");
}
if (suff.getText().toString().contains("cide")) {
suffdef.setText("Act of killing ");
}
if (suff.getText().toString().contains("ectomy")) {
suffdef.setText("Surgical removal of ");
}
}
});
}
}

Related

App Crashes on Button Click that was supposed to send a call instantly

I have set up the button such a way that upon the click of a button it will send a call. when the button is clicked the app crashes. Please Help me debug this. Please suggest if there are alternative ways i can code a button to send a call directly upon clicking on it. I have granted permission in the settings as well.
package com.example.allegiant;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button dial;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dial = findViewById(R.id.dial);
}
public void onDialButton(View view) {
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tell:12345678"));
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return;
}
startActivity(intent);
}
}
Here is the logcat
2021-03-22 21:56:33.365 7530-7530/com.example.allegiant E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.allegiant, PID: 7530
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:402)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397)
at android.view.View.performClick(View.java:6294) 
at android.view.View$PerformClick.run(View.java:24770) 
at android.os.Handler.handleCallback(Handler.java:790) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6494) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=tell:12345678 }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1937)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1616)
at android.app.Activity.startActivityForResult(Activity.java:4487)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676)
at android.app.Activity.startActivityForResult(Activity.java:4445)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:663)
at android.app.Activity.startActivity(Activity.java:4806)
at android.app.Activity.startActivity(Activity.java:4774)
at com.example.allegiant.MainActivity.onDialButton(MainActivity.java:34)
at java.lang.reflect.Method.invoke(Native Method) 
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397) 
at android.view.View.performClick(View.java:6294) 
at android.view.View$PerformClick.run(View.java:24770) 
at android.os.Handler.handleCallback(Handler.java:790) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6494) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
Try adding READ_PHONE_STATE permission in manifest as well as ask it before click.
android.permission.READ_PHONE_STATE
Also surround your code inside click with try - catch having ActivityNotFoundException handling

Crash on super.onCreate(savedInstanceState) after recreate activity

I have two activities in my project ActivityOne and MainActivity.
I start MainActivity using intent from ActivityOne then I toggle dark mode switch in the MainActivity and call recreate() on the activity.
but MainActivity crashes on super.onCreate(savedInstanceState) line when it recreated.
androidx fragment version: 1.2.5
lifecycle version: 2.2.0
MainActivity:
override fun onCreate(savedInstanceState: Bundle?) {
val userInterfaceMode = when (UIMode.currentUIMode) {
is UIMode.DarkMode -> AppCompatDelegate.MODE_NIGHT_YES
is UIMode.LightMode -> AppCompatDelegate.MODE_NIGHT_NO
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
AppCompatDelegate.setDefaultNightMode(userInterfaceMode)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
overridePendingTransition(
R.anim.enter_activity_fade_in_anim,
R.anim.enter_activity_fade_out_anim
)
if (savedInstanceState == null){
setupNavigation()
}
}
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
super.onRestoreInstanceState(savedInstanceState)
setupNavigation()
}
private fun setupNavigation(){
if (supportFragmentManager.findFragmentByTag(NAV_HOST_TAG) != null){
val host = supportFragmentManager
.findFragmentByTag(NAV_HOST_TAG) as NavHostFragment
supportFragmentManager
.beginTransaction()
.attach(host)
.setPrimaryNavigationFragment(host)
.commit()
}else{
val host = NavHostFragment.create(R.navigation.navigation_graph)
supportFragmentManager
.beginTransaction()
.add(
R.id.mainActivityRoot, host,
NAV_HOST_TAG
)
.setPrimaryNavigationFragment(host)
.commit()
}
}
Logcat:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: me.pitok.goodnews, PID: 6173
java.lang.RuntimeException: Unable to start activity ComponentInfo{MainActivity}: java.lang.IllegalArgumentException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3119)
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:4886)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4795)
at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ClientTransactionHandler.executeTransaction(ClientTransactionHandler.java:55)
at android.app.ActivityThread.handleRelaunchActivityLocally(ActivityThread.java:4845)
at android.app.ActivityThread.access$3300(ActivityThread.java:201)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1849)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6864)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: java.lang.IllegalArgumentException
at androidx.lifecycle.LifecycleRegistry.downEvent(LifecycleRegistry.java:263)
at androidx.lifecycle.LifecycleRegistry.backwardPass(LifecycleRegistry.java:314)
at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:334)
at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:145)
at androidx.lifecycle.LifecycleRegistry.setCurrentState(LifecycleRegistry.java:118)
at androidx.navigation.NavBackStackEntry.updateState(NavBackStackEntry.java:150)
at androidx.navigation.NavBackStackEntry.setMaxLifecycle(NavBackStackEntry.java:130)
at androidx.navigation.NavController.popBackStackInternal(NavController.java:325)
at androidx.navigation.NavController.dispatchOnDestinationChanged(NavController.java:426)
at androidx.navigation.NavController.onGraphCreated(NavController.java:636)
at androidx.navigation.NavController.setGraph(NavController.java:586)
at androidx.navigation.NavController.setGraph(NavController.java:551)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:247)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2685)
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:280)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1187)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1368)
at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1446)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1509)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2637)
at androidx.fragment.app.FragmentManager.dispatchCreate(FragmentManager.java:2583)
at androidx.fragment.app.FragmentController.dispatchCreate(FragmentController.java:236)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:315)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:115)
at me.pitok.goodnews.appMain.MainActivity.onCreate(MainActivity.kt:24)
at android.app.Activity.performCreate(Activity.java:7232)
at android.app.Activity.performCreate(Activity.java:7221)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2964)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3119) 
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:4886) 
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4795) 
at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ClientTransactionHandler.executeTransaction(ClientTransactionHandler.java:55) 
at android.app.ActivityThread.handleRelaunchActivityLocally(ActivityThread.java:4845) 
at android.app.ActivityThread.access$3300(ActivityThread.java:201) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1849) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:201) 
at android.app.ActivityThread.main(ActivityThread.java:6864) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) 
Seems to be an issue using the same id for the navigation graph and the destination.
https://issuetracker.google.com/issues/161825212
We had a very similar crash and solved it by using a unique id for the navigation graph.

ClasscastException cannot be cast to linearlayout ot Button.widget.button

Process: com.example.e_classroom, PID: 12427
java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.Button
at com.example.e_classroom.test_questions$3.onAnimationEnd(test_questions.java:116)
at android.view.ViewPropertyAnimator$AnimatorEventListener.onAnimationEnd(ViewPropertyAnimator.java:1136)
at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1171)
at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:722)
at android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:738)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:800)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:571)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:786)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
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:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
here found error can anyone help this how to solve this error
public void onAnimationEnd(Animator animation) {
if(value==0) {
try{
((TextView)v).setText(data);
questindicator.setText(position+1+"/"+list.size());
}catch (ClassCastException ex){
// here 116 line no
((Button)v).setText(data);
}
v.setTag(data);
playanimate(v, 1,data);
}
}

Socket EACCESS permission denied with Android Studio

I am trying to connect my android emulator to my host computer with socket connection.
I have a simple Java server running and lessening in the host on port 6789.
I have the following code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Declares streamText to refer to text area to show all messages
TextView streamText = ((TextView) findViewById(R.id.streamText));
streamText.setText("");
streamText.append("Attempting connection at " + serverIP + " : 6789 \n");
try {
connection = new Socket(InetAddress.getByName(serverIP), 6789); // WHAT IP to connect to host, not virtual device host
streamText.append("Connected to: " + connection.getInetAddress().getHostAddress());
}catch(IOException Exception){
streamText.append(Exception.toString());
Exception.printStackTrace();
}
}
And i am getting this error on logcat:
02-05 11:46:52.257 2663-2663/net.ruiruivo.myfirstapp.chatclientv1 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: net.ruiruivo.myfirstapp.chatclientv1, PID: 2663
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{net.ruiruivo.myfirstapp.chatclientv1/net.ruiruivo.myfirstapp.chatclientv1.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
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:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
at android.app.Activity.findViewById(Activity.java:2071)
at net.ruiruivo.myfirstapp.chatclientv1.MainActivity.<init>(MainActivity.java:33)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1572)
at android.app.Instrumentation.newActivity(Instrumentation.java:1065)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
          
And inside my textView window the Exception Says:
java.net.SocketException: socket failed: EACCES (Permission denied)
I have search this and other sites, the answered that appeared the closest to this was <permission android:name="android.permission.INTERNET"></permission> in my manifest but did not solved the problem.
Can anyone help?
Your problem is somewhere else.
1.) post your XML file because it seems that you run into a NPE because streamText is null
2.) You can not do network code in the main thread - this will cause a
android.os.NetworkOnMainThreadException
You have to implement a separate task for that, e.g.:
private class NetworkTask extends AsyncTask<Void, Void, Object>{...}
Update:
Here you go:
#Override
protected void onCreate(Bundle savedInstanceState) {
//your code
new NetworkTask().execute();
}
private class NetworkTask extends AsyncTask<Void, Void, Object>{
#Override
protected Object doInBackground(Void... v) {
try {
//do your network stuff here
return "";
}
catch (HttpException e) {
return e;
}
}
// onPostExecute displays the results of the AsyncTask.
#Override
protected void onPostExecute(Object result) {
if(result instanceof String){
//everything was fine
}
else{
if(((HttpException)result).getMessage()!=null){
//exception occured
}
}
}
}

javafx IllegalArguementException when popup is open and mouse is clicked on the background stage

on click of it i am launching a popup. Pop has a dynamically created stackpane with a tableview. If i double click a row in table or i enter esc its working fine.
Issue is when i click anywhere on the background stage it gives me following error. How to close the popup when i click on the stage from where the popup is launched. Please suggest.
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1435)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
at javafx.event.Event.fireEvent(Event.java:171)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3324)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3164)
at javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3119)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1559)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2261)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:228)
at com.sun.glass.ui.View.handleMouseEvent(View.java:528)
at com.sun.glass.ui.View.notifyMouse(View.java:922)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
at java.lang.Thread.run(Thread.java:722)
Below is my code
public void trkTripNoBtnClick(ActionEvent ae){
StackPane st = new StackPane();
final TableView<GatePassDTO> tripListTableView = new TableView<GatePassDTO>();
TableColumn<GatePassDTO,String> colTrkTripNo = new TableColumn<GatePassDTO,String>();
TableColumn<GatePassDTO,Date> colGatePassDttm = new TableColumn<GatePassDTO,Date>();
TableColumn<GatePassDTO,String> colTruckNo = new TableColumn<GatePassDTO,String>();
TableColumn<GatePassDTO,String> colBat = new TableColumn<GatePassDTO,String>();
colTrkTripNo.setText("Trip No");
colTrkTripNo.setCellValueFactory(new PropertyValueFactory<GatePassDTO,String>("tourPlnNo"));
colGatePassDttm.setText("Gate Pass Dttm");
colGatePassDttm.setCellValueFactory(new PropertyValueFactory<GatePassDTO,Date>("gatePassDttm"));
colTruckNo.setText("Truck");
colTruckNo.setCellValueFactory(new PropertyValueFactory<GatePassDTO,String>("haulPmNo"));
colBat.setText("BAT ID");
colBat.setCellValueFactory(new PropertyValueFactory<GatePassDTO,String>("batId"));
List<GatePassDTO> tripsList = GateIn.getGatePassReference().gateIn_tourPlnNoLookUp(1);
tripListTableView.getColumns().addAll(colTrkTripNo,colGatePassDttm,colTruckNo,colBat);
tripListTableView.setItems(FXCollections.observableList(tripsList));
final Popup popup = new Popup();
popup.setX(txtTrkTripNo.getLayoutX());
popup.setY(txtTrkTripNo.getLayoutY()+txtTrkTripNo.getHeight()+30);
colTrkTripNo.prefWidthProperty().bind(tripListTableView.widthProperty().multiply(0.20));
colGatePassDttm.prefWidthProperty().bind(tripListTableView.widthProperty().multiply(0.45));
colTruckNo.prefWidthProperty().bind(tripListTableView.widthProperty().multiply(0.15));
colBat.prefWidthProperty().bind(tripListTableView.widthProperty().multiply(0.20));
tripListTableView.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>(){
#Override
public void handle(MouseEvent t) {
if(t.getClickCount() == 2 && tripListTableView.getSelectionModel().getSelectedItem() !=null){
GatePassDTO g = tripListTableView.getSelectionModel().getSelectedItem();
popup.hide();
txtTrkTripNo.setText(g.getTourPlnNo());
getTripDetails(txtTrkTripNo.getText());
}
}
});
tripListTableView.addEventHandler(KeyEvent.KEY_PRESSED,new EventHandler<KeyEvent>(){
#Override
public void handle(KeyEvent t) {
if(t.getCode() == KeyCode.ESCAPE)
popup.hide();
}
});
/*Label lblFind = new Label("Find");
TextField txtfind = new TextField();
st.getChildren().add(lblFind);
st.getChildren().add(txtfind);*/
st.getChildren().add(tripListTableView);
VBox v = new VBox(5);
v.getChildren().addAll(st);
popup.getContent().addAll(v);
popup.show(GateIn.primaryStage);
}
you have to check focus property for stage...
try this its worked
stage.focusedProperty().addListener(new ChangeListener<Boolean>
() {
#Override
public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
if(t1==false)
{
System.out.println("focus losted");
btn.getScene().getWindow().hide();
}
}
});

Resources