2011-07-16 24 views
-1

我只是做最簡單的事情。我有一個2按鈕和ImageView佈局,當我通過ID找到它時,我得到一個NullPointerException空指針異常與從視圖的基本按鈕

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:weightSum="1"> 
<Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
<Button android:text="Button" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
<ImageView android:layout_height="wrap_content" android:id="@+id/imageView1" android:layout_width="76dp" android:layout_weight="0.12"></ImageView> 
</LinearLayout> 

的OnCreate:

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     one = (Button) findViewById(R.id.button1); 
     two = (Button) findViewById(R.id.button2); 
     image = (ImageView)findViewById(R.id.imageView1); 

     one.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent intent = new Intent(); 
       intent.setType("image/*"); 
       intent.setAction(Intent.ACTION_GET_CONTENT); 
       startActivityForResult(Intent.createChooser(intent, "Select Picture"),1); 
      } 
     }); 

     two.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
       startActivityForResult(cameraIntent, 2); 
      } 
     }); 

    } 
+1

錯誤日誌請 –

+3

清潔一次應用程序,然後重試仍然沒有工作然後張貼錯誤日誌。 –

+1

請分享nullpointerexception的堆棧跟蹤 – Kristian

回答

-1

檢查你的代碼,我沒有看到明顯的邏輯將拋出NPE。也許它是在未發佈的代碼中。 我們可以檢查日誌,看看哪些訂單通過以下命令拋出異常: 亞行logcat