綁定帳號登入

Android 台灣中文網

打印 上一主題 下一主題

[討論] 寫程式也遇到科學無法解釋的事情

[複製連結] 查看: 1424|回覆: 3|好評: 0
跳轉到指定樓層
樓主
lkk47 | 收聽TA | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
發表於 2011-11-21 20:46

馬上加入Android 台灣中文網,立即免費下載應用遊戲。

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x
我把出現問題的程式碼貼出來  全貼可能沒耐心看吧
先說明一下在專案中有3個class  假設a.java  b.java  c.java       a,b,c都是個自的activity
a程式碼片段如下:
  1. private void findfile(){[color=Green]//此方法搜尋sdcard/DCIM/100MEDIA/的所有圖片[/color]
  2.                         File images = new File("/sdcard/DCIM/100MEDIA/");
  3.                     File[] imagelist = images.listFiles(new FilenameFilter(){  
  4.                             public boolean accept(File dir, String name)
  5.                         {  
  6.                             return ((name.endsWith(".jpg"))||(name.endsWith(".png")));
  7.                         }  
  8.                     });  
  9.                     mFiles = new String[imagelist.length];  
  10.                     for(int i= 0 ; i< imagelist.length; i++)  
  11.                                {  
  12.                             mFiles[i] = imagelist[i].getAbsolutePath();  
  13.                         }  
  14.                     mUrls = new Uri[mFiles.length];  
  15.                     for(int i=0; i < mFiles.length; i++)  
  16.                         {  
  17.                             mUrls[i] = Uri.parse(mFiles[i]);     
  18.                         }
  19.                    [color=Red] isUrls = new Uri[mFiles.length];  
  20.                     for(int i=0; i < mFiles.length; i++)  
  21.                         {  
  22.                             isUrls[i] = Uri.parse(mFiles[i]);     
  23.                         }[/color]

  24.                     @Override
  25.                 public void onItemSelected(AdapterView<?> arg0, View arg1, final int arg2,
  26.                                 long arg3) {//[color=Green]這方法是Gallery選擇會發生的事件[/color]
  27.                         // TODO Auto-generated method stub
  28.                            argg=arg2;//[color=Green]等等c會用到這一個因為argg是公開的[/color]
  29.                         imageswitch.setImageURI(isUrls[arg2]);[color=Green]//這裡只能給b用給c就發生問題了  這段說明imageswitch顯示Gallery選擇的圖片[/color]
  30.                         shorturl=isUrls[arg2];
  31.                         imageswitch.setOnTouchListener(new OnTouchListener(){
  32.                                 @Override
  33.                                 public boolean onTouch(View arg0, MotionEvent arg1) {
  34.                                         // TODO Auto-generated method stub
  35.                                         Intent intent=new Intent();
  36.                                         intent.setClass(Chosephoto.this, gender.class);
  37.                                         Bundle bundle=new Bundle();
  38.                                         bundle.putInt("int", arg2);
  39.                                         intent.putExtras(bundle);
  40.                                         startActivity(intent);
  41.                                         //使用intent bundle傳送訊息到activity
  42.                                         return false;
  43.                                 }});
  44.                        
  45.                 }
複製代碼
b程式碼片段如下:
  1. public void onCreate(Bundle savedInstanceState) {
  2.         super.onCreate(savedInstanceState);
  3.         setContentView(R.layout.boy_image_view);
  4.         iv=(ImageView) findViewById(R.id.imageView1);
  5.       
  6.         [color=Red]Bundle bundle =this.getIntent().getExtras();
  7.         transfer=bundle.getInt("arg2");
  8.         iv.setImageURI(Chosephoto.isUrls[transfer])[/color];
複製代碼
//紅色這段是bundle接收  iv是顯示傳送過來的圖片uri  跟a的imageswitch.setImageURI(isUrls[arg2]);一樣意思


c的程式碼片段如下:
  1. protected void onCreate(Bundle savedInstanceState) {
  2.                 // TODO Auto-generated method stub
  3.                 super.onCreate(savedInstanceState);
  4.                 setContentView(R.layout.shorthair_xml);
  5.                 shortiv1=(ImageView) findViewById(R.id.shortimageView1);
  6.                 [color=Red]shortiv1.setImageURI(Chosephoto.isUrls[Chosephoto.argg])[/color];[color=Green]//這一段根bundle是一樣的用法  我也試過bundle用法結果都依樣  這一段就跟b的片段iv.setImageURI(Chosephoto.isUrls[transfer])一樣  問題出現在這一句[/color]
複製代碼
輸出結果a,b都正常c出現問題    logcat 顯示c的shortiv1.setImageURI(Chosephoto.isUrls[Chosephoto.argg])這行出現錯誤

最後是很多次  得到一個問題 setImageURI(Chosephoto.isUrls[Chosephoto.argg])這一句只可以給一個activity使用
要是2個activity使用會有1個出錯(換句話說a給b使用成功,b再給c使用c就出錯,a給c也是成功   就是不能給第3個)
不知道是什麼靈異現象  還是有其他方法解決

「用Android 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
收藏收藏 分享分享 分享專題
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

沙發
ploglin | 收聽TA | 只看該作者
發表於 2011-11-22 08:55
你把實際錯誤訊息可以貼上來。
我想問題應該跟你所敍述的不太一樣。
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

板凳
 樓主| lkk47 | 收聽TA | 只看該作者
發表於 2011-11-22 08:59

我的logcat
11-22 08:52:58.181: E/AndroidRuntime(7160):         at com.aa.Shorthair.onCreate(Shorthair.java:36)
這一行也就是c片段的shortiv1.setImageURI(Chosephoto.isUrls[Chosephoto.argg])
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

地板
ploglin | 收聽TA | 只看該作者
發表於 2011-11-22 16:11
把所有的堆疊的錯誤的貼出來。
要看是哪一個部份出問題,必需要看完整的訊息。
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則