Android报错,求指教,帮忙看看?报错-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

Android报错,求指教,帮忙看看?报错

爱吃鱼的程序员 2020-06-10 11:15:24 109

11-10 17:41:11.402: E/AndroidRuntime(31664): FATAL EXCEPTION: main
11-10 17:41:11.402: E/AndroidRuntime(31664): Process: com.example.newtour, PID: 31664
11-10 17:41:11.402: E/AndroidRuntime(31664): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.newtour/com.example.newtour.MenuActivity}: java.lang.NullPointerException
11-10 17:41:11.402: E/AndroidRuntime(31664): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2187)
11-10 17:41:11.402: E/AndroidRuntime(31664): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236)
11-10 17:41:11.402: E/AndroidRuntime(31664): at android.app.ActivityThread.access$800(ActivityThread.java:138)
11-10 17:41:11.402: E/AndroidRuntime(31664): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
11-10 17:41:11.402: E/AndroidRuntime(31664): at android.os.Handler.dispatchMessage(Handler.java:102)
11-10 17:41:11.402: E/AndroidRuntime(31664): at android.os.Looper.loop(Looper.java:136)
11-10 17:41:11.402: E/AndroidRuntime(31664): at android.app.ActivityThread.main(ActivityThread.java:5014)
11-10 17:41:11.402: E/AndroidRuntime(31664): at java.lang.reflect.Method.invokeNative(Native Method)
11-10 17:41:11.402: E/AndroidRuntime(31664): at java.lang.reflect.Method.invoke(Method.java:515)
11-10 17:41:11.402: E/AndroidRuntime(31664): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:805)
11-10 17:41:11.402: E/AndroidRuntime(31664): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:621)
11-10 17:41:11.402: E/AndroidRuntime(31664): at dalvik.system.NativeStart.main(Native Method)
11-10 17:41:11.402: E/AndroidRuntime(31664): Caused by: java.lang.NullPointerException
11-10 17:41:11.402: E/AndroidRuntime(31664): at com.example.newtour.ResideMenu.setBackground(ResideMenu.java:103)
11-10 17:41:11.402: E/AndroidRuntime(31664): at com.example.newtour.MenuActivity.setUpMenu(MenuActivity.java:46)
11-10 17:41:11.402: E/AndroidRuntime(31664): at com.example.newtour.MenuActivity.onCreate(MenuActivity.java:31)
11-10 17:41:11.402: E/AndroidRuntime(31664): at android.app.Activity.performCreate(Activity.java:5251)
11-10 17:41:11.402: E/AndroidRuntime(31664): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-10 17:41:11.402: E/AndroidRuntime(31664): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2151)



public class MenuActivity extends FragmentActivity implements OnClickListener  {




private ResideMenu resideMenu;
private MenuActivity mContext;


/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mContext = this;
setUpMenu();
initFragment();

}
private void initFragment(){
FragmentManager fm=getSupportFragmentManager();
FragmentTransaction transaction=fm.beginTransaction();
transaction.replace(R.id.s_residmenu, new LeftMenuFragment());
transaction.replace(R.id.fl_main, new ContentFragment());

}
private void setUpMenu() {


// attach to current activity;
resideMenu = new ResideMenu(this);
resideMenu.setBackground(R.drawable.guide_6);//侧滑栏背景图
resideMenu.attachToActivity(this);
resideMenu.setMenuListener(menuListener);


// create menu items;
String titles[] = { "北京", "上海", "广州", "深圳","四川","香港","大连","成都","洛阳","福建","天津","厦门" };
//,"四川","香港","大连","成都","洛阳"
int icon[] = { R.drawable.icon_home, R.drawable.icon_profile,
R.drawable.icon_calendar, R.drawable.icon_settings ,R.drawable.icon_profile
,R.drawable.icon_calendar,R.drawable.icon_profile,R.drawable.icon_profile,R.drawable.icon_calendar
,R.drawable.icon_calendar,R.drawable.icon_calendar,R.drawable.icon_calendar};


for (int i = 0; i < titles.length; i++) {
ResideMenuItem item = new ResideMenuItem(this, icon[i], titles[i]);
item.setOnClickListener(this);
resideMenu.addMenuItem(item);
}


// add gesture operation's ignored views


}

@Override
public void onClick(View view) {
resideMenu.closeMenu();
}


private ResideMenu.OnMenuListener menuListener = new ResideMenu.OnMenuListener() {
@Override
public void openMenu() {

}


@Override
public void closeMenu() {

}
};




@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
return resideMenu.onInterceptTouchEvent(ev)
|| super.dispatchTouchEvent(ev);
}






}

public class ResideMenu extends FrameLayout implements
GestureDetector.OnGestureListener {


private ImageView iv_shadow;
private ImageView iv_background;

<p>
	/**<br>
  • set the menu background picture;

  • @param imageResrouce
    */
    public void setBackground(int imageResrouce) {
    iv_background.setImageResource(imageResrouce);
    }

    }


Android开发
分享到
取消 提交回答
全部回答(1)
  • 爱吃鱼的程序员
    2020-06-10 11:15:42
    atcom.example.newtour.ResideMenu.setBackground(ResideMenu.java:103)
    11-1017:41:11.402:E/AndroidRuntime(31664):atcom.example.newtour.MenuActivity.setUpMenu(MenuActivity.java:46)

    11-1017:41:11.402:E/AndroidRuntime(31664):atcom.example.newtour.MenuActivity.onCreate(MenuActivity.java:31)


    空指针呀

    0 0
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

推荐文章
相似问题
推荐课程