- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
获取用户输入:
Intent intentTrashcanLocation = new Intent(this, TrashcanLocationActivity.class);
EditText editWidth = (EditText)findViewById(R.id.dimvalWidth);
EditText editLength = (EditText)findViewById(R.id.dimvalLength);
String width = editWidth.getText().toString();
String length = editLength.getText().toString();
intentTrashcanLocation.putExtra("widthValue", width);
intentTrashcanLocation.putExtra("lengthValue", length);
startActivity(intentTrashcanLocation);
接收和显示:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_trashcan_location);
Intent parentintent = getIntent();
Bundle dimval = parentintent.getExtras();
String width = (String)dimval.get("widthValue");
String length = (String)dimval.get("lengthValue");
TextView widthtext = (TextView)findViewById(R.id.widthView);
TextView lengthtext = (TextView)findViewById(R.id.lengthView);
widthtext.setText(width);
lengthtext.setText(length);
当我运行程序并输入文本并继续进行下一个 Activity 时,程序崩溃。获取错误:
03-29 12:33:57.418: E/AndroidRuntime(28049): FATAL EXCEPTION: main
03-29 12:33:57.418: E/AndroidRuntime(28049): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.trash2/com.example.trash2.TrashcanLocationActivity}: java.lang.NullPointerException
03-29 12:33:57.418: E/AndroidRuntime(28049): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
03-29 12:33:57.418: E/AndroidRuntime(28049): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
03-29 12:33:57.418: E/AndroidRuntime(28049): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-29 12:33:57.418: E/AndroidRuntime(28049): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
03-29 12:33:57.418: E/AndroidRuntime(28049): at android.os.Handler.dispatchMessage(Handler.java:99)
03-29 12:33:57.418: E/AndroidRuntime(28049): at android.os.Looper.loop(Looper.java:137)
03-29 12:33:57.418: E/AndroidRuntime(28049): at android.app.ActivityThread.main(ActivityThread.java:5103)
03-29 12:33:57.418: E/AndroidRuntime(28049): at java.lang.reflect.Method.invokeNative(Native Method)
03-29 12:33:57.418: E/AndroidRuntime(28049): at java.lang.reflect.Method.invoke(Method.java:525)
03-29 12:33:57.418: E/AndroidRuntime(28049): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
03-29 12:33:57.418: E/AndroidRuntime(28049): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-29 12:33:57.418: E/AndroidRuntime(28049): at dalvik.system.NativeStart.main(Native Method)
03-29 12:33:57.418: E/AndroidRuntime(28049): Caused by: java.lang.NullPointerException
03-29 12:33:57.418: E/AndroidRuntime(28049): at com.example.trash2.TrashcanLocationActivity.onCreate(TrashcanLocationActivity.java:36)
03-29 12:33:57.418: E/AndroidRuntime(28049): at android.app.Activity.performCreate(Activity.java:5133)
03-29 12:33:57.418: E/AndroidRuntime(28049): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-29 12:33:57.418: E/AndroidRuntime(28049): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
03-29 12:33:57.418: E/AndroidRuntime(28049): ... 11 more
我对此很陌生,非常感谢任何帮助。谢谢!
编辑:这是 activity_trashcan_location:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.trash2.TrashcanLocationActivity"
tools:ignore="MergeRootFrame" />
和 fragment_trashcan_location:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/interface_bg"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.trash2.TrashcanLocationActivity$PlaceholderFragment" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="11dp"
android:text="Bluetooth Trashcan"
android:textAppearance="@style/AppTheme"
android:textSize="60dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginLeft="10dp"
android:text="- Settings: Trashcan Location?"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="40dp" />
<TextView
android:id="@+id/widthView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/lengthView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/buttonNext"
android:layout_width="140dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="19dp"
android:layout_marginRight="20dp"
android:text="Finish"
android:textSize="30dp"
android:onClick="doMain" />
最佳答案
您的 activity_trashcan_location
布局不包含 View widthView
和 lengthView
。相反,它们位于 fragment 布局中,并且它不会成为 Activity onCreate()
中 Activity View 层次结构的一部分。
要么修复它
将接触 View 的代码移动到 fragment 中,例如它的onCreateView()
,或者
将需要触摸的 View 移动到 Activity 布局中。
关于android - 传入文本值并尝试显示时 Activity 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22734517/
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: How do I copy an object in Java? 我的类中有一个函数 Claus它调用一个函数来接受
任何人都可以给我一个 linux 内核驱动程序手册或示例的链接,它可以修改来自/到指定 ip 端口的传入/传出数据包吗? 谢谢! 最佳答案 Kprobes 是一种可以做到这一点的方法。这是一个使用具有
我有一个 3rd 方网站,该网站具有发送到特定 url 的 webhook。我将其设置为发送到我网站上的空白页面(例如:www.mysite.com/webhook.php) 我在 webhook.p
我对传递的约定感到困惑*args在 super().__init__()在python继承中。 我了解需要使用关键字参数 **kwargs因此,如果需要,CRO 中的类可以采用所需的参数,但为什么还有
我有一个 webapi (.NET core 3.1) 方法,它正在获取 XML 并反序列化为对象。但是一些标签的开头和结尾是不一样的。例如,如果以 打开然后它以 关闭.因此 XML 格式不正确。
是否有一个 hg 命令可以组合 hg传入 + hg传出 + hg status? 这会告诉您是否有任何远程内容需要传入,是否有任何本地提交的内容需要出去,或者是否有任何本地更改需要提交。 最佳答案 虽
据我了解,你无法在两部 iPhone 之间建立连接(如果我错了,请纠正我)。因此,我想做的是在客户端应用程序之间放置一台服务器,该服务器接受消息并将其重新分发给适当的人员。本质上,该应用程序将允许人们
我正在使用 Apache Camel 向我的 Java 服务发送消息。我在消费者路线上保留了 transacted=true。我还需要发送有关成功处理 JMS 消息的电子邮件。 我正在使用以下代码来注
这个问题在这里已经有了答案: What does "this" point to? (5 个答案) 关闭 4 年前。 public class CommandForm extends Form im
我是一名 Swift 开发人员,也是 Dart 的新手。我正在尝试编写一些通用方法。 我想知道我是否可以在 Dart 中实现类似的事情。 //Swift version public func mod
基本上有人问我是否有任何方法可以捕获和下载通过邮件服务器的所有传入和传出电子邮件(最好是文本格式)。这种下载方法需要使用PHP或类似的服务器端语言来完成。 如果我能通过上述阶段,那么最终目标就很容易实
我正在学习 Flask 并且有一个关于动态路由的问题:是否可以传入一个可接受的路由列表?我注意到 any 转换器有潜力,但很难找到它的使用示例。基本上我有不同的端点组,它们应该在它们之间触发相同的 A
我正在学习如何使用 pthread 函数。在这里我想使用 pthread_create 创建一个线程并用它计算一些数字的平均值。(数字序列末尾的0表示已经完成) 这是我到目前为止写的: #includ
我需要传递一个带有字段“nombre”作为参数的条件 目前我这样做: @xcondicion= {:nombre.like => "%#{params[:qyBusqueda]}%"} cliente
我有以下两个 parseInt(),我不太清楚为什么它们会给我不同的结果: alert(parseInt(0.00001)) 显示 0; alert(parseInt(0.00000001)) 显示
我有一个使用 SODA 包来操作 JSON 数据库的 PL/SQL 处理程序。我想: 读取有效负载中键 id 的值 将负载 JSON 写入数据库中的新文档。 要执行第 1 步,处理程序将 :body
我正在使用 Oracle 试用 Dapper,我试图运行多结果集查询,但 Oracle 需要 dbtype 的 refcursor。 StringBuilder query = new StringB
我在将“工作表”选项卡重命名为任何文件名时遇到问题。这样做的问题是,如果用户意外下载工作表两次,Windows 会将 template(1).csv 附加到文件中,以保持其下载目录中的唯一性。在 Ex
我将 id 作为字符串传递到函数中。我想使用该 ID 来更改背景颜色。我用过: $("#"+address).css("background-color", "#3399FF"); 但它没有改变背景颜
我有一个 ListSourceAdapter.java 类, class ListSourceViewHolder extends RecyclerView.ViewHolder implements
我是一名优秀的程序员,十分优秀!