Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Mobile > Mobile Forum > Android - - ช่วยดูโค้ดให้ทีค่ะ อยากให้มันโชว์ไฟล์ของ ftp server แต่พอรันโค้ดแล้วมมัน error T^T



 

Android - - ช่วยดูโค้ดให้ทีค่ะ อยากให้มันโชว์ไฟล์ของ ftp server แต่พอรันโค้ดแล้วมมัน error T^T

 



Topic : 104872



โพสกระทู้ ( 17 )
บทความ ( 0 )



สถานะออฟไลน์




พอดีทำหน้าเกี่ยวกับการโชว์ file ของ server พอดีรันแล้วมันไม่ออก

อยากขอให้ช่วยดูโค้ดให้หน่อยค่ะ อยากทราบว่ามีที่ผิดตรงไหนรึป่าว


Code (Android-Java)
package com.example.android;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;

import org.apache.commons.io.FileUtils;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.ArrayAdapter;
import android.widget.Toast;
import android.widget.TextView;
public class Listview extends ListActivity {
	
	
	
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);


        task getson = new task();
        getson.execute();




    }

    FTPClient client;

    public FTPClient connectWithFTP() throws IOException{
         client = new FTPClient();  
         try {

             client.connect("hostname", 21);  
             client.login("username", "password");
             System.out.println("status :: " + client.getReplyString());
             int reply = client.getReplyCode();
                if (!FTPReply.isPositiveCompletion(reply)) {
                    throw new Exception("Connect failed: " + client.getReplyString());
                }
                try {
                    client.enterLocalPassiveMode();
                    if (!client.setFileType(FTP.BINARY_FILE_TYPE)) {
                        Log.v(getClass().toString(), "Setting binary file type failed.");
                    }
                } catch(Exception e) {
                    e.printStackTrace();
                } 
             checkFiles(client);
        } catch (Exception e) {
            System.out.println("status :: " + client.getReplyString());
        }
          return client;
    }

    private class task extends AsyncTask <Void, Void, FTPClient> {

        @Override
        protected void onPreExecute() {
            // Do stuff before the operation
        }


        @Override
        protected FTPClient doInBackground(Void... params) {
            FTPClient ftp = null;
            try {
                ftp = connectWithFTP();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return ftp;
        }
    }

    public void disconnectWithFTP() throws IOException{
        client.logout();  
        client.disconnect();  
    }

    private void checkFiles(FTPClient clients){
          try {  
              FTPFile[] ftpFiles = clients.listFiles();  
              int length = ftpFiles.length;  
              for (int i = 0; i < length; i++) {  
                String name = ftpFiles[i].getName();  
                Calendar date = ftpFiles[i].getTimestamp();
                Log.v("aasd", name+", "+date);

              }  
            } catch(Exception e) {  
              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;
    }

}




Tag : Mobile, Android, JAVA







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-01-21 23:06:57 By : iamillusion View : 1029 Reply : 6
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Error อะไรครับ มี LogCat ให้ดูหรือเปล่าครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-01-22 09:16:41 By : mr.win
 


 

No. 2



โพสกระทู้ ( 17 )
บทความ ( 0 )



สถานะออฟไลน์


อันนี้ logcat ค่ะ

Code
01-22 11:34:09.272: W/dalvikvm(358): threadid=1: thread exiting with uncaught exception (group=0x40015560)
01-22 11:34:09.292: E/AndroidRuntime(358): FATAL EXCEPTION: main
01-22 11:34:09.292: E/AndroidRuntime(358): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.listfile/com.example.listfile.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
01-22 11:34:09.292: E/AndroidRuntime(358): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-22 11:34:09.292: E/AndroidRuntime(358): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-22 11:34:09.292: E/AndroidRuntime(358): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-22 11:34:09.292: E/AndroidRuntime(358): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-22 11:34:09.292: E/AndroidRuntime(358): at android.os.Handler.dispatchMessage(Handler.java:99)
01-22 11:34:09.292: E/AndroidRuntime(358): at android.os.Looper.loop(Looper.java:123)
01-22 11:34:09.292: E/AndroidRuntime(358): at android.app.ActivityThread.main(ActivityThread.java:3683)
01-22 11:34:09.292: E/AndroidRuntime(358): at java.lang.reflect.Method.invokeNative(Native Method)
01-22 11:34:09.292: E/AndroidRuntime(358): at java.lang.reflect.Method.invoke(Method.java:507)
01-22 11:34:09.292: E/AndroidRuntime(358): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-22 11:34:09.292: E/AndroidRuntime(358): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-22 11:34:09.292: E/AndroidRuntime(358): at dalvik.system.NativeStart.main(Native Method)
01-22 11:34:09.292: E/AndroidRuntime(358): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
01-22 11:34:09.292: E/AndroidRuntime(358): at android.app.ListActivity.onContentChanged(ListActivity.java:243)
01-22 11:34:09.292: E/AndroidRuntime(358): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:210)
01-22 11:34:09.292: E/AndroidRuntime(358): at android.app.Activity.setContentView(Activity.java:1657)
01-22 11:34:09.292: E/AndroidRuntime(358): at com.example.listfile.MainActivity.onCreate(MainActivity.java:33)
01-22 11:34:09.292: E/AndroidRuntime(358): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-22 11:34:09.292: E/AndroidRuntime(358): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-22 11:34:09.292: E/AndroidRuntime(358): ... 11 more
01-22 11:34:11.342: I/Process(358): Sending signal. PID: 358 SIG: 9

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-01-22 11:35:32 By : iamillusion
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Quote:
01-22 11:34:09.292: E/AndroidRuntime(358): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.listfile/com.example.listfile.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'


มัน Error นี้น่ะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-01-22 12:35:49 By : mr.win
 


 

No. 4



โพสกระทู้ ( 17 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณค่ะ แล้วถ้าอยากนำ file ที่เราได้มามาใส่ใน listview และ checkbox เราจะใช้ค่าตัวไหนมาโชว์ใน listview อ่าคะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-01-22 23:55:45 By : iamillusion
 


 

No. 5



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Code (Android-Java)
private List <String> getSD()
{
 List <String> it = new ArrayList <String>();
 File f = new File ("/mnt/sdcard/picture");
 File[] files = f.listFiles ();
 
 for (int i = 0; i <files.length; i++)
 {
 	File  file = files[i];
 	Log.d("Count",file.getPath());
  it.add (file.getPath());
 }
 return it;
}


Android Populate ListView ImageView get Image Resource from SD ...

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-01-23 09:36:48 By : mr.win
 


 

No. 6



โพสกระทู้ ( 17 )
บทความ ( 0 )



สถานะออฟไลน์


ลองแก้แล้วอ่าค่ะ แต่มันไม่โชว์ใน listview


Code (Android-Java)
public class MainActivity extends Activity {

   
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        
        task getson = new task();
        getson.execute();
        
       List<String> Listfile = null ;
       Listfile = checkFiles(client);
       System.out.println("showfile uuu :: "+ Listfile);  
      

       
      //String[] FileList = null;  //new String[] {"1","2","3","4","5","6"};
       
     // listView1
        final ListView lisView1 = (ListView)findViewById(R.id.listView1);
       
       // System.out.println("show :: "+ Listfile);
     
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1,  Listfile);
        lisView1.setAdapter(adapter);
    }

    FTPClient client;

    public FTPClient connectWithFTP() throws IOException{
         client = new FTPClient();  
         try {

             client.connect("server", 21);  
             client.login("username", "password");
             System.out.println("status :: " + client.getReplyString());
             int reply = client.getReplyCode();
                if (!FTPReply.isPositiveCompletion(reply)) {
                    throw new Exception("Connect failed: " + client.getReplyString());
                }
                try {
                    client.enterLocalPassiveMode();
                    if (!client.setFileType(FTP.BINARY_FILE_TYPE)) {
                        Log.v(getClass().toString(), "Setting binary file type failed.");
                    }
                } catch(Exception e) {
                    e.printStackTrace();
                } 
             List<String> aa = checkFiles(client);
             System.out.println("check :: " +aa);
        } catch (Exception e) {
            System.out.println("status :: " + client.getReplyString());
        }
          return client;
    }

    private class task extends AsyncTask <Void, Void, FTPClient> {

        @Override
        protected void onPreExecute() {
            // Do stuff before the operation
        }


        @Override
        protected FTPClient doInBackground(Void... params) {
            FTPClient ftp = null;
            try {
                ftp = connectWithFTP();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    }

    public void disconnectWithFTP() throws IOException{
        client.logout();  
        client.disconnect();  
    }

   
   
    private List<String> checkFiles(FTPClient clients){
    	List<String> it = new ArrayList<String>();
          try {  
              FTPFile[] ftpFiles = clients.listFiles();  
              int length = ftpFiles.length;  
       
              for (int i = 0; i < length; i++) {  
                String name = ftpFiles[i].getName();                  
                it.add (name);
                
                Log.v("aasd", name);
             
              }    // System.out.println("showfile :: "+ it);
            } catch(Exception e) {  
              e.printStackTrace();  
            }  
          //System.out.println("showfile lol :: "+ it);
          return it;
    }

 
    @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;
    }

}




อันนี้เป็นไฟล์ xml
Code (Android-Java)
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
 
   	<TableRow
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" >
     
     <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="ListView and Checkbox : "
        android:layout_span="1"
        android:textAppearance="?android:attr/textAppearanceMedium" />
  	        
 	</TableRow>


	<View
		android:layout_height="1dip"
		android:background="#CCCCCC" />
	
  <RelativeLayout
      	android:layout_gravity="center_vertical|center_horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

 	 <Button
 	     android:id="@+id/btnCheckAll"
 	     android:layout_width="wrap_content"
 	     android:layout_height="wrap_content"
 	     android:layout_alignParentLeft="true"
 	     android:layout_alignParentTop="true"
 	     android:layout_marginLeft="49dp"
 	     android:text="Check All" />

 	 <Button
 	     android:id="@+id/btnClearAll"
 	     android:layout_width="wrap_content"
 	     android:layout_height="wrap_content"
 	     android:layout_alignParentTop="true"
 	     android:layout_marginLeft="36dp"
 	     android:layout_toRightOf="@+id/btnCheckAll"
 	     android:text="Clear All" />
 	 
 	</RelativeLayout>
 	
  <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.1">   
     
     <ListView
         android:id="@+id/listView1"
         android:layout_width="match_parent"
         android:layout_height="wrap_content">
     </ListView>
  	        
 	</LinearLayout>
 	
  <RelativeLayout
      	android:layout_gravity="center_vertical|center_horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

 	 <Button
 	     android:id="@+id/btnGetItem"
 	     android:layout_width="wrap_content"
 	     android:layout_height="wrap_content"
 	     android:layout_alignParentTop="true"
 	     android:layout_centerHorizontal="true"
 	     android:text="Get Item Checked" />
 	 
 	</RelativeLayout>
 	
	<View
		android:layout_height="1dip"
		android:background="#CCCCCC" />
   		  
   	
	
</TableLayout>



ประวัติการแก้ไข
2014-01-23 12:26:01
2014-01-23 20:21:24
2014-01-23 20:23:08
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-01-23 12:19:21 By : iamillusion
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : Android - - ช่วยดูโค้ดให้ทีค่ะ อยากให้มันโชว์ไฟล์ของ ftp server แต่พอรันโค้ดแล้วมมัน error T^T
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่