2017-12-10 16 views
0

私のPHPを表示することはできません。JSONは、AndroidエミュレータでのListViewに

[ 
{ 
salesschedulename: "Visiting Client,", 
salesscheduledate: "2018-01-18", 
salesscheduletime: "10:30:00", 
salesscheduleaddress: "Auckland", 
salesscheduledescription: "Sales Visit" 
}, 
{ 
salesschedulename: "Hunting Client", 
salesscheduledate: "2018-01-21", 
salesscheduletime: "09:00:00", 
salesscheduleaddress: "Sidney", 
salesscheduledescription: "Sales Propose" 
}, 
{ 
salesschedulename: "Visitng Client", 
salesscheduledate: "2018-01-25", 
salesscheduletime: "09:00:00", 
salesscheduleaddress: "Bali, Indonesia", 
salesscheduledescription: "Sales Propose" 
} 

]

問題は次のとおりです:ここにPHPの結果の

<?php 

/* 
* Created by Spider Lynxz 
* Retrieve Data From MySQL Database in Android 
*/ 

//database constants 
require_once 'includes/config.php'; 

// Connecting to mysql database 
$conn = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE); 

// Call query 
    $query = "select sales_schedule_name,sales_schedule_date,sales_schedule_time,sales_schedule_address,sales_schedule_description from sales_schedule"; 


if ($stmt = $conn->prepare($query)) { 
    $stmt->execute(); 
    $stmt->bind_result($salesschedulename, $salesscheduledate, $salesscheduletime, $salesscheduleaddress, $salesscheduledescription); 


    if ($stmt > 0) { 
    $schedule = array(); 

    while ($stmt->fetch()) { 
     //printf("%s, %s, %s, %s, %s\n", $sales_schedule_name, $sales_schedule_date, $sales_schedule_time, $sales_schedule_address, $sales_schedule_description); 
     $temp = array(); 
     $temp['salesschedulename'] = $salesschedulename; 
     $temp['salesscheduledate'] = $salesscheduledate; 
     $temp['salesscheduletime'] = $salesscheduletime; 
     $temp['salesscheduleaddress'] = $salesscheduleaddress; 
     $temp['salesscheduledescription'] = $salesscheduledescription; 
     array_push($schedule, $temp); 

    } 
    }else 
    { 
    } 
    $stmt->close(); 
} 

//displaying the result in json format 
echo json_encode($schedule); 

このデータはできませんアンドロイドエミュレータで表示

リストビュー:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    tools:context="id.infision.dev.farminformationsystemhybrid.fragment.tabSchedule.ScheduleFragment" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <ListView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/schedule_list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 

</RelativeLayout> 

ScheduleList.Java

public class ScheduleList { 

    private String ScheduleName; 
    private String ScheduleDate; 
    private String ScheduleTime; 
    private String ScheduleAddress; 
    private String ScheduleDescription; 


    public ScheduleList(String scheduleName, String scheduleDate, String scheduleTime, String scheduleAddress, String scheduleDescription) { 
     ScheduleName = scheduleName; 
     ScheduleDate = scheduleDate; 
     ScheduleTime = scheduleTime; 
     ScheduleAddress = scheduleAddress; 
     ScheduleDescription = scheduleDescription; 
    } 

    public String getScheduleName() { 
     return ScheduleName; 
    } 

    public void setScheduleName(String scheduleName) { 
     ScheduleName = scheduleName; 
    } 

    public String getScheduleDate() { 
     return ScheduleDate; 
    } 

    public void setScheduleDate(String scheduleDate) { 
     ScheduleDate = scheduleDate; 
    } 

    public String getScheduleTime() { 
     return ScheduleTime; 
    } 

    public void setScheduleTime(String scheduleTime) { 
     ScheduleTime = scheduleTime; 
    } 

    public String getScheduleAddress() { 
     return ScheduleAddress; 
    } 

    public void setScheduleAddress(String scheduleAddress) { 
     ScheduleAddress = scheduleAddress; 
    } 

    public String getScheduleDescription() { 
     return ScheduleDescription; 
    } 

    public void setScheduleDescription(String scheduleDescription) { 
     ScheduleDescription = scheduleDescription; 
    } 

} 

最後ここに(サンプル+ JSONで)私のScheduleFragment.java

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout for this fragment 
    View view = inflater.inflate(R.layout.fragment_schedule, container, false); 

    final ArrayList<ScheduleList> schedule = new ArrayList<>(); 

    try { 

     JSONArray jsonArray=new JSONArray(getURL(AppConfig.URL_SCHEDULELIST)); 
     //iterate loop 
     for(int i=0;i<jsonArray.length();i++){ 

      //get the JSON Object 
      JSONObject schedules=jsonArray.getJSONObject(i); 


      //prepare data to schedule list 
      String scheduleName = schedules.getString("salesschedulename"); 
      String scheduleDate = schedules.getString("salesscheduledate"); 
      String scheduleTime = schedules.getString("salesscheduletime"); 
      String scheduleAddress = schedules.getString("salesscheduleaddress"); 
      String scheduleDescription = schedules.getString("salesscheduledescription"); 

      //adding the schedule to schedule list 

      schedule.add(new ScheduleList(scheduleName, scheduleDate, scheduleTime, scheduleAddress, scheduleDescription)); 

     } 



    } catch (Exception e) { 

     System.out.println(e.getMessage()); 

     Toast toast = Toast.makeText(
       //getActivity(),"Custom Toast From Fragment",Toast.LENGTH_LONG 
       getActivity().getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG 
     ); 
     // Set the Toast display position layout center 
     toast.setGravity(Gravity.CENTER,0,0); 
     // Finally, show the toast 
     toast.show(); 

    } 

    //sampledata 
    //schedule.add(new ScheduleList("test5", "test6", "test7", "test8", "test9")); 



    BindDictionary<ScheduleList> dictionary = new BindDictionary<>(); 
    dictionary.addStringField(R.id.sales_schedule_name, new StringExtractor<ScheduleList>() { 
     @Override 
     public String getStringValue(ScheduleList schedule1, int position) { 
      return schedule1.getScheduleName(); 
     } 
    }); 

    dictionary.addStringField(R.id.sales_schedule_date, new StringExtractor<ScheduleList>() { 
     @Override 
     public String getStringValue(ScheduleList schedule1, int position) { 
      return schedule1.getScheduleDate(); 
     } 
    }); 

    dictionary.addStringField(R.id.sales_schedule_time, new StringExtractor<ScheduleList>() { 
     @Override 
     public String getStringValue(ScheduleList schedule1, int position) { 
      return schedule1.getScheduleTime(); 
     } 
    }); 

    dictionary.addStringField(R.id.sales_schedule_address, new StringExtractor<ScheduleList>() { 
     @Override 
     public String getStringValue(ScheduleList schedule1, int position) { 
      return schedule1.getScheduleAddress(); 
     } 
    }); 

    dictionary.addStringField(R.id.sales_schedule_description, new StringExtractor<ScheduleList>() { 
     @Override 
     public String getStringValue(ScheduleList schedule1, int position) { 
      return schedule1.getScheduleDescription(); 
     } 
    }); 

    FunDapter adapter = new FunDapter(ScheduleFragment.this.getActivity(),schedule, R.layout.schedule_list_layout,dictionary); 

    ListView listView=(ListView) view.findViewById(R.id.schedule_list); 
    listView.setAdapter(adapter); 

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id){ 
      ScheduleList selecteditem = schedule.get(position); 
      Toast.makeText(ScheduleFragment.this.getActivity(),selecteditem.getScheduleName(), Toast.LENGTH_LONG).show(); 
     } 
    }); 

    return view; 

} 

public static String getURL(String url) throws Exception { 
    URL website = new URL(url); 
    URLConnection connection = website.openConnection(); 
    BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF8")); 

    StringBuilder response = new StringBuilder(); 
    String inputLine; 
    String result; 
    while ((inputLine = in.readLine()) != null) { 
     response.append(inputLine); 
    } 
    result=response.toString(); 
    in.close(); 

    return result; 
} 

そして、他の問題があり、それは私のデバイスが、カントショーに表示することができます他のデバイスとエミュレータで(ローカルおよび外部のPHPサーバーの両方)私はすでに入れdepedencies上

: コンパイル 'com.github.amigold.fundapter:ライブラリ:1.0'

と私はすでにあまりにもマニフェストに変更。

エラーは見つかりませんでしたが、エミュレータで表示できません。

そんなにはここ

を助けるために感謝し、私のAppConfig.java

public class AppConfig { 

    // Server user login url 
    public static String URL_LOGIN = "http://192.168.43.146/android/login.php"; 

    // Server user register url 
    public static String URL_REGISTER = "http://192.168.43.146/android/register.php"; 

    // Server user schedule url 
    public static String URL_SCHEDULELIST = "http://192.168.43.146/android/schedulelist.php"; 


    Server user schedule url 
    public static String URL_ITEMLIST = "http://192.168.43.146/android/itemlist.php"; 

} 

マイアンドロイドマニフェスト:あなたのScheduleFragment.java 012で

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="id.infision.dev.farminformationsystemhybrid" 
    xmlns:tool="http://schemas.android.com/tools" 


    android:versionCode="1" 
    android:versionName="1.0" 

    > 


    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 

    <uses-permission android:name="id.infision.dev.farminformationsystemhybrid.permission.MAPS_RECEIVE"/> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> 
    <uses-permission android:name="android.permission.CAMERA" /> 


    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true"/> 

    <permission 
     android:name="com.example.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature"/> 


    <uses-sdk 
     android:minSdkVersion="19" 
     android:targetSdkVersion="27" /> 


    <application 
     android:name=".app.AppController" 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:roundIcon="@mipmap/ic_launcher_round" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme" 
     tool:replace="android:icon"> 

     <meta-data 
      android:name="com.google.android.maps.v2.API_KEY" 
      android:value="@string/google_maps_key" 
      /> 


     <meta-data 
      android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" 
      /> 


     <activity 
      android:name=".activity.Splashscreen" 
      android:label="@string/app_name" 
      android:launchMode="singleTop" 
      android:windowSoftInputMode="adjustPan"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".activity.LoginActivity" 
      android:label="@string/app_name" 
      android:launchMode="singleTop" 
      android:windowSoftInputMode="adjustPan" /> 
     <activity 
      android:name=".activity.RegisterActivity" 
      android:label="@string/app_name" 
      android:launchMode="singleTop" 
      android:windowSoftInputMode="adjustPan" /> 
     <activity 
      android:name=".activity.Login_main" 
      android:label="@string/app_name" 
      android:launchMode="singleTop" /> 
     <activity 
      android:name=".activity.MainActivity" 
      android:label="@string/title_activity_main" 
      android:theme="@style/AppTheme.NoActionBar"></activity> 

    </application>  

A B

+0

これを置く(デバイス対エミュレータ).. – Hansa

+0

あなたの提案に感謝します。 –

答えて

1

エミュレータでgoogleplayを更新した後、すべて正常に動作しています。 やご質問は、環境をランタイムに主に関連すると思われるようあなたは、Androidのエミュレータタグを追加する必要があります主な活動にすべてのあなたのための

if (android.os.Build.VERSION.SDK_INT > 9) { 
     StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
     StrictMode.setThreadPolicy(policy); 
    } 

おかげで(SuperFADX、ハンザ及びその他)

+0

はあなたの問題が解決したようです。問題が解決したことを一目で分かるように、回答があればそれを受け入れることを検討してください。 – Hansa

0

変更この行:このいずれかで

JSONArray jsonArray=new JSONArray(getURL(AppConfig.URL_SCHEDULELIST)); 

String page = new Communicator().executeHttpGet(AppConfig.URL_SCHEDULELIST); 
JSONArray jsonArray = new JSONArray(page); 

そして、それは正しくロードかどうかを確認するためにあなたのエミュレータのWebブラウザに手動でURLを開こう。

+0

私はすでに自分の問題を編集しています。そして、私は自分のローカルホストで動作するAppConfig.javaを見ることができます。ローカルホストと外部ホストのどちらも同じ結果でした。他のデバイスやエミュレータに表示されない。私のデバイスに表示されます。 –

+0

まだ何も起こらない。私は私のマニフェストを見てみましょう –

+0

私は私のエミュレータでインターネットを持っています。私はいつか私のGmailを開いていました。 –

関連する問題