我仍然有问题任何身体帮助?请我没有时间。明天是我最后一个研究生项目演示。
(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);
}
});
}
}
日志猫
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