Assigned
Status Update
Comments
bn...@google.com <bn...@google.com> #2
ki...@google.com <ki...@google.com> #3
Not seeing any crashes on the latest Android 10 device or Marshmallow emulator.
myClipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
myClipboard.addPrimaryClipChangedListener(this);
From the stack trace in the original message, the exception is inside the system ClipboardManager:
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void android.content.IClipboard.addPrimaryClipChangedListener(android.content.IOnPrimaryClipChangedListener, java.lang.String)' on a null object reference
at android.content.ClipboardManager.addPrimaryClipChangedListener(ClipboardManager.java:166)
This should go to the framework team and not appcompat module.
myClipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
myClipboard.addPrimaryClipChangedListener(this);
From the stack trace in the original message, the exception is inside the system ClipboardManager:
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void android.content.IClipboard.addPrimaryClipChangedListener(android.content.IOnPrimaryClipChangedListener, java.lang.String)' on a null object reference
at android.content.ClipboardManager.addPrimaryClipChangedListener(ClipboardManager.java:166)
This should go to the framework team and not appcompat module.
ki...@google.com <ki...@google.com> #4
Also, the internal reproduction details are incorrect. It's failing there on "Error inflating class android.support.design.widget.CoordinatorLayout" since CoordinatorLayout is now in the androidx.coordinatorlayout.widget package.
Description
- MainActivity source
public class MainActivity extends AppCompatActivity implements ClipboardManager.OnPrimaryClipChangedListener{
private ClipboardManager myClipboard;
private ClipData myClip;
EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
myClipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
//myClipboard.addPrimaryClipChangedListener(this);
et = (EditText) findViewById(R.id.etContent);
et.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
return false;
}
});
et.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text;
text = et.getText().toString();
Log.d(getClass().getSimpleName(), String.format("%s", text));
myClip = ClipData.newPlainText("text", text);
myClipboard.setPrimaryClip(myClip);
Toast.makeText(getApplicationContext(), "Text Copied", Toast.LENGTH_SHORT).show();
}
});
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
Log.d(getClass().getSimpleName(), String.format("%s", myClipboard.toString()));
}
@Override
public void onPrimaryClipChanged(){
Log.d(getClass().getSimpleName(), String.format("%s", "PrimaryClipChanged......................"));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo){
menu.clearHeader();
menu.clear();
menu.setHeaderTitle("Text menu");
menu.add(Menu.NONE, Menu.FIRST+1, Menu.NONE, "Test Menu");
super.onCreateContextMenu(menu, view, menuInfo);
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------
- activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="
xmlns:app="
xmlns:tools="
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.jands.myapplication.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
-----------------------------------------------------------------------------------------------------------------------------------------------
- content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="
xmlns:app="
xmlns:tools="
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.jands.myapplication.MainActivity"
tools:showIn="@layout/activity_main">
<EditText
android:id="@+id/etContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
----------------------------------------------------------------------------------------------------------------------------------------
- Logcat message.
06-28 15:19:15.780 3081-3081/? I/art: Late-enabling -Xcheck:jni
06-28 15:19:16.063 3081-3081/com.jands.myapplication 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
06-28 15:19:16.302 3081-3096/com.jands.myapplication W/art: Suspending all threads took: 11.491ms
06-28 15:19:16.316 3081-3096/com.jands.myapplication I/art: Background sticky concurrent mark sweep GC freed 2843(227KB) AllocSpace objects, 0(0B) LOS objects, 19% free, 912KB/1135KB, paused 16.131ms total 71.423ms
06-28 15:19:16.427 3081-3096/com.jands.myapplication I/art: Background partial concurrent mark sweep GC freed 375(65KB) AllocSpace objects, 0(0B) LOS objects, 50% free, 1012KB/2036KB, paused 6.218ms total 42.864ms
06-28 15:19:16.586 3081-3081/com.jands.myapplication D/MainActivity: android.content.ClipboardManager@13ea09b4
06-28 15:19:16.603 3081-3099/com.jands.myapplication D/OpenGLRenderer: Render dirty regions requested: true
06-28 15:19:16.705 3081-3099/com.jands.myapplication D/libEGL: loaded /system/lib/egl/libEGL_VIVANTE.so
06-28 15:19:16.747 3081-3099/com.jands.myapplication D/libEGL: loaded /system/lib/egl/libGLESv1_CM_VIVANTE.so
06-28 15:19:17.032 3081-3099/com.jands.myapplication D/libEGL: loaded /system/lib/egl/libGLESv2_VIVANTE.so
06-28 15:19:17.252 3081-3099/com.jands.myapplication I/OpenGLRenderer: Initialized EGL, version 1.4
06-28 15:19:17.269 3081-3099/com.jands.myapplication D/OpenGLRenderer: Enabling debug mode 0
06-28 15:19:17.336 3081-3081/com.jands.myapplication I/Choreographer: Skipped 51 frames! The application may be doing too much work on its main thread.
06-28 15:19:30.431 3081-3081/com.jands.myapplication W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection
06-28 15:20:04.739 3081-3099/com.jands.myapplication I/OpenGLRenderer: Initialized EGL, version 1.4
06-28 15:20:05.601 3081-3081/com.jands.myapplication I/Choreographer: Skipped 30 frames! The application may be doing too much work on its main thread.
06-28 15:20:10.922 3081-3081/com.jands.myapplication D/AndroidRuntime: Shutting down VM
06-28 14:57:24.034 2831-2831/com.jands.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.jands.myapplication, PID: 2831
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jands.myapplication/com.jands.myapplication.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'void android.content.IClipboard.addPrimaryClipChangedListener(android.content.IOnPrimaryClipChangedListener, java.lang.String)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
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 interface method 'void android.content.IClipboard.addPrimaryClipChangedListener(android.content.IOnPrimaryClipChangedListener, java.lang.String)' on a null object reference
at android.content.ClipboardManager.addPrimaryClipChangedListener(ClipboardManager.java:166)
at com.jands.myapplication.MainActivity.onCreate(MainActivity.java:30)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
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)