Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用android studio和ms sql数据库在android应用程序中不显示图像_Java_Android_Android Recyclerview - Fatal编程技术网

Java 使用android studio和ms sql数据库在android应用程序中不显示图像

Java 使用android studio和ms sql数据库在android应用程序中不显示图像,java,android,android-recyclerview,Java,Android,Android Recyclerview,我正在开发一个项目内容列表应用程序 关于我的应用程序,内容正在使用MS Sql server数据库通过.NET webapp上载。我需要在移动应用程序上显示内容 我使用的是android studio 3.5.1版 一切正常,但图像无法显示。 它显示的是spinner,而不是图像 build.gradle apply plugin: 'com.android.application' android { compileSdkVersion 29 buildToolsVe

我正在开发一个项目内容列表应用程序
关于我的应用程序,内容正在使用MS Sql server数据库通过.NET webapp上载。我需要在移动应用程序上显示内容 我使用的是android studio 3.5.1版

一切正常,但图像无法显示。 它显示的是spinner,而不是图像

build.gradle

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    defaultConfig {
        applicationId "com.test.www.appname"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    dexOptions {
        //incremental true
        javaMaxHeapSize "4g"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {

    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    testImplementation 'junit:junit:4.12'
    implementation files('libs/jtds-1.2.7.jar')
    implementation files('libs/ftp4j-1.6.jar')
    implementation 'com.github.chrisbanes:PhotoView:2.0.0'


}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="1dp">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/relContainer">
        <Spinner
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:textSize="18dp"
            android:layout_marginTop="20dp"
            android:background="@drawable/spinner_selector"
            android:id="@+id/spncategory"/>

    <LinearLayout
        android:id="@+id/wrapper"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/spncategory"
        android:layout_centerHorizontal="true"
        android:orientation="vertical">
        <!--  Recycler View  -->
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_marginTop="15dp"
            android:layout_width="match_parent"
            android:layout_height="328dp"
            android:clipToPadding="false"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="0dp" />

    </LinearLayout>
</RelativeLayout>
</ScrollView>
库布局xml文件

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    defaultConfig {
        applicationId "com.test.www.appname"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    dexOptions {
        //incremental true
        javaMaxHeapSize "4g"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {

    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    testImplementation 'junit:junit:4.12'
    implementation files('libs/jtds-1.2.7.jar')
    implementation files('libs/ftp4j-1.6.jar')
    implementation 'com.github.chrisbanes:PhotoView:2.0.0'


}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="1dp">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/relContainer">
        <Spinner
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:textSize="18dp"
            android:layout_marginTop="20dp"
            android:background="@drawable/spinner_selector"
            android:id="@+id/spncategory"/>

    <LinearLayout
        android:id="@+id/wrapper"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/spncategory"
        android:layout_centerHorizontal="true"
        android:orientation="vertical">
        <!--  Recycler View  -->
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_marginTop="15dp"
            android:layout_width="match_parent"
            android:layout_height="328dp"
            android:clipToPadding="false"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="0dp" />

    </LinearLayout>
</RelativeLayout>
</ScrollView>
RecycleView\u ActivityFragment.java

package com.test.www.appname;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;


public class Gallery extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.gallerylayout, container, false);
        return rootView;
    }
}


package com.test.www.appname;

import android.animation.Animator;
import android.app.ProgressDialog;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Set;
import java.util.TimeZone;

import static android.content.Context.MODE_PRIVATE;


public class RecyclerView_ActivityFragment extends Fragment {
    private static RecyclerView recyclerView;
    ProgressDialog pbd;
    ArrayList<String> galleryadpter;
    Set<String> set;
    private static final String MyPref ="" ;
    ConnectionClass connectionClass;
    String Item="";
    int ItemId;
    TextView txtitemid;
    String img;
    String title;
    EditText edtgacustname,edtgamobileno,edtgaemail;
    int imgid;
    String datein="";
    String timein="";
    private Spinner spncategory;
    private Animator mCurrentAnimator;
    private int mShortAnimationDuration;
    private Button btnlike,btngasubmit;
    int RegIdNo;
    private final String TAG="GAlleryFragment";
    SharedPreferences prefse;
    private static String navigateFrom;//String to get Intent Value
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.gallerylayout, container, false);
        connectionClass=new ConnectionClass();
        navigateFrom = getActivity().getIntent().getStringExtra("pass_ga");//Get Intent Value in String
        ItemnameBind itemnameBind=new ItemnameBind();
        itemnameBind.execute("");
        String strtext;
        if(navigateFrom==null){
            strtext = getArguments().getString("edttext");
            navigateFrom=strtext;
        }else {

            Log.d(TAG,"Not-Success");
        }

        spncategory=(Spinner)rootView.findViewById(R.id.spncategory);
        edtgacustname=(EditText)rootView.findViewById(R.id.edtgacustname);
        edtgamobileno=(EditText)rootView.findViewById(R.id.edtgamobileno);
        edtgaemail=(EditText)rootView.findViewById(R.id.edtgaemail);
        txtitemid=(TextView)rootView.findViewById(R.id.txtitemid);
        Datetime1();
        recyclerView=(RecyclerView)rootView.findViewById(R.id.recycler_view);
        btngasubmit=(Button)rootView.findViewById(R.id.btngasubmit);
        btnlike=(Button)rootView.findViewById(R.id.btnlike);
        if (navigateFrom.equals("pass_gallery")) {
            recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
        }

        prefse =this.getActivity().getSharedPreferences(MyPref, MODE_PRIVATE);
        prefse.edit().remove("yourKey").commit();
        btnlike.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {

                    set = prefse.getStringSet("yourKey", null);

                    if((set==null)||set.size()==0) {

                    Toast.makeText(getActivity(),"Please Select Image",Toast.LENGTH_SHORT).show();
                    }
                    else {
                        galleryadpter = new ArrayList<String>(set);
                        set.clear();
                        spncategory.setVisibility(View.GONE);
                        recyclerView.setVisibility(View.GONE);
                        btnlike.setVisibility(View.GONE);
                        edtgacustname.setVisibility(View.VISIBLE);
                        edtgamobileno.setVisibility(View.VISIBLE);
                        edtgaemail.setVisibility(View.VISIBLE);
                        btngasubmit.setVisibility(View.VISIBLE);
                    }

                }
                catch (Exception ex){
                    throw ex;
                }

            }
        });

        //button submit action
btngasubmit.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Savedata();

    }
});



        return rootView;
    }
    public void Datetime1(){
        Calendar c = Calendar.getInstance();
        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy/MM/dd");
        // TODO: Avoid using the abbreviations when fetching time zones.
        // Use the full Olson zone ID instead.
        dateformat.setTimeZone(TimeZone.getTimeZone("IST"));
        datein = dateformat.format(c.getTime());
        SimpleDateFormat timeformat = new SimpleDateFormat("hh:mm aa");
        timein = timeformat.format(c.getTime());
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home:
               getActivity().finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }


    //Itemname Bind the method

    public class ItemnameBind extends AsyncTask<String, String, String> {
        ArrayList listitemname=new ArrayList();
        String Y;
        @Override
        protected String doInBackground(String... params) {
            try{
                Connection con=connectionClass.CONN();
                if(con==null){
                    Y="Error in connection with SQL server";
                }
                else {
                    String query="Select Category from FD_Category where DataStatus=1";
                    PreparedStatement preparedStatement=con.prepareStatement(query);
                    ResultSet rs=preparedStatement.executeQuery();
                    while (rs.next()){
                        String itemname1=rs.getString("Category");
                        listitemname.add(itemname1);
                    }
                    Y = "Success";
                }
            } catch (Exception ex) {
                Y = ex.toString();

            }
            return Y;
        }

        @Override
        protected void onPreExecute() {

        }

        @Override
        protected void onPostExecute(String s) {
           /* if(pbd.isShowing())
                pbd.dismiss();*/
            if(s!="Success"){
                Toast.makeText(getActivity(),s,Toast.LENGTH_SHORT).show();
            }
            ArrayAdapter ownnamedapter=new ArrayAdapter(getActivity(),android.R.layout.simple_spinner_dropdown_item, listitemname);
            spncategory.setAdapter(ownnamedapter);
            ownnamedapter.notifyDataSetChanged();
            spncategory.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    Item=spncategory.getSelectedItem().toString();
                    ItemIdBind itemidbind=new ItemIdBind();
                    itemidbind.execute("");
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {

                }
            });
        }

    }
    public class ItemIdBind extends AsyncTask<String,String,String> {
        String Y="";
        @Override
        protected String doInBackground(String... params) {
            try{
                Connection con=connectionClass.CONN();
                if(con==null){
                    Y="Error with Sql Connection";
                }
                else {
                    String query="Select * from FD_Category where Category='"+Item+"'";
                    PreparedStatement preparedStatement=con.prepareStatement(query);
                    ResultSet rs=preparedStatement.executeQuery();
                    while (rs.next()){
                        ItemId=rs.getInt("Id");

                    }
                    Y = "Success";
                }

            }
            catch (Exception ex){
                Y=ex.toString();
            }
            return Y;
        }

        @Override
        protected void onPreExecute() {

        }

        @Override
        protected void onPostExecute(String s) {

            if(s!="Success") {
                Toast.makeText(getActivity(), s, Toast.LENGTH_SHORT).show();
            }
            txtitemid.setText(String.valueOf(ItemId));
            Fetch fetch=new Fetch();
            fetch.execute("");
            super.onPostExecute(s);
        }
    }

//save method

    private void Savedata(){
        String custnamega=edtgacustname.getText().toString();
        String Mobilenoga=edtgamobileno.getText().toString();
        String emailidga=edtgaemail.getText().toString();
         /*Set<String> set = prefse.getStringSet("yourKey", null);
                    ArrayList<String> addapterarraylist1 = new ArrayList<String>(set);

                    for (String temp1 : addapterarraylist1) {
                        System.out.println(temp1);
                        Toast.makeText(getActivity(), temp1, Toast.LENGTH_SHORT).show();
                    }*/

        if(custnamega.length()==0){
            edtgacustname.requestFocus();
            edtgacustname.setError("Enter the Name");
        }
        else if(Mobilenoga.length()==0||Mobilenoga.length()<10){
            edtgamobileno.requestFocus();
            edtgamobileno.setError("Enter 10 digit mobile number");
        }
        else if(emailidga.length()==0){
            edtgaemail.requestFocus();
            edtgaemail.setError("Enter the Email Id");
        }
        else {
            InsertGallerydata insertgallerydata=new InsertGallerydata();
            insertgallerydata.execute("");

        }

    }


    public class Fetch extends AsyncTask<String, String, String> {

        String z = "";
        String ownid;

        ArrayList<Data_Model> arrayList=new ArrayList<>();

        @Override
        protected void onPreExecute() {

            pbd=new ProgressDialog(getActivity());
            pbd.setMessage("Please Wait...");
            pbd.setCancelable(false);
            pbd.show();
        }
        @Override
        protected void onPostExecute(String r) {
            // pbbar.setVisibility(View.GONE);
            if (pbd.isShowing())
                pbd.dismiss();
            if(r!="Success"){
                Toast.makeText(getActivity(), r, Toast.LENGTH_SHORT).show();
            }
            try {
            RecyclerView_Adapter adapter = new RecyclerView_Adapter(getActivity(), arrayList);
            recyclerView.setAdapter(adapter);// set adapter on recyclerview
            adapter.notifyDataSetChanged();// Notify the adapter

}
catch (Exception ex){
    z= ex.toString();
    Toast.makeText(getActivity(),z,Toast.LENGTH_SHORT).show();
}
        }
        @Override
        protected String doInBackground(String... params) {
            try {
                Connection con = connectionClass.CONN();
                if (con == null) {
                    z = "Error in connection with SQL server";
                } else {//
                    String query="";
                    query = "select Id,ItemName,Image from FD_ItemMaster where CatId='"+ItemId+"' and DataStatus=1 order by Id desc";
                    PreparedStatement ps2 = con.prepareStatement(query);
                    ResultSet rs2 = ps2.executeQuery();
                    ArrayList data1 = new ArrayList();
                    while (rs2.next()) {
                        imgid=rs2.getInt("Id");
                         title = rs2.getString("ItemName");
                          img = rs2.getString("Image");

                        //Convertong Images string to bitmap
                       // byte[] decodeString = Base64.decode(img, Base64.DEFAULT);
                        //Bitmap decodebitmap = BitmapFactory.decodeByteArray(decodeString, 0, decodeString.length);
                        arrayList.add(new Data_Model(title,img,imgid));

                    }

                        z="Success";
                }

            } catch (Exception ex) {
                z = ex.toString();

            }
            return z;

        }
    }

    public class InsertGallerydata extends AsyncTask<String,String,String> {
        String Z="";
       // int CustGaId=imgid;
        String Itemnumber;
        int CatGaId=ItemId;
        String custnamega=edtgacustname.getText().toString();
        String Mobilenoga=edtgamobileno.getText().toString();
        String emailidga=edtgaemail.getText().toString();



        @Override
        protected String doInBackground(String... strings) {
            try{
//Set<String> set=prefse.getStringSet("yourKey", null);
             //   galleryadpter=new ArrayList<String >();
                for(String temp:galleryadpter){
                    Itemnumber=temp;
                    Connection con=connectionClass.CONN();
                    if(con==null){
                        Z = "Error in connection with SQL server";
                    }
                    else {
                        String query = "";
                        String Like="L";

                        query = "Insert into FD_Enquiry(ItemId,CategoryId,CustName,CustMobileNo,CustEmailId,EnqDate,TypeOf)values('" + Itemnumber + "','" + ItemId + "','" + custnamega + "','" + Mobilenoga + "','" + emailidga + "','" + datein + "','"+Like+"')";
                        PreparedStatement pr = con.prepareStatement(query);
                        pr.executeUpdate();
                        // super.onPostExecute(s);
                        Z = "success";
                    }
                }
            }
            catch (Exception ex)
            {
                Z= ex.toString();
            }

            return Z;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected void onPostExecute(String s) {
           // Toast.makeText(getActivity(),s,Toast.LENGTH_SHORT).show();
            if(!s.equals("success")){
                Toast.makeText(getActivity(),s,Toast.LENGTH_SHORT).show();
            }else {
                Fetch fe=new Fetch();
                fe.execute("");
                Toast.makeText(getActivity(), "Saved Successfully..!", Toast.LENGTH_SHORT).show();
                spncategory.setVisibility(View.VISIBLE);
                recyclerView.setVisibility(View.VISIBLE);
                btnlike.setVisibility(View.VISIBLE);
                edtgacustname.setVisibility(View.GONE);
                edtgamobileno.setVisibility(View.GONE);
                edtgaemail.setVisibility(View.GONE);
                btngasubmit.setVisibility(View.GONE);
                reset();
            }
            super.onPostExecute(s);
        }
    }
    void reset(){
        edtgacustname.setText("");
        edtgaemail.setText("");
        edtgamobileno.setText("");
        galleryadpter.clear();
        set.clear();

    }


}


提前感谢

您确定可以在
获取
任务中获取数据吗?是的,我添加了完整代码请检查您确定可以在
获取
任务中获取数据吗?是的,我添加了完整代码请检查