Flutter TextField Causing NullPointerException
542
You should be using a stateful widget for Textfield and textformfield. probably thats what causing the error.
Author by
rbinnun
Updated on December 23, 2022Comments
-
rbinnun over 1 year
Any idea why the
TextField
in Flutter code below is causing theNullPointerException
shown?Code:
void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: TextField(), ), ); } }
Exception:
W/System.err(13600): java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.ClipData.getItemCount()' on a null object reference W/System.err(13600): at android.os.Parcel.readException(Parcel.java:1626) W/System.err(13600): at android.os.Parcel.readException(Parcel.java:1573) W/System.err(13600): at android.content.IClipboard$Stub$Proxy.getPrimaryClip(IClipboard.java:197) W/System.err(13600): at android.content.ClipboardManager.getPrimaryClip(ClipboardManager.java:247) W/System.err(13600): at io.flutter.plugin.platform.PlatformPlugin.getClipboardData(PlatformPlugin.java:274) W/System.err(13600): at io.flutter.plugin.platform.PlatformPlugin.access$700(PlatformPlugin.java:24) W/System.err(13600): at io.flutter.plugin.platform.PlatformPlugin$1.getClipboardData(PlatformPlugin.java:81) W/System.err(13600): at io.flutter.embedding.engine.systemchannels.PlatformChannel$1.onMethodCall(PlatformChannel.java:141) W/System.err(13600): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:230) W/System.err(13600): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85) W/System.err(13600): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692) W/System.err(13600): at android.os.MessageQueue.nativePollOnce(Native Method) W/System.err(13600): at android.os.MessageQueue.next(MessageQueue.java:323) W/System.err(13600): at android.os.Looper.loop(Looper.java:143) W/System.err(13600): at android.app.ActivityThread.main(ActivityThread.java:7224) W/System.err(13600): at java.lang.reflect.Method.invoke(Native Method) W/System.err(13600): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) W/System.err(13600): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)