Android中,一个activity如何和另外一个activity的Fragment通信?

Android中,一个activity如何和另外一个activity的Fragment通信

7个回答

可以试试广播,也许可以解决

在一个进程里么,用public的静态变量好了

intent带参也可以做到。

ljheee
ljheee 回复viewgroup: 恩恩,是这种情况,B里有多个Fragment,
2 年多之前 回复
viewgroup
viewgroup 比如Activity A 对B立面的C Fragment通信,假设B里有多个Fragment,那么A可以这么写,intent.put("fName(fTag))",c);然后后面携带C需要的参数。这样B就知道要找到C
2 年多之前 回复

两个activity先传值,然后再activity和fragment之间再传值,笨办法。不推荐静态变量,隐藏的大坑,不要轻易尝试。

直接用handler不可以实现吗?

两个activity之间传值会吗,activity和自己的fragment之间传值会吗

一般的可以使用本地广播 LocalBroadcastManager

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
新手问一下, android中setAdapter的空指针问题
代码如下: package com.example.fragmentbestpractice; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; public class NewsTitleFragment extends Fragment implements OnItemClickListener { private ListView titleListView; private List<News> newsList; private NewsAdapter adapter; private boolean isTwoPane; @Override public void onAttach(Activity activity) { super.onAttach(activity); newsList = getNews(); adapter = new NewsAdapter(activity, R.layout.news_item, newsList); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view = inflater .inflate(R.layout.news_title_frag, container, false); titleListView = (ListView) view .findViewById(R.id.title_list); titleListView.setAdapter(adapter); titleListView.setOnItemClickListener(this); return view; } @Override public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); if (getActivity().findViewById(R.id.news_content_layout) != null) { isTwoPane = true; } else { isTwoPane = false; } } @Override public void onItemClick(AdapterView<?> arg0, View view, int position, long id) { News news = newsList.get(position); if (isTwoPane) { NewsContentFragment newsContentFragment = (NewsContentFragment) getFragmentManager() .findFragmentById(R.id.news_content_fragment); newsContentFragment.refresh(news.getTitle(), news.getContent()); } else { NewsContentActivity.actionStart(getActivity(), news.getTitle(), news.getContent()); } } public List<News> getNews() { List<News> newslist = new ArrayList<News>(); News news1 = new News(); news1.setTitle("hahahaahhaahahahhahahaha"); news1.setContent("hohohohohohhohohohohohohohohohohoho" + "hohohohohohohohohohohohohohohohohohohohohohohoh"); newslist.add(news1); News news2 = new News(); news2.setTitle("qoqoqoqoqqoqoqoqoqoqoqoqoqoqo"); news2.setContent("bobobobobobobbobobobbo" + "bobobobobobobobobobobbobobobobbobobobobob" + "bobobooboobobobbobhahahahdhdhabobobobobobobobob"); newslist.add(news2); return newsList; } } 日志中错误提示在这一句中: titleListView.setAdapter(adapter); 网上查了一天了,还是找不到原因,求大神们指教
android 中 fragment 嵌入listview
首先在MainActivity中 ``` public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } ``` 然后在主布局activity_main中只有一个fragment ``` <fragment android:id="@+id/title_fragment" android:layout_width="wrap_content" android:layout_height="wrap_content" android:name="com.example.news.TitleFragment" /> ``` 在com.example.news.TitleFragment里面 我定义了listview ,和自己定义的newsadapter适配器, 还有要装入listview中的数据data。 代码如下: ``` public class TitleFragment extends Fragment implements OnItemClickListener { private NewsAdapter adapter; private List<News> data; private ListView listView; private boolean isTwoPane; @Override public void onAttach(Activity activity) { // TODO Auto-generated method stub super.onAttach(activity); adapter = new NewsAdapter(activity, R.layout.title_list_item, data); data = getNews(); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub Log.i("test", "onCreateView"); View view = inflater.inflate(R.layout.title_frag, container, false); listView = (ListView) view.findViewById(R.id.listView1); listView.setAdapter(adapter); // listView.setOnItemClickListener(this); return view; } private List<News> getNews() { List<News> data = new ArrayList<News>(); News news1 = new News(); news1.setTitle("chongqing is beautiful city!!!"); news1.setContext("There have everything in ChongQing,delicious food ,great building and hot girls "); data.add(news1); News news2 = new News(); news2.setTitle("chongqing is beautiful city2222!!!"); news2.setContext("There have everything in ChongQing,delicious food ,great building and hot girls "); data.add(news2); return data; } @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub } } ``` 在newsadapter适配器: 我试过不用自己定义的适配器就可以,但是用自己定义的适配器就会出错,但是我不知道到底错误在哪。 代码如下: ``` public class NewsAdapter extends ArrayAdapter<News> { private int resourceId; public NewsAdapter(Context context, int textViewResourceId, List<News> objects) { super(context, textViewResourceId, objects); // TODO Auto-generated constructor stub resourceId = textViewResourceId; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub News news = getItem(position); View view; if (convertView == null) { view = LayoutInflater.from(getContext()).inflate(resourceId, null); } else { view = convertView; } TextView titleText = (TextView) view.findViewById(R.id.title); titleText.setText(news.getTitle()); return view; } } ``` R.layout.title_list_item代码: ``` <TextView android:id="@+id/title" android:layout_width="match_parent" android:layout_height="wrap_content" > </TextView> ``` 最后就出现binary xml file line #11:error inflating class fragment 错误。 本人安卓小白一名,求大神告诉我到底哪里错了呀。跪谢
隐藏和显示 Fragment 时显示错误的 fragment
第一次我把程序中的fragments的可见性改变了, fragment显示的不是我设置的。 My layout: <LinearLayout 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:orientation="vertical" tools:context=".MainActivity" > <fragment android:id="@+id/act_main_frag_top_bar" class="br.com.myapp.fragments.TopBarFragment" android:layout_height="wrap_content" android:layout_width="match_parent"/> <fragment android:id="@+id/act_main_frag_toolbar" class="br.com.myapp.fragments.ToolbarFragment" android:layout_height="wrap_content" android:layout_width="match_parent"/> <!-- Tabs --> <fragment android:id="@+id/act_main_frag_twitter" class="br.com.myapp.fragments.TwitterFragment" android:layout_height="match_parent" android:layout_width="match_parent" android:visibility="gone"/> <fragment android:id="@+id/act_main_frag_facebook" class="br.com.myapp.fragments.FacebookFragment" android:layout_height="match_parent" android:layout_width="match_parent" android:visibility="gone"/> <fragment android:id="@+id/act_main_frag_tv_show" class="br.com.myapp.fragments.TVShowFragment" android:layout_height="match_parent" android:layout_width="match_parent" android:visibility="gone"/> <fragment android:id="@+id/act_main_frag_info" class="br.com.bluepen.mixtv.fragments.InfoFragment" android:layout_height="match_parent" android:layout_width="match_parent" android:visibility="gone"/> </LinearLayout> myActivity: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FragmentManager manager = getSupportFragmentManager(); mStreamingFrag = (StreamingFragment) manager.findFragmentById(R.id.act_main_frag_streaming); mFacebookFrag = (FacebookFragment) manager.findFragmentById(R.id.act_main_frag_facebook); mTwitterFrag = (TwitterFragment) manager.findFragmentById(R.id.act_main_frag_twitter); mTVShowFrag = (TVShowFragment) manager.findFragmentById(R.id.act_main_frag_tv_show); mInfoFrag = (InfoFragment) manager.findFragmentById(R.id.act_main_frag_info); mToolbar = (ToolbarFragment) manager.findFragmentById(R.id.act_main_frag_toolbar); mToolbar.setListener(this); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.show(mStreamingFrag); transaction.commit(); } 在onCreate方法执行后,fragment显示的是 TwitterFragment,而不是我在onCreate方法的最后设置的StreamingFragment 。
android 用fragment里的这个intent,点击按钮无法跳转到下一个活动呢
public class SponsorGroupActivityFragment extends Fragment { private Button createNewGroupActivity; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.sponsor_group_activity_frag,container,false); createNewGroupActivity = (Button) view.findViewById(R.id.create_new_group_activity); createNewGroupActivity.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(),CreateGroupActivityActivity.class); startActivity(intent); } }); return view; } }
Android使用Xutils3下载安装apk报错问题,求解
1.根据xutils3的文档说明,创建了一个类对xutils进行初始化 ``` public class MyApp extends Application { @Override public void onCreate() { super.onCreate(); x.Ext.init(this); x.Ext.setDebug(false); } } ``` 2.然后在配置文件中做了如下配置 ``` <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.gao.mysafe"> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.INSTALL_PACKAGES" tools:ignore="ProtectedPermissions" /> <application android:name=".MyApp" android:allowBackup="true" android:icon="@mipmap/safe_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".SplashActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity"></activity> </application> </manifest> ``` 3.在activity中调用了xutils的下载方法 ``` //apk下载地址,放置apk的路径 //1.获取sd卡路径 String path = Environment.getExternalStorageDirectory().getPath() + "/mysafe.apk"; //2.发送请求,获取apk,并放到指定路径 RequestParams rp = new RequestParams(url); rp.setSaveFilePath(path); rp.setAutoRename(true); x.http().get(rp, new Callback.ProgressCallback<File>() { //下载成功 @Override public void onSuccess(File result) { ToastUtils.show(SplashActivity.this, "下载成功,开始安装!!"); installAPK(result); } //下载出现问题 @Override public void onError(Throwable ex, boolean isOnCallback) { } @Override public void onCancelled(CancelledException cex) { } @Override public void onFinished() { } @Override public void onWaiting() { } //刚刚开始下载 @Override public void onStarted() { } //下载过程中方法 @Override public void onLoading(long total, long current, boolean isDownloading) { } }); ``` 然后在模拟器中出现了如下问题 ``` D/dalvikvm: Not late-enabling CheckJNI (already on) I/InstantRun: Instant Run Runtime started. Android package is com.gao.mysafe, real application class is com.gao.mysafe.MyApp. W/InstantRun: No instant run dex files added to classpath D/dalvikvm: GC_FOR_ALLOC freed 68K, 5% free 2929K/3056K, paused 2ms, total 3ms I/dalvikvm-heap: Grow heap (frag case) to 34.554MB for 33177612-byte allocation D/dalvikvm: GC_FOR_ALLOC freed <1K, 1% free 35328K/35460K, paused 5ms, total 5ms D/OpenGLRenderer: Enabling debug mode 0 I/dalvikvm: Could not find method android.view.Window$Callback.onProvideKeyboardShortcuts, referenced from method android.support.v7.view.WindowCallbackWrapper.onProvideKeyboardShortcuts W/dalvikvm: VFY: unable to resolve interface method 16550: Landroid/view/Window$Callback;.onProvideKeyboardShortcuts (Ljava/util/List;Landroid/view/Menu;I)V D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002 W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;) I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested W/dalvikvm: VFY: unable to resolve interface method 16552: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002 I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode W/dalvikvm: VFY: unable to resolve interface method 16556: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode; D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002 I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations W/dalvikvm: VFY: unable to resolve virtual method 747: Landroid/content/res/TypedArray;.getChangingConfigurations ()I D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType W/dalvikvm: VFY: unable to resolve virtual method 769: Landroid/content/res/TypedArray;.getType (I)I D/dalvikvm: VFY: replacing opcode 0x6e at 0x0008 I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable W/dalvikvm: VFY: unable to resolve virtual method 710: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable; D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity W/dalvikvm: VFY: unable to resolve virtual method 712: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable; D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering W/dalvikvm: VFY: unable to resolve instanceof 158 (Landroid/graphics/drawable/RippleDrawable;) in Landroid/support/v7/widget/AppCompatImageHelper; D/dalvikvm: VFY: replacing opcode 0x20 at 0x000c I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method android.support.v7.content.res.AppCompatResources.getColorStateList W/dalvikvm: VFY: unable to resolve virtual method 470: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList; D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006 ``` 4.调用安装方法后也出现了错误 ``` private void installAPK(File file) { //系统应用界面,源码,安装apk入口 Intent intent = new Intent(Intent.ACTION_VIEW); intent.addCategory("android.intent.category.DEFAULT"); //文件作为数据源 intent.setData(Uri.fromFile(file)); //设置安装类型 intent.setType("application/vnd.android.package-archive"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); /* 也可以用下面代码一行完成 intent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive"); */ try{ startActivityForResult(intent, 0); }catch (Exception e){ e.printStackTrace(); } } ``` 问题如下: ``` D/dalvikvm: GC_FOR_ALLOC freed 422K, 2% free 36957K/37436K, paused 3ms, total 3ms W/System.err: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW cat=[android.intent.category.DEFAULT] typ=application/vnd.android.package-archive flg=0x10000000 } W/System.err: at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632) W/System.err: at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424) W/System.err: at android.app.Activity.startActivityForResult(Activity.java:3424) W/System.err: at android.app.Activity.startActivityForResult(Activity.java:3385) W/System.err: at com.gao.mysafe.SplashActivity.installAPK(SplashActivity.java:338) W/System.err: at com.gao.mysafe.SplashActivity.access$500(SplashActivity.java:30) W/System.err: at com.gao.mysafe.SplashActivity$6.onSuccess(SplashActivity.java:280) W/System.err: at com.gao.mysafe.SplashActivity$6.onSuccess(SplashActivity.java:275) W/System.err: at org.xutils.http.HttpTask.onSuccess(HttpTask.java:447) W/System.err: at org.xutils.common.task.TaskProxy$InternalHandler.handleMessage(TaskProxy.java:198) W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102) W/System.err: at android.os.Looper.loop(Looper.java:136) W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5017) W/System.err: at java.lang.reflect.Method.invokeNative(Native Method) W/System.err: at java.lang.reflect.Method.invoke(Method.java:515) W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) W/System.err: at dalvik.system.NativeStart.main(Native Method) ``` 弄了半天不知道是什么问题,在真机上也不好使,安装不上,求大神解答一下,谢谢了!!
android给listview添加下拉刷新崩溃
logcat: 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi W/dalvikvm﹕ VFY: unable to resolve virtual method 12221: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi W/dalvikvm﹕ VFY: unable to resolve virtual method 9785: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi W/dalvikvm﹕ VFY: unable to resolve virtual method 396: Landroid/content/res/TypedArray;.getChangingConfigurations ()I 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi W/dalvikvm﹕ VFY: unable to resolve virtual method 418: Landroid/content/res/TypedArray;.getType (I)I 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawable 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi W/dalvikvm﹕ VFY: unable to resolve virtual method 359: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable; 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawableForDensity 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi W/dalvikvm﹕ VFY: unable to resolve virtual method 361: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable; 10-09 15:17:36.549 15984-15984/com.example.jkd.fchangshi D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 10-09 15:17:36.599 15984-15984/com.example.jkd.fchangshi I/dalvikvm-heap﹕ Grow heap (frag case) to 26.484MB for 9000016-byte allocation 10-09 15:17:36.629 15984-15984/com.example.jkd.fchangshi D/AndroidRuntime﹕ Shutting down VM 10-09 15:17:36.629 15984-15984/com.example.jkd.fchangshi W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x415e8d58) 10-09 15:17:36.629 15984-15984/com.example.jkd.fchangshi E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.jkd.fchangshi, PID: 15984 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jkd.fchangshi/com.example.jkd.fchangshi.MainActivity}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2190) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250) at android.app.ActivityThread.access$800(ActivityThread.java:139) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5049) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:818) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at com.example.jkd.fchangshi.MainActivity$PlaceholderFragment.onCreateView(MainActivity.java:295) at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:953) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499) at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:548) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171) at android.app.Activity.performStart(Activity.java:5303) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2163)             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)             at android.app.ActivityThread.access$800(ActivityThread.java:139)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)             at android.os.Handler.dispatchMessage(Handler.java:102)             at android.os.Looper.loop(Looper.java:136)             at android.app.ActivityThread.main(ActivityThread.java:5049)             at java.lang.reflect.Method.invokeNative(Native Method)             at java.lang.reflect.Method.invoke(Method.java:515)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:818)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634)             at dalvik.system.NativeStart.main(Native Method) 10-09 15:17:36.759 15984-16013/com.example.jkd.fchangshi I/System.out﹕ 获取成功 10-09 15:17:36.829 15984-16013/com.example.jkd.fchangshi I/System.out﹕ 转字符串成功
运行到setContentView这里崩溃了
这是第一行代码里面的一个项目,运行后崩溃: ![图片说明](https://img-ask.csdn.net/upload/201702/12/1486848687_748230.jpg) MainActivity.java ``` package com.example.newsapp; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.Window; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } ``` News.java ``` package com.example.newsapp; public class News { private String title; private String content; public String getTitle() { return title; } public void setTitle(String title) { this.title=title; } public String getContent() { return content; } public void setContent(String content) { this.content=content; } } ``` NewsAdapter.java ``` package com.example.newsapp; import java.util.List; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; public class NewsAdapter extends ArrayAdapter<News> { private int resourceId; public NewsAdapter(Context context,int textViewResourceId,List<News> objects) { super(context,textViewResourceId,objects); resourceId=textViewResourceId; } @Override public View getView(int position,View convertView,ViewGroup parent) { News news=getItem(position); View view; if (convertView==null) { view=LayoutInflater.from(getContext()).inflate(resourceId,null); } else { view=convertView; } TextView newsTitleText=(TextView)view.findViewById(R.id.news_title); newsTitleText.setText(news.getTitle()); return view; } } ``` NewsContentActivity.java ``` package com.example.newsapp; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.view.Window; public class NewsContentActivity extends FragmentActivity { public static void actionStart(Context context,String newsTitle,String newsContent) { Intent intent=new Intent(context,NewsContentActivity.class ); intent.putExtra("news_title",newsTitle); intent.putExtra("news_content",newsContent); context.startActivity(intent); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.news_content); FragmentManager fragmentManager=getSupportFragmentManager(); String newsTitle=getIntent().getStringExtra("news_title"); String newsContent=getIntent().getStringExtra("news_content"); NewsContentFragment newsContentFragment=(NewsContentFragment)fragmentManager.findFragmentById(R.id.news_content_fragment); newsContentFragment.refresh(newsTitle,newsContent); } } ``` NewsContentFragment.java ``` package com.example.newsapp; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class NewsContentFragment extends Fragment { private View view; @Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) { view=inflater.inflate(R.layout.news_content_frag,container,false ); return view; } public void refresh(String newsTitle,String newsContent) { View visibilityLayout=view.findViewById(R.id.visibility_layout); visibilityLayout.setVisibility(View.VISIBLE); TextView newsTitleText=(TextView)view.findViewById(R.id.news_title); TextView newsContentText=(TextView)view.findViewById(R.id.news_content); newsTitleText.setText(newsTitle); newsContentText.setText(newsContent); } } ``` NewsTitleFragment.java ``` package com.example.newsapp; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; public class NewsTitleFragment extends Fragment implements OnItemClickListener { private ListView newsTitleListView; private List<News> newsList; private NewsAdapter adapter; private boolean isTwoPane; @Override public void onAttach(Activity activity) { super.onAttach(activity); newsList=getNews(); adapter=new NewsAdapter(activity,R.layout.news_item,newsList); } @Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) { View view=inflater.inflate(R.layout.news_title_frag,container,false ); newsTitleListView=(ListView)view.findViewById(R.id.news_title_list_view); newsTitleListView.setAdapter(adapter); newsTitleListView.setOnItemClickListener(this ); return view; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (getActivity().findViewById(R.id.news_content_layout)!=null ) isTwoPane=true; else isTwoPane=false; } @Override public void onItemClick(AdapterView<?> parent,View view,int position,long id) { News news=newsList.get(position); if (isTwoPane) { NewsContentFragment newsContentFragment=(NewsContentFragment)getFragmentManager().findFragmentById(R.id.news_content_fragment); newsContentFragment.refresh(news.getTitle(),news.getContent()); } else { NewsContentActivity.actionStart(getActivity(),news.getTitle(),news.getContent()); } } private List<News> getNews() { List<News> newsList=new ArrayList<News>(); News news1=new News(); news1.setTitle("标题"); news1.setContent("内容"); newsList.add(news1); News news2=new News(); news2.setTitle("日记"); news2.setContent("去旅游"); newsList.add(news2); return newsList; } } ```
Android,Fragment使用AsyncHttpClient数据不显示
先贴代码: NewsFragment.java ``` public class NewsFragment extends Fragment { private final static String TAG = "NewsFragment"; Activity activity; ArrayList<NewsEntity> newsList = new ArrayList<NewsEntity>(); HeadListView mListView; NewsAdapter mAdapter; int channel_id; ImageView detail_loading; public final static int SET_NEWSLIST = 0; /** 此方法意思为fragment是否可见 ,可见时候加载数据 */ @Override public void setUserVisibleHint(boolean isVisibleToUser) { //onCreateView之前调用的 if (isVisibleToUser) { System.out.println("isVisibleToUser"); System.out.println(channel_id); if (channel_id == 0) { channel_id = 1; } initData(); //fragment可见时加载数据 if(newsList !=null && newsList.size() !=0){ System.out.println("newList not null"); handler.obtainMessage(SET_NEWSLIST).sendToTarget(); }else{ System.out.println("newList null"); new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(2); } catch (InterruptedException e) { e.printStackTrace(); } handler.obtainMessage(SET_NEWSLIST).sendToTarget(); } }).start(); } }else{ System.out.println("isNotVisibleToUser"); //fragment不可见时不执行操作 } super.setUserVisibleHint(isVisibleToUser); } // OnPageChangeListener @Override public void onAttach(Activity activity) { System.out.println("news_frag_onAttach"); this.activity = activity; super.onAttach(activity); } @Override public void onCreate(Bundle savedInstanceState) { System.out.println("news_frag_onCreate"); Bundle args = getArguments(); //传值 // text = args != null ? args.getString("text") : ""; channel_id = args != null ? args.getInt("id", 0) : 0; System.out.println("NewsFragment_channel_id:"+channel_id); if (getUserVisibleHint()) { System.out.println("onCreate_getUserVisibleHint"); } super.onCreate(savedInstanceState); } @SuppressLint("InflateParams") @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { System.out.println("news_frag_onCreateView"); View view = LayoutInflater.from(getActivity()).inflate(R.layout.news_fragment, null); mListView = (HeadListView) view.findViewById(R.id.mListView); detail_loading = (ImageView)view.findViewById(R.id.detail_loading); return view; } private void initData() { //newsList.clear(); newsList = Constants2.getNewsList(channel_id); } @SuppressLint("HandlerLeak") Handler handler = new Handler() { @Override public void handleMessage(Message msg) { System.out.println("handler:"+msg.what); switch (msg.what) { case SET_NEWSLIST: detail_loading.setVisibility(View.GONE); if(mAdapter == null){ mAdapter = new NewsAdapter(activity, newsList); //判断是不是城市的频道 if(channel_id == Constants2.CHANNEL_CITY){ //是城市频道 mAdapter.setCityChannel(true); initCityChannel(); } } mListView.setAdapter(mAdapter); mListView.setOnScrollListener(mAdapter); mListView.setPinnedHeaderView(LayoutInflater.from(activity).inflate(R.layout.list_item_section, mListView, false)); mListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(activity, DetailsActivity.class); if(channel_id == Constants2.CHANNEL_CITY){ if(position != 0){ intent.putExtra("news", mAdapter.getItem(position - 1)); startActivity(intent); activity.overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left); } }else{ intent.putExtra("news", mAdapter.getItem(position)); startActivity(intent); activity.overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left); } } }); break; default: break; } super.handleMessage(msg); } }; /* 初始化选择城市的header*/ @SuppressLint("InflateParams") public void initCityChannel() { View headview = LayoutInflater.from(activity).inflate(R.layout.city_category_list_tip, null); TextView chose_city_tip = (TextView) headview.findViewById(R.id.chose_city_tip); chose_city_tip.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(activity, CityListActivity.class); startActivity(intent); } }); mListView.addHeaderView(headview); } /* 摧毁视图 */ @Override public void onDestroyView() { super.onDestroyView(); Log.d("onDestroyView", "channel_id = " + channel_id); mAdapter = null; } /* 摧毁该Fragment,一般是FragmentActivity 被摧毁的时候伴随着摧毁 */ @Override public void onDestroy() { super.onDestroy(); Log.d(TAG, "channel_id = " + channel_id); } } ``` Contants2.java ``` public class Constants2 { public static final String GET_NEWS_URL = AppApplication.NEWS_URL+"/getNewsJSON.php"; public static final String GET_Comment_URL = AppApplication.NEWS_URL+"/commentlist.php"; static ArrayList<NewsEntity> newsList = new ArrayList<NewsEntity>(); static ArrayList<CommentEntity> commentList = new ArrayList<CommentEntity>(); static JSONArray jsonArray; static JSONArray commentJsonArray; /* * 获取新闻列表 */ public static ArrayList<NewsEntity> getNewsList(int channel_id) { AsyncHttpClient client = new AsyncHttpClient(); RequestParams params = new RequestParams(); params.add("channel_id", String.valueOf(channel_id)); System.out.println("Constants2_channel_id:"+String.valueOf(channel_id)); client.post(GET_NEWS_URL, params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int i, Header[] handler, byte[] bytes) { String response = new String(bytes); Log.e("debug","response:"+response); try { jsonArray = new JSONArray(response); } catch (JSONException e) { System.err.println("newslist_jsonArray_error"); e.printStackTrace(); } } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { System.out.println("数据错误!!"); } }); if (jsonArray != null) { System.out.println("/////////////////////////"); System.out.println(jsonArray.length()); newsList.clear(); for(int i =0 ; i < jsonArray.length() ; i++){ try { JSONObject obj = jsonArray.getJSONObject(i); NewsEntity news = new NewsEntity(); news.setId(i); news.setNewsId(obj.getString("newsId")); news.setCollectStatus(false); news.setCommentNum(i + 10); news.setInterestedStatus(true); news.setLikeStatus(true); news.setReadStatus(false); news.setNewsCategory("推荐"); news.setNewsCategoryId(1); news.setSource_url(""); news.setTitle(obj.getString("title")); List<String> url_list = new ArrayList<String>(); news.setPicOne(obj.getString("pic_url")); url_list.add(obj.getString("pic_url")); news.setPicList(url_list); news.setReporter(obj.getString("reporter")); news.setPublishTime(obj.getString("time")); news.setReadStatus(false); news.setSource("手机腾讯网"); news.setContent(obj.getString("content")); news.setSummary("腾讯数码讯(编译:Gin)谷歌眼镜可能是目前最酷的可穿戴数码设备,你可以戴着它去任何地方(只要法律法规允许或是没有引起众怒),作为手机的第二块“增强现实显示屏”来使用。另外,虽然它仍未正式销售,但谷歌近日在美国市场举行了仅限一天的开放购买活动,价格则为1500美元(约合人民币9330元),虽然仍十分昂贵,但至少可以满足一些尝鲜者的需求,也预示着谷歌眼镜的公开大规模销售离我们越来越近了。"); news.setMark(i); news.setIsLarge(false); if(i == 2){ news.setComment("评论部分,说的非常好。"); } // news.setPublishTime(Long.valueOf(obj.getString("time"))); if(i <= 2){ news.setPublishTime(DateTools.getTime()); }else if(i >2 && i <= 5){ news.setPublishTime(String.valueOf(Long.valueOf(DateTools.getTime()) - 86400)); }else{ news.setPublishTime(String.valueOf(Long.valueOf(DateTools.getTime()) - 86400 * 2)); } newsList.add(news); } catch (JSONException e) { e.printStackTrace(); } } } return newsList; } } ``` 流程是这样: 当前fragment可视时通过initData()加载数据,就是调用Constants2的getNewsList(channel_id) 方法,_该方法执行异步任务返回一个newsList,现在的问题是首次加载的时候数据显示,请问有什么解决方法?
关于BaseAdapter的问题
我需要显示图片代码是这样的: @Override public View getView(int position, View convertView, ViewGroup parent) { final int index = position % (myBookData.size()); Log.e("sxy", "index="+index); ImageView iv; if(convertView == null) { iv = new ImageView(parent.getContext()); } else { iv = (ImageView) convertView; } Bitmap logo = null; MyBook myBook = myBookData.get(index); if(myBook != null) { logo = myBook.bitmap; } if(logo == null) { logo = BitmapFactory.decodeResource(getResources(), R.drawable.update_bookdef_bg); } Drawable dIcon = new BitmapDrawable(ImageUtils.addDecoratedIcon(ActSelBook.this, logo)); iv.setImageDrawable(dIcon); iv.setTag(myBook); iv.setLayoutParams(new Gallery.LayoutParams(230, 325)); iv.setScaleType(ImageView.ScaleType.CENTER_INSIDE); return iv; } 可是却总是报错: 01-26 15:50:46.801: I/ActSelBook(11385): myBookData.size()=6 01-26 15:50:46.811: E/InputEventReceiver(11385): Exception dispatching input event. 01-26 15:50:46.811: D/AndroidRuntime(11385): Shutting down VM 01-26 15:50:46.811: W/dalvikvm(11385): threadid=1: thread exiting with uncaught exception (group=0x417fc270) 01-26 15:50:46.811: E/AndroidRuntime(11385): FATAL EXCEPTION: main 01-26 15:50:46.811: E/AndroidRuntime(11385): Process: com.noahedu.ampmlistening, PID: 11385 01-26 15:50:46.811: E/AndroidRuntime(11385): java.lang.NullPointerException 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewGroup.canViewReceivePointerEvents(ViewGroup.java:2140) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:1492) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.View.dispatchGenericMotionEvent(View.java:7777) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:1824) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:1551) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.View.dispatchGenericMotionEvent(View.java:7777) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:1824) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:1551) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.View.dispatchGenericMotionEvent(View.java:7777) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:1824) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:1551) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.View.dispatchGenericMotionEvent(View.java:7777) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:1824) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:1551) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.View.dispatchGenericMotionEvent(View.java:7777) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:1824) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:1551) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.View.dispatchGenericMotionEvent(View.java:7777) 01-26 15:50:46.811: E/AndroidRuntime(11385): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchGenericMotionEvent(PhoneWindow.java:2195) 01-26 15:50:46.811: E/AndroidRuntime(11385): at com.android.internal.policy.impl.PhoneWindow.superDispatchGenericMotionEvent(PhoneWindow.java:1533) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.app.Activity.dispatchGenericMotionEvent(Activity.java:2494) 01-26 15:50:46.811: E/AndroidRuntime(11385): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchGenericMotionEvent(PhoneWindow.java:2149) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.View.dispatchPointerEvent(View.java:7893) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4034) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3913) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3479) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3529) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3498) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3605) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3506) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3662) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3479) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3529) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3498) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3506) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3479) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5682) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5662) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5633) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5762) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:5735) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:5781) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.Choreographer.doCallbacks(Choreographer.java:574) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.Choreographer.doFrame(Choreographer.java:542) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.os.Handler.handleCallback(Handler.java:733) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.os.Handler.dispatchMessage(Handler.java:95) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.os.Looper.loop(Looper.java:136) 01-26 15:50:46.811: E/AndroidRuntime(11385): at android.app.A 01-26 15:50:46.821: W/ActivityManager(774): Force finishing activity com.noahedu.ampmlistening/.update.ActSelBook 01-26 15:50:46.831: D/dalvikvm(2604): GC_FOR_ALLOC freed 157K, 9% free 5498K/6008K, paused 22ms, total 22ms 01-26 15:50:46.831: I/dalvikvm-heap(2604): Grow heap (frag case) to 6.200MB for 800272-byte allocation 01-26 15:50:46.841: D/dalvikvm(2604): GC_FOR_ALLOC freed 0K, 8% free 6280K/6792K, paused 9ms, total 9ms 请大侠帮帮忙,指教下下。
无法执行 ImageView imageView = new ImageView(this);
我写的瀑布流显示图片 每次执行到Log.e("error","101成功压缩图片")这句就没办法执行了,下面是我的代码 import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ScrollView; public class MainActivity extends Activity implements Runnable{ private final int NUM_OF_PIC = 30; //每次请求获取的图片数量 private LinearLayout linearLayout1 = null; private LinearLayout linearLayout2 = null; private LinearLayout linearLayout3 = null; private View scrollView = null; public static int USE_LINEAR_INTERVAL = 0; public static int linearlayoutWidth; private byte[][] picBytes = new byte[NUM_OF_PIC][]; private int numOfPic = 0;//已加载的图片数量 private int index = 0; public static int requestTime = 0; private PictureArrayOfBytes picArray ; private Handler mHandler = new Handler(){ public void handleMessage(Message msg) { switch (msg.what) { case 1: try { Log.e("error","39"); addBitmaps(); Log.e("error","41"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } break; } }; }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); linearLayout1 = (LinearLayout)findViewById(R.id.main_linearlayout1); linearLayout2 = (LinearLayout)findViewById(R.id.main_linearlayout2); linearLayout3 = (LinearLayout)findViewById(R.id.main_linearlayout3); linearlayoutWidth = (int)(getWindowManager().getDefaultDisplay().getWidth()/3); Log.e("error","creat: " + String.valueOf(linearlayoutWidth)); scrollView = findViewById(R.id.scroll); Log.e("error","61"); final Thread thread = new Thread(new MainActivity()); Log.e("error","65"); thread.start(); Log.e("error","67"); Log.e("info", "context: "+(context == null)); scrollView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN : break; case MotionEvent.ACTION_MOVE : index++; break; default : break; } if (event.getAction() == MotionEvent.ACTION_UP && index > 0) { index = 0; View view = ((ScrollView) v).getChildAt(0); if (view.getMeasuredHeight() <= v.getScrollY() + v.getHeight()) { //加载数据代码 //每次加载30张图片,一共加载5次 if (numOfPic >= NUM_OF_PIC){ numOfPic = 0; thread.start(); } } } return false; } }); Log.e("error","90"); } private void addBitmaps() throws Exception{ Log.e("error","87:开始加载图片"); for (int i = 0; i < NUM_OF_PIC; i++){ Log.e("error","将图片数据转换成bitmap"); Bitmap bitmap = BitmapFactory.decodeByteArray(picBytes[i], 0, picBytes[i].length); Log.e("error","改编图片的大小"); Bitmap bitmap2 = BitmapZoom.bitmapZoomByWidth(bitmap, 240); //压缩图片大小 Log.e("error","101成功压缩图片"); Log.e("info", "context: "+(context == null)); ImageView imageView = new ImageView(this); Log.e("error","103"); imageView.setImageBitmap(bitmap); Log.e("error","105"); //根据图片的大小,为图片挖坑 LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(bitmap2.getWidth(), bitmap2.getHeight()); //将坑和图片对象联系起来 Log.e("error","109"); imageView.setLayoutParams(layoutParams); Log.e("error","111"); //按照顺序加载图片 switch (USE_LINEAR_INTERVAL) { case 0: linearLayout1.addView(imageView); numOfPic++; break; case 1: linearLayout2.addView(imageView); numOfPic++; break; case 2: linearLayout3.addView(imageView); numOfPic++; break; default: break; } USE_LINEAR_INTERVAL++; USE_LINEAR_INTERVAL= USE_LINEAR_INTERVAL%3; } } @Override public void run() { // TODO Auto-generated method stub try { requestTime++; picArray = new PictureArrayOfBytes(requestTime); picBytes = picArray.getPicByteArray(); Message message = new Message(); message.what = 1; Log.e("error","153"); mHandler.sendMessage(message); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } 下面是我的logcat中的信息: 06-07 15:08:39.146: D/dalvikvm(2418): GC_CONCURRENT freed 292K, 4% free 13039K/13511K, paused 6ms+6ms 06-07 15:08:46.238: E/error(2418): 153 06-07 15:08:46.238: E/error(2418): 39 06-07 15:08:46.238: E/error(2418): 87:开始加载图片 06-07 15:08:46.238: E/error(2418): 将图片数据转换成bitmap 06-07 15:08:46.315: D/dalvikvm(2418): GC_FOR_ALLOC freed 252K, 4% free 13084K/13575K, paused 76ms 06-07 15:08:46.315: I/dalvikvm-heap(2418): Grow heap (frag case) to 12.987MB for 160016-byte allocation 06-07 15:08:46.498: D/dalvikvm(2418): GC_FOR_ALLOC freed <1K, 4% free 13240K/13767K, paused 87ms 06-07 15:08:46.498: E/error(2418): 改编图片的大小 06-07 15:08:46.566: D/dalvikvm(2418): GC_FOR_ALLOC freed 27K, 5% free 13214K/13767K, paused 66ms 06-07 15:08:46.575: I/dalvikvm-heap(2418): Grow heap (frag case) to 13.181MB for 230416-byte allocation 06-07 15:08:46.635: D/dalvikvm(2418): GC_FOR_ALLOC freed 0K, 5% free 13439K/14023K, paused 60ms **06-07 15:08:46.645: E/error(2418): 101成功压缩图片 06-07 15:08:46.655: W/System.err(2418): java.lang.NullPointerException** 06-07 15:08:46.685: W/System.err(2418):at android.content.ContextWrapper.getResources(ContextWrapper.java:81) 06-07 15:08:46.685: W/System.err(2418): at android.view.View.<init>(View.java:2696) 06-07 15:08:46.685: W/System.err(2418): at android.widget.ImageView.<init>(ImageView.java:104) 06-07 15:08:46.685: W/System.err(2418): at com.example.mywaterfallversion2.MainActivity.addBitmaps(MainActivity.java:113) 06-07 15:08:46.685: W/System.err(2418): at com.example.mywaterfallversion2.MainActivity.access$0(MainActivity.java:101) 06-07 15:08:46.698: W/System.err(2418): at com.example.mywaterfallversion2.MainActivity$1.handleMessage(MainActivity.java:39) 06-07 15:08:46.698: W/System.err(2418): at android.os.Handler.dispatchMessage(Handler.java:99) 06-07 15:08:46.698: W/System.err(2418): at android.os.Looper.loop(Looper.java:137) 06-07 15:08:46.698: W/System.err(2418): at android.app.ActivityThread.main(ActivityThread.java:4424) 06-07 15:08:46.698: W/System.err(2418): at java.lang.reflect.Method.invokeNative(Native Method) 06-07 15:08:46.706: W/System.err(2418): at java.lang.reflect.Method.invoke(Method.java:511) 06-07 15:08:46.706: W/System.err(2418): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 06-07 15:08:46.706: W/System.err(2418): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 06-07 15:08:46.706: W/System.err(2418): at dalvik.system.NativeStart.main(Native Method)
一条关于安卓开发的问题
我创建了两个Fragment,在MainAcitivity里分别用两个按钮去启动它们,代码如下: public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn=(Button)findViewById(R.id.btn1); Button button=(Button)findViewById(R.id.btn2); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { FragmentManager fm=getFragmentManager(); Fragment fragment=fm.findFragmentById(R.id.linear1); if(fragment==null) { fragment=new frag(); fm.beginTransaction() .add(R.id.linear1,fragment) .commit(); } } }); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { FragmentManager fm=getFragmentManager(); Fragment fragment=fm.findFragmentById(R.id.linear1); if(fragment==null) { fragment=new frag2(); fm.beginTransaction() .replace(R.id.linear1,fragment) .commit(); } } }); } 但是我在运行的时候发现按了按钮btn后显示了第一个Fragment,但是再按按钮button是就没有任何反应了,第二个Fragment没有显示出来,请问这是怎么回事?要实现Fragment的替换,我应该如何去做?
安卓客户端电脑服务器 udp 手机到连接那步就不运行了
eclipse juno 电脑是jre1.8 手机是安卓4.1.2 服务器到接受信息卡住,手机到连接服务器卡住 没报错 我试了手机连电脑开的wifi和手机电脑连一个wifi都不行 不知是哪出了问题? 刚注册的没悬赏见谅 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button1=(Button)findViewById(R.id.button1); editText1=(EditText)findViewById(R.id.editText1); editText2=(EditText)findViewById(R.id.editText2); /* // 开启服务器 ExecutorService exec = Executors.newCachedThreadPool(); UDPServer server = new UDPServer(); exec.execute(server);*/ // int port = 5050; new AlertDialog.Builder(MainActivity.this).setTitle("测试").setMessage("创建成功").setPositiveButton("确定", null).show(); try { addr = InetAddress.getByName("192.168.191.4"); new AlertDialog.Builder(MainActivity.this).setTitle("测试").setMessage("ip").setPositiveButton("确定", null).show(); // dClient = new DatagramSocket(PORT,addr); dClient = new DatagramSocket(); //随机端口 new AlertDialog.Builder(MainActivity.this).setTitle("测试").setMessage("连接 UDP 成功").setPositiveButton("确定", null).show(); button1.setOnClickListener(new OnClickListener() { public void onClick(View v) { String str1 = editText1.getText().toString(); String str2 = editText2.getText().toString(); Pattern p = Pattern.compile("[^( |\\n)*]"); //匹配 除了空白以外的字符 Matcher m = p.matcher(str2); if(m.find()==true) //不能只含有空格或者回车 { /*String msg; try { Socket socket = new Socket("202.204.48.135",5554); PrintWriter out = new PrintWriter( new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())),true); out.println(str2); BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream())); msg = br.readLine();*/ str2="ID1:\n"+str2; // str1="frag"; // editText1.setText(str1); DatagramPacket sendPacket = new DatagramPacket(str2.getBytes() ,str2.length() , addr , PORT); try { dClient.send(sendPacket); } catch (IOException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } // str1=str1+"\n"+"ID1:\n"+str2+"\n"; // editText1.setText(str1); editText2.setText(null); /* } catch (IOException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } */ } else { editText2.setText(null); } } }); } catch (UnknownHostException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } catch (SocketException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } //以下是自动生成的 @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } ``` ```
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它是一个过程,是一个不断累积、不断沉淀、不断总结、善于传达自己的个人见解以及乐于分享的过程。
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过...
前端 | 2. 正则
转载请注明以下: 本文转自清自以敬的博客:https://blog.csdn.net/qq_45791147 文章目录1.转义2.正则表达式初步2.1.匹配字符2.1.1.组成元素2.1.2.基础正则的设计 1.转义 转义的作用: 当某个字符在表达式中具有特殊含义,例如字符串引号中出现了引号,为了可以使用这些字符本身,而不是使用其在表达式中的特殊含义,则需要通过转义符“\”来构建该字符转义...
有哪些让程序员受益终生的建议
从业五年多,辗转两个大厂,出过书,创过业,从技术小白成长为基层管理,联合几个业内大牛回答下这个问题,希望能帮到大家,记得帮我点赞哦。 敲黑板!!!读了这篇文章,你将知道如何才能进大厂,如何实现财务自由,如何在工作中游刃有余,这篇文章很长,但绝对是精品,记得帮我点赞哦!!!! 一腔肺腑之言,能看进去多少,就看你自己了!!! 目录: 在校生篇: 为什么要尽量进大厂? 如何选择语言及方...
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
linux系列之常用运维命令整理笔录
本博客记录工作中需要的linux运维命令,大学时候开始接触linux,会一些基本操作,可是都没有整理起来,加上是做开发,不做运维,有些命令忘记了,所以现在整理成博客,当然vi,文件操作等就不介绍了,慢慢积累一些其它拓展的命令,博客不定时更新 free -m 其中:m表示兆,也可以用g,注意都要小写 Men:表示物理内存统计 total:表示物理内存总数(total=used+free) use...
比特币原理详解
一、什么是比特币 比特币是一种电子货币,是一种基于密码学的货币,在2008年11月1日由中本聪发表比特币白皮书,文中提出了一种去中心化的电子记账系统,我们平时的电子现金是银行来记账,因为银行的背后是国家信用。去中心化电子记账系统是参与者共同记账。比特币可以防止主权危机、信用风险。其好处不多做赘述,这一层面介绍的文章很多,本文主要从更深层的技术原理角度进行介绍。 二、问题引入 假设现有4个人...
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发...
网页实现一个简单的音乐播放器(大佬别看。(⊙﹏⊙))
今天闲着无事,就想写点东西。然后听了下歌,就打算写个播放器。 于是乎用h5 audio的加上js简单的播放器完工了。 演示地点演示 html代码如下` music 这个年纪 七月的风 音乐 ` 然后就是css`*{ margin: 0; padding: 0; text-decoration: none; list-...
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。
数据库优化 - SQL优化
以实际SQL入手,带你一步一步走上SQL优化之路!
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 cpp 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7 p...
通俗易懂地给女朋友讲:线程池的内部原理
餐盘在灯光的照耀下格外晶莹洁白,女朋友拿起红酒杯轻轻地抿了一小口,对我说:“经常听你说线程池,到底线程池到底是个什么原理?”
《奇巧淫技》系列-python!!每天早上八点自动发送天气预报邮件到QQ邮箱
将代码部署服务器,每日早上定时获取到天气数据,并发送到邮箱。 也可以说是一个小型人工智障。 知识可以运用在不同地方,不一定非是天气预报。
经典算法(5)杨辉三角
杨辉三角 是经典算法,这篇博客对它的算法思想进行了讲解,并有完整的代码实现。
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹...
面试官:你连RESTful都不知道我怎么敢要你?
干货,2019 RESTful最贱实践
Docker 从入门到掉坑
Docker 介绍 简单的对docker进行介绍,可以把它理解为一个应用程序执行的容器。但是docker本身和虚拟机还是有较为明显的出入的。我大致归纳了一下,可以总结为以下几点: docker自身也有着很多的优点,关于它的优点,可以总结为以下几项: 安装docker 从 2017 年 3 月开始 docker 在原来的基础上分为两个分支版本: Docker CE 和 Doc...
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看...
白话阿里巴巴Java开发手册高级篇
不久前,阿里巴巴发布了《阿里巴巴Java开发手册》,总结了阿里巴巴内部实际项目开发过程中开发人员应该遵守的研发流程规范,这些流程规范在一定程度上能够保证最终的项目交付质量,通过在时间中总结模式,并推广给广大开发人员,来避免研发人员在实践中容易犯的错误,确保最终在大规模协作的项目中达成既定目标。 无独有偶,笔者去年在公司里负责升级和制定研发流程、设计模板、设计标准、代码标准等规范,并在实际工作中进行...
SQL-小白最佳入门sql查询一
不要偷偷的查询我的个人资料,即使你再喜欢我,也不要这样,真的不好;
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // doshom...
Nginx 原理和架构
Nginx 是一个免费的,开源的,高性能的 HTTP 服务器和反向代理,以及 IMAP / POP3 代理服务器。Nginx 以其高性能,稳定性,丰富的功能,简单的配置和低资源消耗而闻名。 Nginx 的整体架构 Nginx 里有一个 master 进程和多个 worker 进程。master 进程并不处理网络请求,主要负责调度工作进程:加载配置、启动工作进程及非停升级。worker 进程负责处...
Python 编程开发 实用经验和技巧
Python是一门很灵活的语言,也有很多实用的方法,有时候实现一个功能可以用多种方法实现,我这里总结了一些常用的方法和技巧,包括小数保留指定位小数、判断变量的数据类型、类方法@classmethod、制表符中文对齐、遍历字典、datetime.timedelta的使用等,会持续更新......
YouTube排名第一的励志英文演讲《Dream(梦想)》
Idon’t know what that dream is that you have, I don't care how disappointing it might have been as you've been working toward that dream,but that dream that you’re holding in your mind, that it’s po...
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,...
程序员:我终于知道post和get的区别
是一个老生常谈的话题,然而随着不断的学习,对于以前的认识有很多误区,所以还是需要不断地总结的,学而时习之,不亦说乎
《程序人生》系列-这个程序员只用了20行代码就拿了冠军
你知道的越多,你不知道的越多 点赞再看,养成习惯GitHub上已经开源https://github.com/JavaFamily,有一线大厂面试点脑图,欢迎Star和完善 前言 这一期不算《吊打面试官》系列的,所有没前言我直接开始。 絮叨 本来应该是没有这期的,看过我上期的小伙伴应该是知道的嘛,双十一比较忙嘛,要值班又要去帮忙拍摄年会的视频素材,还得搞个程序员一天的Vlog,还要写BU...
程序员把地府后台管理系统做出来了,还有3.0版本!12月7号最新消息:已在开发中有github地址
第一幕:缘起 听说阎王爷要做个生死簿后台管理系统,我们派去了一个程序员…… 996程序员做的梦: 第一场:团队招募 为了应对地府管理危机,阎王打算找“人”开发一套地府后台管理系统,于是就在地府总经办群中发了项目需求。 话说还是中国电信的信号好,地府都是满格,哈哈!!! 经常会有外行朋友问:看某网站做的不错,功能也简单,你帮忙做一下? 而这次,面对这样的需求,这个程序员...
网易云6亿用户音乐推荐算法
网易云音乐是音乐爱好者的集聚地,云音乐推荐系统致力于通过 AI 算法的落地,实现用户千人千面的个性化推荐,为用户带来不一样的听歌体验。 本次分享重点介绍 AI 算法在音乐推荐中的应用实践,以及在算法落地过程中遇到的挑战和解决方案。 将从如下两个部分展开: AI算法在音乐推荐中的应用 音乐场景下的 AI 思考 从 2013 年 4 月正式上线至今,网易云音乐平台持续提供着:乐屏社区、UGC...
为什么要学数据结构?
一、前言 在可视化化程序设计的今天,借助于集成开发环境可以很快地生成程序,程序设计不再是计算机专业人员的专利。很多人认为,只要掌握几种开发工具就可以成为编程高手,其实,这是一种误解。要想成为一个专业的开发人员,至少需要以下三个条件: 1) 能够熟练地选择和设计各种数据结构和算法 2) 至少要能够熟练地掌握一门程序设计语言 3) 熟知所涉及的相关应用领域的知识 其中,后两个条件比较容易实现,而第一个...
金山办公上市,雷军心愿了却!
作者 | 胡巍巍 出品 | CSDN(ID:CSDNnews) 11月17日,大周末的,雷军微博发了个重磅消息: “明天将是里程碑式的一天,金山办公终于成功在科创板挂牌上市了! 从1988年金山创办到今天,WPS走了整整31年。 从1999年以金山办公为主体准备上市算起,这一天,我们等了20年。 WPS和金山的历程,这是一个坚持梦想并最终取得胜利的励志故事。期待大家的祝福!”...
8年经验面试官详解 Java 面试秘诀
作者 |胡书敏 责编 | 刘静 出品 | CSDN(ID:CSDNnews) 本人目前在一家知名外企担任架构师,而且最近八年来,在多家外企和互联网公司担任Java技术面试官,前后累计面试了有两三百位候选人。在本文里,就将结合本人的面试经验,针对Java初学者、Java初级开发和Java开发,给出若干准备简历和准备面试的建议。 Java程序员准备和投递简历的实...
面试官如何考察你的思维方式?
1.两种思维方式在求职面试中,经常会考察这种问题:北京有多少量特斯拉汽车?某胡同口的煎饼摊一年能卖出多少个煎饼?深圳有多少个产品经理?一辆公交车里能装下多少个乒乓球?一个正常成年人有多少根头发?这类估算问题,被称为费米问题,是以科学家费米命名的。为什么面试会问这种问题呢?这类问题能把两类人清楚地区分出来。一类是具有文科思维的人,擅长赞叹和模糊想象,它主要依靠的是人的第一反应和直觉,比如小孩...
17张图带你解析红黑树的原理!保证你能看懂!
二叉查找树 由于红黑树本质上就是一棵二叉查找树,所以在了解红黑树之前,咱们先来看下二叉查找树。 二叉查找树(Binary Search Tree),也称有序二叉树(ordered binary tree),排序二叉树(sorted binary tree),是指一棵空树或者具有下列性质的二叉树: 若任意结点的左子树不空,则左子树上所有结点的值均小于它的根结点的值; 若任意结点的...
腾讯“疯狂”开源!
作者 | 马超 责编 | 胡巍巍 出品 | CSDN(ID:CSDNnews) 近日,腾讯自研的万亿级分布式消息中间件TubeMQ正式开源,并捐赠给Apache基金会,成为基金会官方认可的Incubator项目。 我们知道与TubeMQ功能类似的kafka是领英公司在早在10年前捐赠给Apache基金会的金牌项目,而那时的腾讯还在忙于3Q大战,公司文化也相对封闭,甚至连目前社交领...
so easy! 10行代码写个"狗屁不通"文章生成器
前几天,GitHub 有个开源项目特别火,只要输入标题就可以生成一篇长长的文章。 背后实现代码一定很复杂吧,里面一定有很多高深莫测的机器学习等复杂算法 不过,当我看了源代码之后 这程序不到50行 尽管我有多年的Python经验,但我竟然一时也没有看懂 当然啦,原作者也说了,这个代码也是在无聊中诞生的,平时撸码是不写中文变量名的, 中文...
知乎高赞:中国有什么拿得出手的开源软件产品?(整理自本人原创回答)
知乎高赞:中国有什么拿得出手的开源软件产品? 在知乎上,有个问题问“中国有什么拿得出手的开源软件产品(在 GitHub 等社区受欢迎度较好的)?” 事实上,还不少呢~ 本人于2019.7.6进行了较为全面的回答,对这些受欢迎的 Github 开源项目分类整理如下: 分布式计算、云平台相关工具类 1.SkyWalking,作者吴晟、刘浩杨 等等 仓库地址: apache/skywalking 更...
相关热词 c# 引用mysql c#动态加载非托管dll c# 两个表数据同步 c# 返回浮点json c# imap 链接状态 c# 漂亮字 c# 上取整 除法 c#substring c#中延时关闭 c#线段拖拉
立即提问