我試圖把新的項目。一切slidemenu的示例項目是罰款和應用程序啓動後 我主要活動的應用程序所觸項目之一墜毀
這裏代碼的RuntimeException:無法啓動活動ComponentInfo {} com.example.PropertiesActivity
01-02 00:56:10.139: E/AndroidRuntime(28905): FATAL EXCEPTION: main
01-02 00:56:10.139: E/AndroidRuntime(28905): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.newtest/com.jeremyfeinstein.slidingmenu.example.PropertiesActivity}: java.lang.NullPointerException
01-02 00:56:10.139: E/AndroidRuntime(28905): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
01-02 00:56:10.139: E/AndroidRuntime(28905): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
01-02 00:56:10.139: E/AndroidRuntime(28905): at android.app.ActivityThread.access$600(ActivityThread.java:162)
01-02 00:56:10.139: E/AndroidRuntime(28905): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
01-02 00:56:10.139: E/AndroidRuntime(28905): at android.os.Handler.dispatchMessage(Handler.java:107)
01-02 00:56:10.139: E/AndroidRuntime(28905): at android.os.Looper.loop(Looper.java:194)
01-02 00:56:10.139: E/AndroidRuntime(28905): at android.app.ActivityThread.main(ActivityThread.java:5371)
01-02 00:56:10.139: E/AndroidRuntime(28905): at java.lang.reflect.Method.invokeNative(Native Method)
01-02 00:56:10.139: E/AndroidRuntime(28905): at java.lang.reflect.Method.invoke(Method.java:525)
01-02 00:56:10.139: E/AndroidRuntime(28905): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
01-02 00:56:10.139: E/AndroidRuntime(28905): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
01-02 00:56:10.139: E/AndroidRuntime(28905): at dalvik.system.NativeStart.main(Native Method)
01-02 00:56:10.139: E/AndroidRuntime(28905): Caused by: java.lang.NullPointerException
01-02 00:56:10.139: E/AndroidRuntime(28905): at com.jeremyfeinstein.slidingmenu.example.BaseActivity.onCreate(BaseActivity.java:54)
01-02 00:56:10.139: E/AndroidRuntime(28905): at com.jeremyfeinstein.slidingmenu.example.PropertiesActivity.onCreate(PropertiesActivity.java:25)
01-02 00:56:10.139: E/AndroidRuntime(28905): at android.app.Activity.performCreate(Activity.java:5122)
01-02 00:56:10.139: E/AndroidRuntime(28905): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1084)
01-02 00:56:10.139: E/AndroidRuntime(28905): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
01-02 00:56:10.139: E/AndroidRuntime(28905): ... 11 more
PropertiesActivity:
package com.jeremyfeinstein.slidingmenu.example;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.newtest.R;
public class PropertiesActivity extends BaseActivity {
public PropertiesActivity() {
super(R.string.properties);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setSlidingActionBarEnabled(true);
setContentView(R.layout.properties);
// left and right modes
RadioGroup mode = (RadioGroup) findViewById(R.id.mode);
mode.check(R.id.left);
mode.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
SlidingMenu sm = getSlidingMenu();
switch (checkedId) {
case R.id.left:
sm.setMode(SlidingMenu.LEFT);
sm.setShadowDrawable(R.drawable.shadow);
break;
case R.id.right:
sm.setMode(SlidingMenu.RIGHT);
sm.setShadowDrawable(R.drawable.shadowright);
break;
case R.id.left_right:
sm.setMode(SlidingMenu.LEFT_RIGHT);
sm.setSecondaryMenu(R.layout.menu_frame_two);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.menu_frame_two, new SampleListFragment())
.commit();
sm.setSecondaryShadowDrawable(R.drawable.shadowright);
sm.setShadowDrawable(R.drawable.shadow);
}
}
});
// touch mode stuff
RadioGroup touchAbove = (RadioGroup) findViewById(R.id.touch_above);
touchAbove.check(R.id.touch_above_full);
touchAbove.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.touch_above_full:
getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
break;
case R.id.touch_above_margin:
getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
break;
case R.id.touch_above_none:
getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
break;
}
}
});
// scroll scale stuff
SeekBar scrollScale = (SeekBar) findViewById(R.id.scroll_scale);
scrollScale.setMax(1000);
scrollScale.setProgress(333);
scrollScale.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) { }
@Override
public void onStartTrackingTouch(SeekBar seekBar) { }
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
getSlidingMenu().setBehindScrollScale((float) seekBar.getProgress()/seekBar.getMax());
}
});
// behind width stuff
SeekBar behindWidth = (SeekBar) findViewById(R.id.behind_width);
behindWidth.setMax(1000);
behindWidth.setProgress(750);
behindWidth.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) { }
@Override
public void onStartTrackingTouch(SeekBar seekBar) { }
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
float percent = (float) seekBar.getProgress()/seekBar.getMax();
getSlidingMenu().setBehindWidth((int) (percent * getSlidingMenu().getWidth()));
getSlidingMenu().requestLayout();
}
});
// shadow stuff
CheckBox shadowEnabled = (CheckBox) findViewById(R.id.shadow_enabled);
shadowEnabled.setChecked(true);
shadowEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked)
getSlidingMenu().setShadowDrawable(
getSlidingMenu().getMode() == SlidingMenu.LEFT ?
R.drawable.shadow : R.drawable.shadowright);
else
getSlidingMenu().setShadowDrawable(null);
}
});
SeekBar shadowWidth = (SeekBar) findViewById(R.id.shadow_width);
shadowWidth.setMax(1000);
shadowWidth.setProgress(75);
shadowWidth.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { }
@Override
public void onStartTrackingTouch(SeekBar seekBar) { }
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
float percent = (float) seekBar.getProgress()/ (float) seekBar.getMax();
int width = (int) (percent * (float) getSlidingMenu().getWidth());
getSlidingMenu().setShadowWidth(width);
getSlidingMenu().invalidate();
}
});
// fading stuff
CheckBox fadeEnabled = (CheckBox) findViewById(R.id.fade_enabled);
fadeEnabled.setChecked(true);
fadeEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
getSlidingMenu().setFadeEnabled(isChecked);
}
});
SeekBar fadeDeg = (SeekBar) findViewById(R.id.fade_degree);
fadeDeg.setMax(1000);
fadeDeg.setProgress(666);
fadeDeg.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) { }
@Override
public void onStartTrackingTouch(SeekBar seekBar) { }
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
getSlidingMenu().setFadeDegree((float) seekBar.getProgress()/seekBar.getMax());
}
});
}
}
BaseActivity:
package com.jeremyfeinstein.slidingmenu.example;
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.ListFragment;
import android.support.v4.view.ViewPager;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;
import com.newtest.R;
public class BaseActivity extends SlidingFragmentActivity {
private int mTitleRes;
protected ListFragment mFrag;
public BaseActivity(int titleRes) {
mTitleRes = titleRes;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(mTitleRes);
// set the Behind View
setBehindContentView(R.layout.menu_frame);
if (savedInstanceState == null) {
FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
mFrag = new SampleListFragment();
t.replace(R.id.menu_frame, mFrag);
t.commit();
} else {
mFrag = (ListFragment)this.getSupportFragmentManager().findFragmentById(R.id.menu_frame);
}
// customize the SlidingMenu
SlidingMenu sm = getSlidingMenu();
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setShadowDrawable(R.drawable.shadow);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setFadeDegree(0.35f);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
toggle();
return true;
case R.id.github:
Util.goToGitHub(this);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
不能發現問題,請幫我
這裏是一個代碼?BaseActivity類代碼,請 – IceJOKER
@IceJOKER對不起,這裏是代碼。 – lvl4fi4