附上代码,没报错,一运行就程序异常,求指教。
xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/RLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <TextView
        android:id="@+id/lblComments"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="请输入你所在位置和你要去的位置"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        />
    <EditText
        android:id="@+id/text1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/lblComments"
        android:layout_below="@+id/lblComments"
         />
    <TextView
        android:id="@+id/view1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/text1"
        android:textSize="40px"
        android:layout_centerHorizontal="true"
        android:text="到"
        />
    <EditText
        android:id="@+id/text2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/view1"
        />
    <Button
            android:id="@+id/button6"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="路线搜索" 
            android:layout_below="@+id/text2"/>
    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button6"
        android:layout_centerHorizontal="true"
        >
        <ImageView
            android:id="@+id/image2"
            android:src= "@drawable/pic13"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </FrameLayout>
</RelativeLayout>
activity文件
package com.example.superet;import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;public class ditu extends Activity {
EditText textBox1;
EditText textBox2;
private ImageView image;
@Override
public void onCreate(Bundle savedInstanceState)  {
textBox1 = (EditText) findViewById(R.id.text1);
textBox2 = (EditText) findViewById(R.id.text2);
super.onCreate(savedInstanceState);
setContentView(R.layout.chaoshiditu1);
Button btn6 = (Button)findViewById(R.id.button6);
image = (ImageView) findViewById(R.id.image2);
btn6.setOnClickListener(new OnClickListener() {          
      public void onClick(View v) 
     {              
     String str1 = textBox1.getText().toString();
     String str2 = textBox2.getText().toString();
     if (str1=="1"&&str2=="2"||str1=="2"&&str2=="1") 
     {
     image.setBackgroundResource(R.drawable.pic1);
}
     if (str1=="1"&&str2=="3"||str1=="3"&&str2=="1") 
     {
     image.setBackgroundResource(R.drawable.pic2);
}  
     if (str1=="1"&&str2=="3"||str1=="3"&&str2=="1") 
     {
     image.setBackgroundResource(R.drawable.pic3);
}  
     if (str1=="1"&&str2=="4"||str1=="4"&&str2=="1") 
     {
     image.setBackgroundResource(R.drawable.pic4);
}  
     if (str1=="1"&&str2=="5"||str1=="5"&&str2=="1") 
     {
     image.setBackgroundResource(R.drawable.pic5);
}  
     if (str1=="1"&&str2=="6"||str1=="6"&&str2=="1") 
     {
     image.setBackgroundResource(R.drawable.pic6);
}  
     if (str1=="1"&&str2=="7"||str1=="7"&&str2=="1") 
     {
     image.setBackgroundResource(R.drawable.pic7);
}  
     if (str1=="1"&&str2=="8"||str1=="8"&&str2=="1") 
     {
     image.setBackgroundResource(R.drawable.pic8);
}  
     else {
     image.setBackgroundResource(R.drawable.pic13);
}
     } 
});
}
}Androidimageview布局Stringtextbox

解决方案 »

  1.   


    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        android:id="@+id/RLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android"
        >
        <TextView
            android:id="@+id/lblComments"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="请输入你所在位置和你要去的位置"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            />
        <EditText
            android:id="@+id/text1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/lblComments"
            android:layout_below="@+id/lblComments"
             />
        <TextView
            android:id="@+id/view1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/text1"
            android:textSize="40px"
            android:layout_centerHorizontal="true"
            android:text="到"
            />
        <EditText
            android:id="@+id/text2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/view1"
            />
        <Button
                android:id="@+id/button6"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="路线搜索" 
                android:layout_below="@+id/text2"/>
        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/button6"
            android:layout_centerHorizontal="true"
            >
            <ImageView
                android:id="@+id/image2"
                android:src= "@drawable/pic13"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" />
        </FrameLayout>
    </RelativeLayout>package com.example.superet;import android.os.Bundle;
    import android.app.Activity;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.ImageView;public class ditu extends Activity {
    EditText textBox1;
    EditText textBox2;
    private ImageView image;
    @Override
    public void onCreate(Bundle savedInstanceState)  {
    textBox1 = (EditText) findViewById(R.id.text1);
    textBox2 = (EditText) findViewById(R.id.text2);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.chaoshiditu1);
    Button btn6 = (Button)findViewById(R.id.button6);
    image = (ImageView) findViewById(R.id.image2);
    btn6.setOnClickListener(new OnClickListener() {          
          public void onClick(View v) 
         {              
          String str1 = textBox1.getText().toString();
          String str2 = textBox2.getText().toString();
          if (str1=="1"&&str2=="2"||str1=="2"&&str2=="1") 
          {
          image.setBackgroundResource(R.drawable.pic1);
    }
          if (str1=="1"&&str2=="3"||str1=="3"&&str2=="1") 
          {
          image.setBackgroundResource(R.drawable.pic2);
    }  
          if (str1=="1"&&str2=="3"||str1=="3"&&str2=="1") 
          {
          image.setBackgroundResource(R.drawable.pic3);
    }  
          if (str1=="1"&&str2=="4"||str1=="4"&&str2=="1") 
          {
          image.setBackgroundResource(R.drawable.pic4);
    }  
          if (str1=="1"&&str2=="5"||str1=="5"&&str2=="1") 
          {
          image.setBackgroundResource(R.drawable.pic5);
    }  
          if (str1=="1"&&str2=="6"||str1=="6"&&str2=="1") 
          {
          image.setBackgroundResource(R.drawable.pic6);
    }  
          if (str1=="1"&&str2=="7"||str1=="7"&&str2=="1") 
          {
          image.setBackgroundResource(R.drawable.pic7);
    }  
          if (str1=="1"&&str2=="8"||str1=="8"&&str2=="1") 
          {
          image.setBackgroundResource(R.drawable.pic8);
    }  
          else {
          image.setBackgroundResource(R.drawable.pic13);
    }
         } 
    });
    }
    }
      

  2.   

    你把运行时的log发一下把。看看是哪里出了问题
      

  3.   

    你是顺序不对啊

    setContentView(R.layout.chaoshiditu1);
    然后
    textBox1 = (EditText) findViewById(R.id.text1);
    textBox2 = (EditText) findViewById(R.id.text2);
    这样就不会报错了
      

  4.   

    先不说其他的,说点基础的吧。
    if (str1=="1"&&str2=="2"||str1=="2"&&str2=="1") 
    这样写,你觉得是否合适。
    java基础,比较内容与比较内存地址,有木有这个概念。其他的代码没看
      

  5.   

    5#的你好。原来是用的str1.equals(1)也不行啊。
      

  6.   

    用"1".equals(str1);
    要把变量写在括号里。因为变量有可能是null。
      

  7.   

    用"1".equals(str1);
    要把变量写在括号里。因为变量有可能是null。
    嗯刚打的时候忘了双引号,主要还是那个顺序报错,不过谢谢你这么热心回答
      

  8.   

    用"1".equals(str1);
    要把变量写在括号里。因为变量有可能是null。
    嗯刚打的时候忘了双引号,主要还是那个顺序报错,不过谢谢你这么热心回答
    客气。