当我触摸这个区域时,我被逼近了: 一个人很难过,这里没有 .closeDrawer(); 我不知道,我必须在哪里创建它。这是我的日志:
08-17 20:18:28.275: E/InputEventReceiver(24620): Exception dispatching input event.
08-17 20:18:28.275: E/MessageQueue-JNI(24620): Exception in MessageQueue callback: handleReceiveCallback
08-17 20:18:28.285: E/MessageQueue-JNI(24620): java.lang.NullPointerException
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.support.v4.widget.DrawerLayout.isContentView(DrawerLayout.java:805)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.support.v4.widget.DrawerLayout.onInterceptTouchEvent(DrawerLayout.java:831)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1854)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1966)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1418)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.app.Activity.dispatchTouchEvent(Activity.java:2424)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1914)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.View.dispatchPointerEvent(View.java:7564)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3883)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3778)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5419)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5399)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5370)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5493)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:182)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.os.MessageQueue.nativePollOnce(Native Method)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.os.MessageQueue.next(MessageQueue.java:132)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.os.Looper.loop(Looper.java:124)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at java.lang.reflect.Method.invokeNative(Native Method)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at java.lang.reflect.Method.invoke(Method.java:525)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at dalvik.system.NativeStart.main(Native Method)
08-17 20:18:28.285: D/AndroidRuntime(24620): Shutting down VM
08-17 20:18:28.285: W/dalvikvm(24620): threadid=1: thread exiting with uncaught exception (group=0x417fd700)
08-17 20:18:28.295: E/AndroidRuntime(24620): FATAL EXCEPTION: main
08-17 20:18:28.295: E/AndroidRuntime(24620): java.lang.NullPointerException
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.support.v4.widget.DrawerLayout.isContentView(DrawerLayout.java:805)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.support.v4.widget.DrawerLayout.onInterceptTouchEvent(DrawerLayout.java:831)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1854)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
08-17 20:18:28.295: E/AndroidRuntime(24620): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1966)
08-17 20:18:28.295: E/AndroidRuntime(24620): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1418)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.app.Activity.dispatchTouchEvent(Activity.java:2424)
08-17 20:18:28.295: E/AndroidRuntime(24620): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1914)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.View.dispatchPointerEvent(View.java:7564)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3883)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3778)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5419)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5399)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5370)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5493)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:182)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.os.MessageQueue.nativePollOnce(Native Method)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.os.MessageQueue.next(MessageQueue.java:132)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.os.Looper.loop(Looper.java:124)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-17 20:18:28.295: E/AndroidRuntime(24620): at java.lang.reflect.Method.invokeNative(Native Method)
08-17 20:18:28.295: E/AndroidRuntime(24620): at java.lang.reflect.Method.invoke(Method.java:525)
08-17 20:18:28.295: E/AndroidRuntime(24620): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-17 20:18:28.295: E/AndroidRuntime(24620): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-17 20:18:28.295: E/AndroidRuntime(24620): at dalvik.system.NativeStart.main(Native Method)
这是抽屉xml:
<ListView
android:id="@+id/left_drawer"
android:layout_width="270dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#E3E9E3"
android:dividerHeight="1dp"
android:showDividers="middle"
android:background="#F3F3F4"/>
</android.support.v4.widget.DrawerLayout>
这是我的代码:
import com.mdev.learnit.helpprogramms.Calculator;
import com.mdev.learnit.settings.AboutActivity;
import com.mdev.learnit.settings.SettingsActivity;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class StartActivity extends Activity {
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
private CharSequence mDrawerTitle;
private CharSequence mTitle;
private String[] mPlanetTitles;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drawer_main);
mTitle = mDrawerTitle = getTitle();
mPlanetTitles = getResources().getStringArray(R.array.drawer_names);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
// добавляем тень к открытому Navigation Drawer
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// прописываем адаптер к нашему списку
mDrawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_text, mPlanetTitles));
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
// делаем иконку приложения кликабельной
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
// конфигурируем нашу икноку, добавляем текст для открытия/закрытия, добавляем дополнительное изображение, которое будет обозначать открыт ли Navigation Drawer или же он закрыт
mDrawerToggle = new ActionBarDrawerToggle(
this,
mDrawerLayout,
R.drawable.ic_drawer_white,
R.string.drawer_open,
R.string.drawer_close
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
private class DrawerItemClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView parent, View view, int position,long id) {
switch(position) {
case 0:
Intent a = new Intent(StartActivity.this, AlgebraTheoryActivity.class);
startActivity(a);
break;
case 1:
Intent b = new Intent(StartActivity.this, Calculator.class);
startActivity(b);
break;
case 2:
Intent c = new Intent(StartActivity.this, SettingsActivity.class);
startActivity(c);
break;
case 3:
Intent d = new Intent(StartActivity.this, AboutActivity.class);
startActivity(d);
break;
default:
}
}
}
@Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
public boolean onOptionsItemSelected(MenuItem item) {
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
*抱歉俄罗斯评论
一个人很难过,这里没有 .closeDrawer(); 我不知道,我必须在哪里创建它。
请帮帮我。