小编Squ*_*art的帖子

Android:应用在启动新活动时崩溃

基本上,我想开始一个活动,打印出输入字符串和下面的图像.

在activity_display_message.xml中:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical" >

      <TextView 
            android:text="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />

        <ImageView
        android:id="@+id/imageView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/serious" />    


</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是OnCreate()中的代码:

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_display_message);  
    Intent intent = getIntent();

    String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

    ImageView image2 = (ImageView) findViewById(R.id.imageView2);


    // Create the text view

    TextView textView = (TextView)findViewById(R.id.textView);
    //textView.setTextSize(20);

    textView.setText(message);
    // Set the text view as the activity layout   


    // Show the Up button in the action bar.
    setupActionBar();
}
Run Code Online (Sandbox Code Playgroud)

这段代码有什么问题吗?

编辑:不知道如何获得堆栈跟踪,但我刚刚在Catlog中找到了这些行:

07-05 12:26:53.677: …
Run Code Online (Sandbox Code Playgroud)

crash android textview

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

crash ×1

textview ×1