所以我一直在嘗試從我的數據庫中檢索基本上是帖子的 JSON 文件。它們可以從我正在運行的 Django REST API 中獲取。我可以訪問該網址并查看我網絡中任何設備的可用帖子。但是,我無法檢索它們,以便它們可以發布在我的 Android 應用程序上。postExecute我的登錄AsyncTask沒有顯示任何 JSON 對象,只是空的。它不會在我的 logcat 中返回任何錯誤消息,所以我不確定是什么問題。我正在嘗試制作原型社交網絡類型的東西,其中帖子存儲在我的數據庫內的數據庫中,并通過 API 獲取它們。我AsyncTask用來連接到我的 URL 并在那里進行處理Posts.javapublic class Posts extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_posts); PostsDetails postDetailsHelper = new PostsDetails(); postsDoneBtn = (Button) findViewById(R.id.PostsDoneButton); postDetailsHelper.callPostDetails("192.168.0.18:8000/api/"); postDetailsHelper.postDetailsCalled('n'); postsDoneBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(Posts.this, MainActivity.class)); } }); } public class PostsDetails { // calls the execute for AsyncTask private void callPostDetails(String theurl){ PostsHelper = new WSAdapter.SendPostsRequest(); // sets if post details are called postDetailsCalled('y'); // executes AsyncTask PostsHelper.execute(theurl); } }}
1 回答

阿晨1998
TA貢獻2037條經驗 獲得超6個贊
您需要將協議方案添加到您的 URL: http://
、https://
或您需要的任何其他內容。
所以它應該是這樣的:
postDetailsHelper.callPostDetails("http://192.168.0.18:8000/api/");
添加回答
舉報
0/150
提交
取消