问题描述
- android这个错误怎么改啊?
-
两部分代码分开写可以,放在一起写不知道哪里错了
.import java.util.ArrayList; import java.util.List; import android.app.ActionBar; import android.app.Activity; import android.content.res.Configuration; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout.DrawerListener; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; public class MainActivity extends Activity implements OnItemClickListener, DrawerListener { private DrawerLayout drawerLayout; private ListView lv_drawer; private ArrayAdapter<String> adapter_drawer; private ArrayList<String> list_drawer; private String string_drawer; private ActionBarDrawerToggle toggle; private ListView lv_swiperefresh; private SwipeRefreshLayout swipeRefreshLayout; private ArrayAdapter<String> adapter_swipe; private ArrayList<String> list_swipe; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); drawerLayout = (DrawerLayout) findViewById(R.id.drawer); lv_drawer = (ListView) findViewById(R.id.list_drawer); list_drawer = new ArrayList<String>(); for (int i = 0; i <= 5; i++) { list_drawer.add("天香-天心" + i); } adapter_drawer = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list_drawer); lv_drawer.setAdapter(adapter_drawer); lv_drawer.setOnItemClickListener(this); ActionBar bar = getActionBar(); bar.setDisplayHomeAsUpEnabled(true); bar.setHomeButtonEnabled(true); string_drawer = (String) bar.getTitle(); toggle = new ActionBarDrawerToggle(this, drawerLayout, android.R.drawable.ic_media_play, 0, 0); drawerLayout.setDrawerListener(this); lv_swiperefresh = (ListView) findViewById(R.id.lv_swipe); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefreshlayout); list_swipe = new ArrayList<String>(); for (int i = 0; i <= 3; i++) { list_swipe.add("项目" + i); } adapter_swipe = new ArrayAdapter<String>(this, R.layout.item, R.id.lv_swipe, list_swipe); lv_swiperefresh.setAdapter(adapter_swipe); swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { new updata().execute(); } }); } private class updata extends AsyncTask<Void, Void, List<String>> { @Override protected List<String> doInBackground(Void... params) { try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } List<String> newData = new ArrayList<String>(); newData.add("新数据1"); newData.add("新数据2"); newData.add("新数据3"); return newData; } @Override protected void onPostExecute(List<String> result) { adapter_swipe.addAll(result); swipeRefreshLayout.setRefreshing(false); } } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (toggle.onOptionsItemSelected(item)) { return true; } return super.onOptionsItemSelected(item); } @Override protected void onPostCreate(Bundle savedInstanceState) { toggle.syncState(); } @Override public void onConfigurationChanged(Configuration newConfig) { toggle.onConfigurationChanged(newConfig); } @Override public void onDrawerClosed(View arg0) { getActionBar().setTitle(string_drawer); } @Override public void onDrawerOpened(View arg0) { getActionBar().setTitle("success"); } @Override public void onDrawerSlide(View arg0, float arg1) { } @Override public void onDrawerStateChanged(int arg0) { } @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(this, lv_drawer.getItemAtPosition(position).toString(), Toast.LENGTH_SHORT).show(); drawerLayout.closeDrawer(lv_drawer); } }
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.refresh_drawer_demo.MainActivity" > <android.support.v4.widget.DrawerLayout android:id="@+id/drawer" android:layout_height="match_parent" android:layout_width="match_parent"> <FrameLayout android:id="@+id/frame_drawer" android:layout_width="match_parent" android:layout_height="match_parent" > </FrameLayout> <ListView android:id="@+id/list_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:background="#ffffcc" ></ListView> </android.support.v4.widget.DrawerLayout> <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swiperefreshlayout" android:layout_width="match_parent" android:layout_height="wrap_content" > <ListView android:id="@+id/lv_swipe" android:layout_width="match_parent" android:layout_height="match_parent" > </ListView> </android.support.v4.widget.SwipeRefreshLayout> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/tv" android:layout_width="match_parent" android:layout_height="40dip" android:textColor="#000" android:gravity="center_vertical" android:textSize="18sp" /> </LinearLayout>
【错误报告】
.10-03 03:18:42.596: E/memtrack(1969): Couldn't load memtrack module (No such file or directory) 10-03 03:18:42.606: E/android.os.Debug(1969): failed to load memtrack module: -2 10-03 03:18:42.936: E/memtrack(1979): Couldn't load memtrack module (No such file or directory) 10-03 03:18:42.936: E/android.os.Debug(1979): failed to load memtrack module: -2 10-03 03:18:42.976: E/gralloc_goldfish(939): gralloc_alloc: Mismatched usage flags: 246 x 410, usage 333 10-03 03:18:42.976: E/(939): GraphicBufferAlloc::createGraphicBuffer(w=246, h=410) failed (Invalid argument), handle=0x0 10-03 03:18:42.976: E/BufferQueue(1278): [ScreenshotClient] dequeueBuffer: SurfaceComposer::createGraphicBuffer failed 10-03 03:18:43.136: E/AndroidRuntime(1991): FATAL EXCEPTION: main 10-03 03:18:43.136: E/AndroidRuntime(1991): Process: com.example.refresh_drawer_demo, PID: 1991 10-03 03:18:43.136: E/AndroidRuntime(1991): android.util.SuperNotCalledException: Activity {com.example.refresh_drawer_demo/com.example.refresh_drawer_demo.MainActivity} did not call through to super.onPostCreate() 10-03 03:18:43.136: E/AndroidRuntime(1991): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 10-03 03:18:43.136: E/AndroidRuntime(1991): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 10-03 03:18:43.136: E/AndroidRuntime(1991): at android.app.ActivityThread.access$800(ActivityThread.java:135) 10-03 03:18:43.136: E/AndroidRuntime(1991): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 10-03 03:18:43.136: E/AndroidRuntime(1991): at android.os.Handler.dispatchMessage(Handler.java:102) 10-03 03:18:43.136: E/AndroidRuntime(1991): at android.os.Looper.loop(Looper.java:136) 10-03 03:18:43.136: E/AndroidRuntime(1991): at android.app.ActivityThread.main(ActivityThread.java:5017) 10-03 03:18:43.136: E/AndroidRuntime(1991): at java.lang.reflect.Method.invokeNative(Native Method) 10-03 03:18:43.136: E/AndroidRuntime(1991): at java.lang.reflect.Method.invoke(Method.java:515) 10-03 03:18:43.136: E/AndroidRuntime(1991): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 10-03 03:18:43.136: E/AndroidRuntime(1991): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 10-03 03:18:43.136: E/AndroidRuntime(1991): at dalvik.system.NativeStart.main(Native Method) 10-03 03:18:43.366: E/gralloc_goldfish(939): gralloc_alloc: Mismatched usage flags: 246 x 410, usage 333 10-03 03:18:43.366: E/(939): GraphicBufferAlloc::createGraphicBuffer(w=246, h=410) failed (Invalid argument), handle=0x0 10-03 03:18:43.366: E/BufferQueue(1278): [ScreenshotClient] dequeueBuffer: SurfaceComposer::createGraphicBuffer failed 10-03 03:18:53.006: E/WindowManager(1278): Starting window AppWindowToken{b34da468 token=Token{b3681700 ActivityRecord{b39889b0 u0 com.example.refresh_drawer_demo/.MainActivity t5}}} timed out
解决方案
说明白点,就是**public class MainActivity extends Activity**和 private class updata extends AsyncTask
这两个类不能同时出现在一个类中,建议你最好分开写。
解决方案二:
Android 编译源码 错误
解决方案三:
把错误提示贴出来看看
解决方案四:
这个问题的直接原因是由于你忘记了 JAVA的一个class不能同时extends两个类,这是属于语法错误,建议你再看下相关的书籍就能搞定。
解决方案五:
提示信息不是说了你的onPostCreate()方法里没有调用父类方法吗?
解决方案六:
android.util.SuperNotCalledException: Activity {com.example.refresh_drawer_demo/com.example.refresh_drawer_demo.MainActivity} did not call through to super.onPostCreate()
这段看明白了吗?
解决方案七:
提示信息不是说了你的onPostCreate()方法里没有调用父类方法吗?
时间: 2025-01-30 17:41:25