我在 AndroidTabRestaurantDescFilterListView.java 中得到 NULL 值
过滤器.java
public class Filters extends Activity implements OnSeekBarChangeListener{
// declare text objects variables
private SeekBar PRICEbar,DISTANCEbar, RATINGbar;
private TextView PRICEtextProgress,DISTANCEtextProgress, RATINGtextProgress;
Button back;
Button FILTER;
private RadioGroup rdg;
private RadioButton indian;
private RadioButton thai;
private RadioButton chinese;
private String selectedType="";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// load the layout
setContentView(R.layout.filters);
/** Finding all the views in this Activity. */
PRICEbar = (SeekBar)findViewById(R.id.PRICEseekBarID); // make seekbar object
DISTANCEbar = (SeekBar)findViewById(R.id.DISTANCEseekBarID); // make seekbar object
RATINGbar = (SeekBar)findViewById(R.id.RATINGseekBarID); // make seekbar object
FILTER=(Button) findViewById(R.id.TopNavigationBarFilterDoneButton);
rdg = (RadioGroup) findViewById(R.id.radioGroup1);
indian = (RadioButton) findViewById(R.id.IndianRG_ID);
thai = (RadioButton) findViewById(R.id.ThaiRG_ID);
chinese = (RadioButton) findViewById(R.id.ChineseRG_ID);
back=(Button) findViewById(R.id.TopNavigationBarFilterBackButton);
back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
PRICEbar.setOnSeekBarChangeListener(this);
PRICEbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
PRICEtextProgress = (TextView)findViewById(R.id.PRICEtextViewProgressID);
PRICEtextProgress.setText("Price:: Rs "+progress);
seekBar.setMax(100);
}
});
////////////////////////////////////////////////////////
DISTANCEbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
DISTANCEtextProgress = (TextView)findViewById(R.id.DISTANCEtextViewProgressID);
DISTANCEtextProgress.setText("Distance:: "+progress);
seekBar.setMax(25);
}
});
////////////////////////////////////////////////////////
RATINGbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
RATINGtextProgress = (TextView)findViewById(R.id.RATINGtextViewProgressID);
RATINGtextProgress.setText("Rating:: "+progress);
seekBar.setMax(5);
RatingBar ratingBar = (RatingBar)findViewById(R.id.RATINGfinalvalueratingID);
ratingBar.setRating(5);
ratingBar.setFocusable(false);
RatingBar ratingBar1 = (RatingBar)findViewById(R.id.RATINGinitialvalueratingID);
ratingBar1.setRating(0);
ratingBar.setFocusable(false);
}
});
rdg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
if(i==R.id.BreakfastRG_ID){
selectedType = indian.getText().toString();
}else if(i==R.id.LunchRG_ID){
selectedType = thai.getText().toString();
}else{
selectedType = chinese.getText().toString();
}
}
});
FILTER.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent FilterIntent=new Intent(Filters.this,AndroidTabRestaurantDescFilterListView.class);
FilterIntent.putExtra("REST1",selectedType);
FilterIntent.putExtra("PriceBar", PRICEbar.getProgress());
FilterIntent.putExtra("DistanceBar", DISTANCEbar.getProgress());
FilterIntent.putExtra("RatingBar", RATINGbar.getProgress());
startActivity(FilterIntent);
}
});
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (seekBar == PRICEbar)
PRICEtextProgress.setText("Price:: Rs "+progress);
else if (seekBar == DISTANCEbar)
DISTANCEtextProgress.setText("Distance:: "+progress);
else if (seekBar == RATINGbar)
RATINGtextProgress.setText("Rating:: "+progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
}
AndroidTabRestaurantDescFilterListView.java
public class AndroidTabRestaurantDescFilterListView extends TabActivity {
// TabSpec Names
private static final String INBOX_SPEC = "Rating";
private static final String OUTBOX_SPEC = "Price";
private static final String PROFILE_SPEC = "Distance";
Button Photos;
Button Filter;
Button Search;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Photos=(Button) findViewById(R.id.PhotoButton);
Filter=(Button) findViewById(R.id.FilterButton);
Search=(Button) findViewById(R.id.SearchBottomBarID);
TabHost tabHost = getTabHost();
String REST1 = getIntent().getStringExtra("REST1");
String PriceBar = getIntent().getStringExtra("PriceBar");
String DistanceBar = getIntent().getStringExtra("DistanceBar");
String RatingBar = getIntent().getStringExtra("RatingBar");
// Tab
TabSpec inboxSpec = tabHost.newTabSpec(INBOX_SPEC);
Intent inboxIntent = new Intent(this, RatingDescriptionFilterActivity.class);
inboxIntent.putExtra("REST1", REST1);
inboxIntent.putExtra("PriceBar", PriceBar);
inboxIntent.putExtra("DistanceBar", DistanceBar);
inboxIntent.putExtra("RatingBar", RatingBar);
inboxSpec.setIndicator(INBOX_SPEC);
inboxSpec.setContent(inboxIntent);
// Tab
TabSpec PriceSpec = tabHost.newTabSpec(OUTBOX_SPEC);
Intent PriceIntent = new Intent(this, PriceDescriptionFilterActivity.class);
PriceIntent.putExtra("REST1", REST1);
PriceIntent.putExtra("PriceBar", PriceBar);
PriceIntent.putExtra("DistanceBar", DistanceBar);
PriceIntent.putExtra("RatingBar", RatingBar);
PriceSpec .setIndicator(OUTBOX_SPEC);
PriceSpec.setContent(PriceIntent);
// Tab
TabSpec DistanceSpec = tabHost.newTabSpec(PROFILE_SPEC);
Intent DistanceIntent = new Intent(this, DistanceDescriptionFilterActivity.class);
DistanceIntent.putExtra("REST1", REST1);
DistanceIntent.putExtra("PriceBar", PriceBar);
DistanceIntent.putExtra("DistanceBar", DistanceBar);
DistanceIntent.putExtra("RatingBar", RatingBar);
DistanceSpec .setIndicator(PROFILE_SPEC);
DistanceSpec.setContent(DistanceIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(inboxSpec);
tabHost.addTab(PriceSpec);
tabHost.addTab(DistanceSpec);
//Set the current value tab to default first tab
tabHost.setCurrentTab(0);
//Setting custom height for the tabs
final int height = 45;
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = height;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = height;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = height;
Photos.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent PhotoIntent=new Intent(AndroidTabRestaurantDescFilterListView.this,AndroidTabRestaurantDescImageListView.class);
startActivity(PhotoIntent);
}
});
Filter.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent FilterIntent=new Intent(AndroidTabRestaurantDescFilterListView.this,Filters.class);
startActivity(FilterIntent);
}
});
Search.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent FilterIntent=new Intent(AndroidTabRestaurantDescFilterListView.this,SearchPage.class);
startActivity(FilterIntent);
}
});
}
}
日志
10-21 19:53:11.376: E/AndroidRuntime(1393): FATAL EXCEPTION: AsyncTask #2
10-21 19:53:11.376: E/AndroidRuntime(1393): java.lang.RuntimeException: An error occured while executing doInBackground()
10-21 19:53:11.376: E/AndroidRuntime(1393): at android.os.AsyncTask$3.done(AsyncTask.java:200)
10-21 19:53:11.376: E/AndroidRuntime(1393): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
10-21 19:53:11.376: E/AndroidRuntime(1393): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
10-21 19:53:11.376: E/AndroidRuntime(1393): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
10-21 19:53:11.376: E/AndroidRuntime(1393): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-21 19:53:11.376: E/AndroidRuntime(1393): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
10-21 19:53:11.376: E/AndroidRuntime(1393): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
10-21 19:53:11.376: E/AndroidRuntime(1393): at java.lang.Thread.run(Thread.java:1096)
10-21 19:53:11.376: E/AndroidRuntime(1393): Caused by: java.lang.NullPointerException
10-21 19:53:11.376: E/AndroidRuntime(1393): at com.project.findmybuffet.RatingDescriptionFilterActivity$DownloadJSON.doInBackground(RatingDescriptionFilterActivity.java:86)
10-21 19:53:11.376: E/AndroidRuntime(1393): at com.project.findmybuffet.RatingDescriptionFilterActivity$DownloadJSON.doInBackground(RatingDescriptionFilterActivity.java:1)
10-21 19:53:11.376: E/AndroidRuntime(1393): at android.os.AsyncTask$2.call(AsyncTask.java:185)
10-21 19:53:11.376: E/AndroidRuntime(1393): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-21 19:53:11.376: E/AndroidRuntime(1393): ... 4 more
10-21 19:53:15.026: E/WindowManager(1393): Activity com.project.findmybuffet.AndroidTabRestaurantDescFilterListView has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@45fb1c10 that was originally added here
10-21 19:53:15.026: E/WindowManager(1393): android.view.WindowLeaked: Activity com.project.findmybuffet.AndroidTabRestaurantDescFilterListView has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@45fb1c10 that was originally added here
10-21 19:53:15.026: E/WindowManager(1393): at android.view.ViewRoot.<init>(ViewRoot.java:247)
10-21 19:53:15.026: E/WindowManager(1393): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
10-21 19:53:15.026: E/WindowManager(1393): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
10-21 19:53:15.026: E/WindowManager(1393): at android.view.Window$LocalWindowManager.addView(Window.java:424)
10-21 19:53:15.026: E/WindowManager(1393): at android.app.Dialog.show(Dialog.java:241)
10-21 19:53:15.026: E/WindowManager(1393): at com.project.findmybuffet.RatingDescriptionFilterActivity$DownloadJSON.onPreExecute(RatingDescriptionFilterActivity.java:77)
10-21 19:53:15.026: E/WindowManager(1393): at android.os.AsyncTask.execute(AsyncTask.java:391)
10-21 19:53:15.026: E/WindowManager(1393): at com.project.findmybuffet.RatingDescriptionFilterActivity.onCreate(RatingDescriptionFilterActivity.java:60)
10-21 19:53:15.026: E/WindowManager(1393): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-21 19:53:15.026: E/WindowManager(1393): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
10-21 19:53:15.026: E/WindowManager(1393): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
10-21 19:53:15.026: E/WindowManager(1393): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
10-21 19:53:15.026: E/WindowManager(1393): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
10-21 19:53:15.026: E/WindowManager(1393): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
10-21 19:53:15.026: E/WindowManager(1393): at android.widget.TabHost.setCurrentTab(TabHost.java:323)
10-21 19:53:15.026: E/WindowManager(1393): at android.widget.TabHost.addTab(TabHost.java:213)
10-21 19:53:15.026: E/WindowManager(1393): at com.project.findmybuffet.AndroidTabRestaurantDescFilterListView.onCreate(AndroidTabRestaurantDescFilterListView.java:87)
我的分析::
- 我能够从搜索栏获取
值
PRICEbar
,,DISTANCEbar
RATINGbar
- 我将意图传递
filter.java
给AndroidTabRestaurantDescFilterListView.java
...。所有三个都是从搜索栏获得的整数 AndroidTabRestaurantDescFilterListView.java
但是当我在下一个活动中将它们作为意图接收时,我在课堂上得到了 NULL 值
调试结果::**for **AndroidTabRestaurantDescFilterListView
this AndroidTabRestaurantDescFilterListView (id=830102681688)
tabHost TabHost (id=830102691544)
savedInstanceState null
REST1 "Chinese" (id=830102732832)
PriceBar null
DistanceBar null
为什么我在这里得到 NULL ?
我该如何调试呢?