我正在尝试从EditText字段获取输入并将其存储到SQLite数据库中。但即使在我输入文本后,Fields也为null。 我之前做了类似的事情,结果很好,但我很困惑这里导致问题的原因。
package com.example.mridul.eventmanager;
import android.content.Intent;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class CreateEvent extends AppCompatActivity {
EditText edit,edit2,edit3,edit4;
TextView t1;
ImageView img;
Button bpost;
public static final int PICK_IMAGE=1;
Uri imageuri;
Event in;
DatabaseHelper dc = new DatabaseHelper(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_event);
edit = (EditText) findViewById(R.id.editText7);
edit2 = (EditText) findViewById(R.id.editText8);
edit3 = (EditText) findViewById(R.id.editText9);
edit4 = (EditText) findViewById(R.id.editText10);
t1 = (TextView) findViewById(R.id.textView6);
img = (ImageView) findViewById(R.id.imageView);
bpost = (Button) findViewById(R.id.button3);
t1.setOnClickListener(new View.OnClickListener(){
public void onClick(View vim){
operationGallery();
}
});
bpost.setOnClickListener(new View.OnClickListener(){
public void onClick(View vPost){
in.sEventName(edit.getText().toString()); //Problem here
in.sEventDesc(edit2.getText().toString());
in.sEventVenue(edit3.getText().toString());
in.sType(edit4.getText().toString());
in.sPic(imageuri.toString());
dc.addEvent(in);
Toast.makeText(getApplicationContext(), "Data Saved", Toast.LENGTH_SHORT).show();
Intent gBack = new Intent(CreateEvent.this, LoginActivity.class);
CreateEvent.this.startActivity(gBack);
}
});
} public void operationGallery(){
Intent im = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(im , PICK_IMAGE);
}
public void onActivityResult(int requestcode, int resultcode, Intent data){
super.onActivityResult(requestcode, resultcode, data);
if((resultcode == RESULT_OK)&&(requestcode == PICK_IMAGE)){
imageuri = data.getData();
img.setImageURI(imageuri);
}
}
}
以下是执行代码后我得到的错误
答案 0 :(得分:0)
您刚刚忘记在"
中启动Event对象"答案 1 :(得分:0)
您的Event
对象in
未初始化。