正在尝试创建一个用于上传图像和文本的应用,上传后在服务器中成功。当我尝试在android应用中查看上传的图像时遇到上述错误,请确认我不是专家,还是中间人
public class ItemsActivity extends AppCompatActivity {
InterstitialAd interstitialAd;
AdView adView;
String category = "";
class Teacher{
private String name,description,location,contacts,imageURL;
public Teacher(String name, String description, String location, String contacts,String imageURL) {
this.name = name;
this.description = description;
this.location=location;
this.contacts=contacts;
this.imageURL = imageURL;
}
public String getName() {return name;}
public String getDescription() { return description; }
public String getContacts() {return contacts;}
public String getLocation() {return location;}
public String getImageURL() { return imageURL; }
}
/*
Class to adapt data from grid vie/ row model
*/
public class GridViewAdapter extends BaseAdapter {
Context c;
ArrayList<Teacher> teachers;
public GridViewAdapter(Context c, ArrayList<Teacher> teachers) {
this.c = c;
this.teachers = teachers;
}
@Override
public int getCount() {return teachers.size();}
@Override
public Object getItem(int i) {return teachers.get(i);}
@Override
public long getItemId(int i) {return i;}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
if(view==null)
{
view= LayoutInflater.from(c).inflate(R.layout.row_model,viewGroup,false);
}
TextView txtName = view.findViewById(R.id.nameTextView);
TextView txtDescription = view.findViewById(R.id.descriptionTextView);
TextView txtLocation = view.findViewById(R.id.location);
TextView txtContacts = view.findViewById(R.id.contacts);
ImageView teacherImageView = view.findViewById(R.id.imageView);
final Teacher teacher= (Teacher) this.getItem(i);
txtName.setText(teacher.getName());
txtDescription.setText(teacher.getDescription());
txtLocation.setText(teacher.getLocation());
txtContacts.setText(teacher.getContacts());
if(teacher.getImageURL() != null && teacher.getImageURL().length() > 0)
{
Log.i("message", teacher.getImageURL());
Picasso.get().load(teacher.getImageURL()).placeholder(R.drawable.tracy).into(teacherImageView);
}else {
Toast.makeText(c, "Empty Image URL", Toast.LENGTH_LONG).show();
Picasso.get().load(R.drawable.tracy).into(teacherImageView);
}
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
interstitialAd.show();
Toast.makeText(c, teacher.getName(), Toast.LENGTH_SHORT).show();
}
});
return view;
}
}
/*
Our HTTP Client
*/
public class DataRetriever {
//Connecting to my SQL server use correct Url
private static final String PHP_MYSQL_SITE_URL="http://192.168.0.190/BuySellNigeria/index.php";
private static final String PHP_MYSQL_SITE_IMAGE="http://192.168.0.190/BuySellNigeria/images/";
//INSTANCE FIELDS
private final Context c;
private GridViewAdapter adapter ;
public DataRetriever(Context c) { this.c = c; }
/*
RETRIEVE/SELECT/REFRESH
*/
public void retrieve(final GridView gv, final ProgressBar myProgressBar)
{
final ArrayList<Teacher> teachers = new ArrayList<>();
myProgressBar.setIndeterminate(true);
myProgressBar.setVisibility(View.VISIBLE);
AndroidNetworking.get(PHP_MYSQL_SITE_URL + "?category=" + category)
.setPriority(Priority.MEDIUM)
.build()
.getAsJSONArray(new JSONArrayRequestListener() {
@Override
public void onResponse(JSONArray response) {
Log.i("message", String.valueOf(response));
JSONObject jo;
Teacher teacher;
try
{
for(int i=0;i<response.length();i++)
{
jo=response.getJSONObject(i);
int id=jo.getInt("id");
String imageURL=jo.getString("teacher_image_url");
String name=jo.getString("teacher_name");
String description=jo.getString("teacher_description");
String location=jo.getString("location");
String contacts=jo.getString("contacts");
//String category=jo.getString("category");
teacher=new Teacher(name,description,location,contacts,PHP_MYSQL_SITE_IMAGE+imageURL);
teachers.add(teacher);
}
//SET TO SPINNER
adapter =new GridViewAdapter(c,teachers);
gv.setAdapter(adapter);
myProgressBar.setVisibility(View.GONE);
}catch (JSONException e)
{
myProgressBar.setVisibility(View.GONE);
Toast.makeText(c, "GOOD RESPONSE BUT JAVA CAN'T PARSE JSON IT RECEIEVED. "+e.getMessage(), Toast.LENGTH_LONG).show();
}
}
//ERROR
(这是当我单击按钮以检查发布在本地主机服务器中的项目时错误回显的地方。请帮助我尝试检查google中的每个位置,但是我没有答案)
@Override
public void onError(ANError anError) {
anError.printStackTrace();
myProgressBar.setVisibility(View.GONE);
Toast.makeText(c, "UNSUCCESSFUL : ERROR US : "+anError.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
category = intent.getStringExtra("category");
setContentView(R.layout.activity_items);
GridView myGridView=findViewById(R.id.myGridView);
ProgressBar myDataLoaderProgressBar=findViewById(R.id.myDataLoaderProgressBar);
MobileAds.initialize(this, "ca-app-pub-2870870041610409/1561856277");
adView = (AdView) findViewById(R.id.adView);
AdRequest request = new AdRequest.Builder().build();
adView.loadAd(request);
//
MobileAds.initialize(this, "ca-app-pub-2870870041610409/1561856277");
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId("ca-app-pub-2870870041610409/9057202918");
interstitialAd.loadAd(new AdRequest.Builder().build());
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
interstitialAd.show();
}
@Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
}
@Override
public void onAdOpened() {
// Code to be executed when the ad is displayed.
}
@Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
@Override
public void onAdClosed() {
// Code to be executed when the interstitial ad is closed.
}
});
new DataRetriever(ItemsActivity.this).retrieve(myGridView,myDataLoaderProgressBar);
}
}
enter code here