gpt4 book ai didi

android - 我一直收到错误 "no value for url"

转载 作者:行者123 更新时间:2023-11-29 01:22:43 24 4
gpt4 key购买 nike

这是我的java代码。我的 android studio 中的 url 没有任何值(value)。我打算从 wamp 服务器的 sql 数据库中获取图像。

public class MainActivity extends AppCompatActivity implements 
View.OnClickListener{
private String imagesJSON;

private static final String JSON_ARRAY ="result";
private static final String IMAGE_URL = "url";

private JSONArray arrayImages= null;

private int TRACK = 0;

private static final String IMAGES_URL =
"http://192.168.43.214/apexStore2/image.php";

private Button buttonFetchImages;
private Button buttonMoveNext;
private Button buttonMovePrevious;
private ImageView imageView;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

imageView = (ImageView) findViewById(R.id.imageView);
buttonFetchImages = (Button) findViewById(R.id.buttonFetchImages);
buttonMoveNext = (Button) findViewById(R.id.buttonNext);
buttonMovePrevious = (Button) findViewById(R.id.buttonPrev);
buttonFetchImages.setOnClickListener(this);
buttonMoveNext.setOnClickListener(this);
buttonMovePrevious.setOnClickListener(this);
}


private void extractJSON(){
try {

JSONObject jsonObject = new JSONObject(imagesJSON);
arrayImages = jsonObject.getJSONArray(JSON_ARRAY);
} catch (JSONException e) {
e.printStackTrace();
}
}

private void showImage(){
try {
JSONObject jsonObject = arrayImages.getJSONObject(TRACK);
getImage(jsonObject.getString(IMAGE_URL));
} catch (JSONException e) {
e.printStackTrace();
}
}

private void moveNext(){
if(TRACK < arrayImages.length()){
TRACK++;
showImage();
}
}

private void movePrevious(){
if(TRACK>0){
TRACK--;
showImage();
}
}



private void getAllImages() {
class GetAllImages extends AsyncTask<String,Void,String>{
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(MainActivity.this, "Fetching
Data...","Please Wait...",true,true);
}

@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
imagesJSON = s;
extractJSON();
showImage();
}

@Override
protected String doInBackground(String... params) {
String uri = params[0];
BufferedReader bufferedReader = null;
try {
URL url = new URL(uri);
HttpURLConnection con = (HttpURLConnection)
url.openConnection();
con.setRequestProperty("Content-Type",
"application/json;charset=utf-8");
con.setRequestProperty("X-Requested-With",
"XMLHttpRequest");
StringBuilder sb = new StringBuilder();

bufferedReader = new BufferedReader(new
InputStreamReader(con.getInputStream()));

String json;
while((json = bufferedReader.readLine())!= null){
sb.append(json+"\n");
}

return sb.toString().trim();

}catch(Exception e){
return null;
}
}
}
GetAllImages gai = new GetAllImages();
gai.execute(IMAGES_URL);
}

private void getImage(String urlToImage){
class GetImage extends AsyncTask<String,Void,Bitmap>{
ProgressDialog loading;
@Override
protected Bitmap doInBackground(String... params) {
URL url = null;
Bitmap image = null;

String urlToImage = params[4];
try {
url = new URL(urlToImage);
image =
BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return image;
}

@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(MainActivity.this,"Downloading
Image...","Please wait...",true,true);
}

@Override
protected void onPostExecute(Bitmap bitmap) {
super.onPostExecute(bitmap);
loading.dismiss();
imageView.setImageBitmap(bitmap);
}
}
GetImage gi = new GetImage();
gi.execute(urlToImage);
}

@Override
public void onClick(View v) {
if(v == buttonFetchImages) {
getAllImages();
}
if(v == buttonMoveNext){
moveNext();
}
if(v== buttonMovePrevious){
movePrevious();
}
}

这是我的 PHP 代码。当我运行我的 php 代码时,我得到以下输出:

 {
"result": [{
"product_img1": "product-131.jpg"
}, {
"product_img1": "product-124.jpg"
}, {
"product_img1": "product-118.jpg"
}, {
"product_img1": "product-126.jpg"
}, {
"product_img1": "USM_New_Logo1.jpg"
}, {
"product_img1": "UI.PNG"
}, {
"product_img1": "cat402.PNG"
}, {
"product_img1": "launcher.png"
}]
}

我的 php 代码可以从 sql 数据库中获取图像,但是,我的 android studio 无法获取它。有什么解决办法吗?

<?php 
include ('classes/functions.php');

$check_product = "SELECT * FROM products WHERE cat_id = '0';";
$run_product_checking = mysqli_query($con, $check_product);
$result = array();
while($row = mysqli_fetch_array($run_product_checking)){
array_push($result,
array('product_img1'=>$row[4]

));
}

echo json_encode(array("result"=>$result));
?>

最佳答案

将 IP 地址更改为其域名值。

关于android - 我一直收到错误 "no value for url",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35859758/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com