android虚拟器中运行正常,但在真机上运行出错!

glee10 2014-07-06 08:10:55
弄了一小段代码,在虚拟器上运行正常,但将在res中把APK拷出来在真机中安装,运行出现“很抱歉,XX已停止运行。
开发中用的是4.03版本,真机上是4.04版本。
实在想不通是哪儿的问题。
请各位指教指教。
谢谢!
...全文
638 27 打赏 收藏 转发到动态 举报
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
蔡正浩 2014-07-31
  • 打赏
  • 举报
回复
引用 25 楼 glee10 的回复:
谢谢指点! 我正在学习基础的东西,对于调试手头的书籍没怎么提及。所以确实吃力。关于教材,您有没有什么好的推荐? 我查了下,这些图片不太大,peachdrop的,才20到40K。在其之前装入的两三幅图片也才100到400K。
你要引用我们的回复来回复,要不我们收不到提醒,不会看。
蔡正浩 2014-07-31
  • 打赏
  • 举报
回复
引用 25 楼 glee10 的回复:
谢谢指点! 我正在学习基础的东西,对于调试手头的书籍没怎么提及。所以确实吃力。关于教材,您有没有什么好的推荐? 我查了下,这些图片不太大,peachdrop的,才20到40K。在其之前装入的两三幅图片也才100到400K。
当当网找下,对比下网上的评论选一本入门书籍就行,一般都有调试的说明,或者视频也行,马士丁的视频入个门还是不错的。书的话我买了本杨丰盛的Android应用开发揭秘,感觉不太好,你最好别买。
glee10 2014-07-08
  • 打赏
  • 举报
回复
谢谢指点! 我正在学习基础的东西,对于调试手头的书籍没怎么提及。所以确实吃力。关于教材,您有没有什么好的推荐? 我查了下,这些图片不太大,peachdrop的,才20到40K。在其之前装入的两三幅图片也才100到400K。
glee10 2014-07-08
  • 打赏
  • 举报
回复
另外,将setContentView(R.layout.main);下面的代码注释掉后的报错信息如下: 07-08 10:06:29.969: E/Posix(3844): [CDS]Libcore_io_Posix-throwErrnoException, functionName: open; errno: No such file or directory 07-08 10:06:30.586: E/Posix(3860): [CDS]Libcore_io_Posix-throwErrnoException, functionName: open; errno: No such file or directory 07-08 10:06:32.110: E/dalvikvm-heap(3872): Out of memory on a 5054416-byte allocation. 07-08 10:06:32.126: E/AndroidRuntime(3872): FATAL EXCEPTION: main 07-08 10:06:32.126: E/AndroidRuntime(3872): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mingrisoft/com.mingrisoft.MainActivity}: android.view.InflateException: Binary XML file line #30: Error inflating class <unknown> 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2077) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.app.ActivityThread.access$600(ActivityThread.java:134) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.os.Handler.dispatchMessage(Handler.java:99) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.os.Looper.loop(Looper.java:154) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.app.ActivityThread.main(ActivityThread.java:4624) 07-08 10:06:32.126: E/AndroidRuntime(3872): at java.lang.reflect.Method.invokeNative(Native Method) 07-08 10:06:32.126: E/AndroidRuntime(3872): at java.lang.reflect.Method.invoke(Method.java:511) 07-08 10:06:32.126: E/AndroidRuntime(3872): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809) 07-08 10:06:32.126: E/AndroidRuntime(3872): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576) 07-08 10:06:32.126: E/AndroidRuntime(3872): at dalvik.system.NativeStart.main(Native Method) 07-08 10:06:32.126: E/AndroidRuntime(3872): Caused by: android.view.InflateException: Binary XML file line #30: Error inflating class <unknown> 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.view.LayoutInflater.createView(LayoutInflater.java:608) 07-08 10:06:32.126: E/AndroidRuntime(3872): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:57) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:655) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.view.LayoutInflater.rInflate(LayoutInflater.java:741) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.view.LayoutInflater.inflate(LayoutInflater.java:491) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 07-08 10:06:32.126: E/AndroidRuntime(3872): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:254) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.app.Activity.setContentView(Activity.java:1837) 07-08 10:06:32.126: E/AndroidRuntime(3872): at com.mingrisoft.MainActivity.onCreate(MainActivity.java:56) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.app.Activity.performCreate(Activity.java:4479) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2041) 07-08 10:06:32.126: E/AndroidRuntime(3872): ... 11 more 07-08 10:06:32.126: E/AndroidRuntime(3872): Caused by: java.lang.reflect.InvocationTargetException 07-08 10:06:32.126: E/AndroidRuntime(3872): at java.lang.reflect.Constructor.constructNative(Native Method) 07-08 10:06:32.126: E/AndroidRuntime(3872): at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.view.LayoutInflater.createView(LayoutInflater.java:588) 07-08 10:06:32.126: E/AndroidRuntime(3872): ... 24 more 07-08 10:06:32.126: E/AndroidRuntime(3872): Caused by: java.lang.OutOfMemoryError 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.graphics.Bitmap.nativeCreate(Native Method) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.graphics.Bitmap.createBitmap(Bitmap.java:605) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.graphics.Bitmap.createBitmap(Bitmap.java:551) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:543) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:518) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:370) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.content.res.Resources.loadDrawable(Resources.java:2260) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.content.res.Resources.getDrawable(Resources.java:953) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:280) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:867) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:804) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.content.res.Resources.loadDrawable(Resources.java:2245) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.content.res.TypedArray.getDrawable(TypedArray.java:608) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.view.View.<init>(View.java:2791) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.widget.ImageView.<init>(ImageView.java:113) 07-08 10:06:32.126: E/AndroidRuntime(3872): at android.widget.ImageView.<init>(ImageView.java:109) 07-08 10:06:32.126: E/AndroidRuntime(3872): ... 27 more 07-08 10:06:32.744: E/Posix(490): [CDS]Libcore_io_Posix-throwErrnoException, functionName: access; errno: No such file or directory 07-08 10:06:32.744: E/Posix(490): [CDS]Libcore_io_Posix-throwErrnoException, functionName: access; errno: No such file or directory 07-08 10:06:32.987: E/Posix(2245): [CDS]Libcore_io_Posix-throwErrnoException, functionName: access; errno: No such file or directory 07-08 10:06:33.002: E/Posix(2245): [CDS]Libcore_io_Posix-throwErrnoException, functionName: access; errno: No such file or directory 07-08 10:06:33.014: E/Posix(2245): [CDS]Libcore_io_Posix-throwErrnoException, functionName: access; errno: No such file or directory 07-08 10:06:35.951: E/Posix(2245): [CDS]Libcore_io_Posix-throwErrnoException, functionName: access; errno: No such file or directory 07-08 10:06:35.961: E/Posix(2245): [CDS]Libcore_io_Posix-throwErrnoException, functionName: access; errno: No such file or directory 07-08 10:06:35.971: E/Posix(2245): [CDS]Libcore_io_Posix-throwErrnoException, functionName: access; errno: No such file or directory
glee10 2014-07-08
  • 打赏
  • 举报
回复
真的非常感谢各位的热心帮助!还是这个论坛好!!! 我将setContentView(R.layout.main);下面的代码注释掉,果然还是报错。 peach_drop.xml的内容如下: <?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/peachdrop720a" android:duration="200" /> <item android:drawable="@drawable/peachdrop720b" android:duration="200" /> <item android:drawable="@drawable/peachdrop720c" android:duration="200" /> <item android:drawable="@drawable/peachdrop720d" android:duration="200" /> <item android:drawable="@drawable/peachdrop720e" android:duration="200" /> <item android:drawable="@drawable/peachdrop720f" android:duration="200" /> <item android:drawable="@drawable/peachdrop720g" android:duration="200" /> <item android:drawable="@drawable/peachdrop720h" android:duration="200" /> <item android:drawable="@drawable/peachdrop720i" android:duration="200" /> <item android:drawable="@drawable/peachdrop720j" android:duration="200" /> <item android:drawable="@drawable/peachdrop720k" android:duration="200" /> <item android:drawable="@drawable/peachdrop720l" android:duration="200" /> <item android:drawable="@drawable/peachdrop720m" android:duration="200" /> <item android:drawable="@drawable/peachdrop720n" android:duration="600" /> </animation-list> ------这些都是720X780的png图,每幅都是从PS生成的。 之前在模拟机上可以正常,但是我对于main.xml的另一ImageView(即"@+id/mirrow_change")也定义了另一幅动画,则虚拟器也报错,试来试去发现两者只能正常显示其一。不得不先装mirrow_change改为图像并注释掉。 这个问题现在比较关键,上面的peach_drop.xml有什么问题吗?
蔡正浩 2014-07-08
  • 打赏
  • 举报
回复
引用 22 楼 glee10 的回复:
果然如此!!! 在main.xlm中将以下内容中去掉后,其它功能一切正常。 <ImageView android:id="@+id/peach_drop" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitEnd" android:background="@anim/peach_drop"/> 那么,原因是什么呢? (之前我对于main.xml的另一ImageView(即"@+id/mirrow_change")也定义了另一幅动画,则虚拟器也报错,试来试去发现两者只能正常显示其一。不得不先将mirrow_change改为图像并注释掉,虚拟机也正常(但真机不正常)。现在将这个peach_drop去掉真机才正常。) 我在想, 原因之一:我在framelayout中同时加了数个ImageView组件,又同时给两个或以上的这些组件背景加了动画,是不是就冲突了?是framelayout对这个有限制吗? 还是原因之二:我的图片格式?(但每一幅都是PS中生成的。) 原因之三:??
还有就是不同版本对内存控制是不一样的,估计这是造成真机,虚拟机不一样结果的原因
蔡正浩 2014-07-08
  • 打赏
  • 举报
回复
引用 22 楼 glee10 的回复:
果然如此!!! 在main.xlm中将以下内容中去掉后,其它功能一切正常。 <ImageView android:id="@+id/peach_drop" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitEnd" android:background="@anim/peach_drop"/> 那么,原因是什么呢? (之前我对于main.xml的另一ImageView(即"@+id/mirrow_change")也定义了另一幅动画,则虚拟器也报错,试来试去发现两者只能正常显示其一。不得不先将mirrow_change改为图像并注释掉,虚拟机也正常(但真机不正常)。现在将这个peach_drop去掉真机才正常。) 我在想, 原因之一:我在framelayout中同时加了数个ImageView组件,又同时给两个或以上的这些组件背景加了动画,是不是就冲突了?是framelayout对这个有限制吗? 还是原因之二:我的图片格式?(但每一幅都是PS中生成的。) 原因之三:??
好像前面的思路都搞错了,最开始的错误应该是第三句报错处, Out of memory 应该是指内存溢出,你的图片是不是很大的,建议先只定义两张图片的动画试下。我以前做一个小游戏试过内存溢出,因为android应用对内存的控制比较严格,好像单张图片的大小也有限制。先试下吧。 http://bbs.csdn.net/topics/390267830 07-07 13:11:56.648: E/Posix(6593): [CDS]Libcore_io_Posix-throwErrnoException, functionName: open; errno: No such file or directory 07-07 13:11:57.295: E/Posix(6609): [CDS]Libcore_io_Posix-throwErrnoException, functionName: open; errno: No such file or directory 07-07 13:11:59.047: E/dalvikvm-heap(6621): Out of memory on a 5054416-byte allocation. 还有就是楼主最好先找本书看下android基础知识,一般看完前几章就可以边学边看了,或者看视频,感觉你还不会调试,这样做起东西来很难。
fireyou 2014-07-08
  • 打赏
  • 举报
回复
android.view.InflateException: Binary XML file line #30: Error inflating class <unknown> 说明是xml里有问题。30行。 仔细看看
glee10 2014-07-08
  • 打赏
  • 举报
回复
果然如此!!! 在main.xlm中将以下内容中去掉后,其它功能一切正常。 <ImageView android:id="@+id/peach_drop" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitEnd" android:background="@anim/peach_drop"/> 那么,原因是什么呢? (之前我对于main.xml的另一ImageView(即"@+id/mirrow_change")也定义了另一幅动画,则虚拟器也报错,试来试去发现两者只能正常显示其一。不得不先将mirrow_change改为图像并注释掉,虚拟机也正常(但真机不正常)。现在将这个peach_drop去掉真机才正常。) 我在想, 原因之一:我在framelayout中同时加了数个ImageView组件,又同时给两个或以上的这些组件背景加了动画,是不是就冲突了?是framelayout对这个有限制吗? 还是原因之二:我的图片格式?(但每一幅都是PS中生成的。) 原因之三:??
風言楓語 2014-07-08
  • 打赏
  • 举报
回复
引用 16 楼 caizhegnhao 的回复:
[quote=引用 12 楼 glee10 的回复:] 从Logcat的信息中哪一行可以看出55行报错了? 第55行是从“public class MainActivity extends Activity {“这一行算起的吗?
根据logcat的信息可以知道加载布局xml的那句代码抛一场了,而真正异常源头其实还在前面,下面这句代码说明了是布局文件30行报异常。 android.view.InflateException: Binary XML file line #30: Error inflating class <unknown> <ImageView android:id="@+id/peach_drop" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitEnd" android:background="@anim/peach_drop"/> 30行处是一个imageview,对比前后相信是 android:background="@anim/peach_drop" 这里报错了,这个的意思应该是加载一个动画为背景吧,相信你这个动画定义有问题。检查下动画的定义吧,可能会跟机型有关系。[/quote] 16搂说的不错 注释掉还报错的话就是布局的问题了 你的布局文件里面可能出问题的就那个动画了 把那个动画去掉运行试下
tony4geek 2014-07-08
  • 打赏
  • 举报
回复
是不是内存溢出。
蔡正浩 2014-07-08
  • 打赏
  • 举报
回复
引用 12 楼 glee10 的回复:
从Logcat的信息中哪一行可以看出55行报错了? 第55行是从“public class MainActivity extends Activity {“这一行算起的吗?
根据logcat的信息可以知道加载布局xml的那句代码抛一场了,而真正异常源头其实还在前面,下面这句代码说明了是布局文件30行报异常。 android.view.InflateException: Binary XML file line #30: Error inflating class <unknown> <ImageView android:id="@+id/peach_drop" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitEnd" android:background="@anim/peach_drop"/> 30行处是一个imageview,对比前后相信是 android:background="@anim/peach_drop" 这里报错了,这个的意思应该是加载一个动画为背景吧,相信你这个动画定义有问题。检查下动画的定义吧,可能会跟机型有关系。
echoJiang 2014-07-07
  • 打赏
  • 举报
回复
window -> showView -> other... ->Android -> logcat, 就可以打开logcat了, 之后运行一下,把红色的打印发出来给大家看看
風言楓語 2014-07-07
  • 打赏
  • 举报
回复
看logcat 异常信息不是在控制台 而是在logcat里面
風言楓語 2014-07-07
  • 打赏
  • 举报
回复
可以先把setContentView(R.layout.main);下面的代码注释掉 如果还是报错就是他的问题了
glee10 2014-07-07
  • 打赏
  • 举报
回复
55行是这一句:setContentView(R.layout.main); 我的main.xml如下: <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/frameLayout1" android:background="#FF0077FF" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageView android:id="@+id/cloud" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/cloud" android:layout_gravity="left|center"/> <ImageView android:id="@+id/peach" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitEnd" android:background="@drawable/peach720"/> <ImageView android:id="@+id/moon" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitEnd" android:background="@drawable/moon720"/> <ImageView android:id="@+id/peach_drop" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitEnd" android:background="@anim/peach_drop"/> <ImageView android:id="@+id/main" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitEnd" android:background="@drawable/mirrow720"/> <ImageView android:id="@+id/mirrow" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitEnd"/> <ImageView android:id="@+id/mirrow_change" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitEnd" android:background="@drawable/mirrow720"/> </FrameLayout> ----有什么不妥吗?怎么在模拟器上没问题呢?
風言楓語 2014-07-07
  • 打赏
  • 举报
回复
引用 12 楼 glee10 的回复:
从Logcat的信息中哪一行可以看出55行报错了? 第55行是从“public class MainActivity extends Activity {“这一行算起的吗?
: at com.mingrisoft.MainActivity.onCreate(MainActivity.java:55) eclipce不是有行号显示的么 你直接看那行号就行了
glee10 2014-07-07
  • 打赏
  • 举报
回复
从Logcat的信息中哪一行可以看出55行报错了? 第55行是从“public class MainActivity extends Activity {“这一行算起的吗?
glee10 2014-07-07
  • 打赏
  • 举报
回复
没想到有回复那么快。谢谢! 这是代码: package com.mingrisoft; import android.app.Activity; import android.graphics.drawable.AnimationDrawable; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.view.View.OnTouchListener; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationUtils; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.FrameLayout; import android.widget.ScrollView; import android.widget.TextView; import android.widget.Toast; import android.app.*; import java.io.File; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.Toast; import android.content.SharedPreferences; import android.content.DialogInterface.OnClickListener; import android.content.SharedPreferences.Editor; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //全屏模式,屏蔽一切标题 setContentView(R.layout.main); final ImageView iv_c=(ImageView)findViewById(R.id.cloud); final ImageView iv_p=(ImageView)findViewById(R.id.peach_drop); //final ImageView iv_m=(ImageView)findViewById(R.id.mirrow_change); //获取要应用动画效果的ImageView final ImageView iv_main=(ImageView)findViewById(R.id.main); //获取要显示结果的ImageView final Animation cloud_tran=AnimationUtils.loadAnimation(this, R.anim.cloud_tran); //获取蓝天白云移动的动画资源 final AnimationDrawable anim_p = (AnimationDrawable)iv_p.getBackground(); //final AnimationDrawable anim_m = (AnimationDrawable)iv_m.getBackground(); //获取应用的帧动画 FrameLayout ll=(FrameLayout)findViewById(R.id.frameLayout1); //获取帧布局管理器 Toast.makeText(this,"触摸开启...", Toast.LENGTH_LONG).show(); //提示 anim_p.start(); iv_c.startAnimation(cloud_tran);//开始播放蓝天白动移动的动画 ll.setOnTouchListener(new OnTouchListener() { //触摸后执行: @Override public boolean onTouch(View v, MotionEvent event) { //anim_m.start(); return false; } }); } //创建选项菜单 @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater=new MenuInflater(this); //实例化一个MenuInflater对象 inflater.inflate(R.menu.optionmenu, menu); //解析菜单文件 return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { if(item.isChecked()){ //当菜单项已经被选中 item.setChecked(false); //设置菜单项不被选中 }else{ item.setChecked(true); //设置菜单项被选中 } switch(item.getItemId()){ case R.id.theone: Intent intentFromGallery= new Intent(); intentFromGallery.setType("image/*");//设置为取图片类 intentFromGallery.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(intentFromGallery,0); Toast.makeText(MainActivity.this, item.getTitle(), Toast.LENGTH_SHORT).show(); break; case R.id.voise: Toast.makeText(MainActivity.this, item.getTitle(), Toast.LENGTH_SHORT).show(); break; case R.id.backmusic://如果选中“设定背景音乐” Toast.makeText(MainActivity.this, item.getTitle(), Toast.LENGTH_SHORT).show(); break; case R.id.aboutme://如果选中“提示” Toast.makeText(MainActivity.this, item.getTitle(), Toast.LENGTH_SHORT).show(); AlertDialog alert = new AlertDialog.Builder(MainActivity.this).create(); alert.setIcon(R.drawable.ic_launcher); alert.setTitle("温柔提示:" ); alert.setMessage("版权所有! "); alert.setButton(DialogInterface.BUTTON_POSITIVE,"确定", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "您单击了确定按钮",Toast.LENGTH_SHORT).show(); } }); alert.show(); break; case R.id.more://如果选中"妙用” ScrollView scroller=new ScrollView(MainActivity.this); TextView tip =new TextView(MainActivity.this); tip.setPadding(10, 10, 10, 10); tip.setTextSize(20); scroller.addView(tip); tip.setText("诸天软件,版权所有! " +"诸天软件,版权所有!诸天软件,版权所有!诸天软件,版权所有!诸天软件,版权所有!" +"诸天软件,版权所有!诸天软件,版权所有!诸天软件,版权所有!诸天软件,版权所有!"); FrameLayout ll=(FrameLayout)findViewById(R.id.frameLayout1); //获取帧布局管理器 ll.addView(scroller); break; case R.id.quit://如果选中“退出” Toast.makeText(MainActivity.this, item.getTitle(), Toast.LENGTH_SHORT).show(); break; default: } return true; } //文件选择后返回结果处理 protected void onActivityResult(int requestCode,int resultCode,Intent data){ super.onActivityResult(requestCode,resultCode,data); switch(requestCode){ case 1 : saveTheoneImage(data);//调用该方法,将文件选择的结果以URI的方式存入SharedPreferences break; } } private void saveTheoneImage(Intent data){ Uri uri = data.getData(); //将返回的结果 String theonepath=uri.getPath().toString(); SharedPreferences sp = getSharedPreferences("config",MODE_PRIVATE); Editor editor =sp.edit(); editor.putString("theonefilepath", theonepath); editor.commit(); } }
glee10 2014-07-07
  • 打赏
  • 举报
回复
连是连上了,在手机上也运行了,然后还是中断。 以上信息似乎是连接时的调试信息,运行时好象在控制台没有信息提示。
加载更多回复(7)

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧