2013-05-19 13 views
0

我仍然有任何身體幫助的問題??請我沒時間。 Tommorow是我最後的研究生項目介紹。如何解決RunTime錯誤與Android的ImageView在Android

(java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.assfar/com.example.assfar.hotel.Hotel_Details}: java.lang.NullPointerException 

我買了啓動活動運行時錯誤

package com.example.assfar.hotel; 

import android.app.Activity; 
import android.content.Intent; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.ImageView; 
import android.widget.TextView; 

import com.example.assfar.R; 
import com.example.assfar.database.DBHelper; 
import com.example.assfar.offers.Customer_Info; 


public class Hotel_Details extends Activity{ 

    private DBHelper dataBase; 
    private ImageView imgv; 
    private TextView textView; 
    private TextView textView2; 
    private TextView textView3; 
    private Cursor cursor; 
    private String price; 
    private String hotelDesc; 
    private int idValue; 
    private byte [] imgByte; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.hotel_details); 

     textView = (TextView)findViewById(R.id.hotel_name); 
     textView2 = (TextView)findViewById(R.id.hotel_desc); 
     textView3 = (TextView)findViewById(R.id.hotel_price); 

     imgv = (ImageView)findViewById(R.id.hotel_image); 
     imgv.setImageDrawable(null); 


     Intent i= getIntent(); 
     // getting attached intent data 
     String item = i.getStringExtra("selected Item"); 
     int id = i.getIntExtra("hotel_id", 1); 


     // displaying selected product name 
      textView.setText(item); 

     imgByte= null; 

     dataBase= DBHelper.instance(); 
     SQLiteDatabase db= dataBase.getWritableDatabase(); 

     cursor= db.rawQuery("select * from hotel_reservation", null); 

     if(cursor!=null) { 
      if(cursor.moveToFirst()); 
      { 
       do 
       { 

       price = cursor.getString(cursor.getColumnIndex("price")); 
       idValue= cursor.getInt(cursor.getColumnIndex("ReservationID")); 
       hotelDesc= cursor.getString(cursor.getColumnIndex("hotel_Description"));             
       imgByte= cursor.getBlob(cursor.getColumnIndex("hotel_photo")); 
       Bitmap bmp = BitmapFactory.decodeByteArray(imgByte,0,imgByte.length); 

        if(idValue==id){ 

         textView2.setText("\n"+hotelDesc); 
         imgv.setImageBitmap(bmp); 
         } 

       } while(cursor.moveToNext()); 
      } 
     } 


     Button butt_reserve= (Button)findViewById(R.id.reserve); 
     butt_reserve.setOnClickListener(new OnClickListener(){ 

      @Override 
      public void onClick(View v) { 
       Intent i=new Intent(Hotel_Details.this,Customer_Info.class); 
       startActivity(i);      
     } 

     }); 

     } 
} 

logcat的

05-19 16:53:32.411: E/AndroidRuntime(3661): FATAL EXCEPTION: main 
    05-19 16:53:32.411: E/AndroidRuntime(3661): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.assfar/com.example.assfar.hotel.Hotel_Details}: java.lang.NullPointerException 
    05-19 16:53:32.411: E/AndroidRuntime(3661):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 
    05-19 16:53:32.411: E/AndroidRuntime(3661):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
    05-19 16:53:32.411: E/AndroidRuntime(3661):  at android.app.ActivityThread.access$600(ActivityThread.java:141) 
    05-19 16:53:32.411: E/AndroidRuntime(3661):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
    05-19 16:53:32.411: E/AndroidRuntime(3661):  at android.os.Handler.dispatchMessage(Handler.java:99) 
    05-19 16:53:32.411: E/AndroidRuntime(3661):  at android.os.Looper.loop(Looper.java:137) 
    05-19 16:53:32.411: E/AndroidRuntime(3661):  at android.app.ActivityThread.main(ActivityThread.java:5041) 
    05-19 16:53:32.411: E/AndroidRuntime(3661):  at java.lang.reflect.Method.invokeNative(Native Method) 
    05-19 16:53:32.411: E/AndroidRuntime(3661):  at java.lang.reflect.Method.invoke(Method.java:511) 
    05-19 16:53:32.411: E/AndroidRuntime(3661):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
    05-19 16:53:32.411: E/AndroidRuntime(3661):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
    05-19 16:53:32.411: E/AndroidRuntime(3661):  at dalvik.system.NativeStart.main(Native Method) 
    05-19 16:53:32.411: E/AndroidRuntime(3661): Caused by: java.lang.NullPointerException 
    05-19 16:53:32.411: E/AndroidRuntime(3661):  at com.example.assfar.hotel.Hotel_Details.onCreate(Hotel_Details.java:74) 
    05-19 16:53:32.411: E/AndroidRuntime(3661):  at android.app.Activity.performCreate(Activity.java:5104) 
    05-19 16:53:32.411: E/AndroidRuntime(3661):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 
    05-19 16:53:32.411: E/AndroidRuntime(3661):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 
    05-19 16:53:32.411: E/AndroidRuntime(3661):  ... 11 more 
+0

發佈完整的logcat – Pragnani

+0

調試並檢查您是否正在獲取db實例!= null – Daniel

+0

我有一個db實例。我已經試過沒有圖像的代碼,它的工作非常規 – user2327501

回答

0

檢查以確保您已註冊您的活動在您的清單。這是這種錯誤最常見的原因。

+1

這絕對應該是一個評論 – Daniel

+1

@Daniel同意。做一個評論。他得到NP,而不是activitynotfound異常。 –

+0

活動在清單文件中註冊 – user2327501

相關問題