我从前一个活动中获取了一个解析对象的Id并将其存储在" obj" 我知道Id正在通过检查传递,但我得到空指针异常,因为我的四个字符串restName,restAddress,restCuisine和restLocation是空的,即使我尝试通过我的解析查询分配相应的值。
package com.example.gastronomaapp;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.parse.GetCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
public class SingleRestraunt extends ActionBarActivity {
private GoogleMap map;
TextView resteName, resteCuisine, resteLocation, resteAddress;
String restName = "nothing", obj, restCuisine = "nothing",
restLocation = "nothing", restAddress = "nothing";
Double Lang, Long;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_restraunt);
Intent i = getIntent();
obj = i.getStringExtra("restName");
getDetails(obj);
}
private void getDetails(String obj) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Restraunt");
query.getInBackground(obj, new GetCallback<ParseObject>() {
@Override
public void done(ParseObject object, ParseException e) {
if (e == null) {
restName = object.getString("Name");
restCuisine = object.getString("Cuisine");
restLocation = object.getString("Location");
restAddress = object.getString("Address");
Lang = object.getDouble("Lat");
Long = object.getDouble("Long");
} else {
e.printStackTrace();
}
}
});
// prepareMap(Lang, Long);
addData();
}
public void addData() {
resteName = (TextView) findViewById(R.id.restrauntName);
resteCuisine = (TextView) findViewById(R.id.restrauntCuisine);
resteLocation = (TextView) findViewById(R.id.restrauntLocation);
resteAddress = (TextView) findViewById(R.id.restrauntAddress);
resteName.setText(restName);
resteCuisine.setText(restCuisine);
resteLocation.setText(restLocation);
resteAddress.setText(restAddress);
}
public void prepareMap(Double Lang, Double Long) {
final LatLng REST = new LatLng(Lang, Long);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
@SuppressWarnings("unused")
Marker hamburg = map.addMarker(new MarkerOptions().position(REST)
.title("Here"));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(REST, 15));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.single_restraunt, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void Submit(View v) {
final EditText edit = (EditText) findViewById(R.id.review);
final EditText edit1 = (EditText) findViewById(R.id.rName);
String rName = edit1.getText().toString();
String review = edit.getText().toString();
ParseObject newReview = new ParseObject("Reviews");
newReview.put("Name", rName);
newReview.put("review", review);
newReview.saveInBackground();
}
}
我最初调试时没有为我的所有字符串添加任何值。当及时运行时,没有打印任何内容,表明查询没有对我的字符串进行任何更改。任何建议?