這是我的類文件,它擴展了FragmentActivity。我不確定我是否做得對。我想在這個活動中有一個標籤式佈局,但應用程序不斷崩潰。從AsynTask開始片段活動
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_booking);
viewPager = (ViewPager)findViewById(R.id.viewPager);
viewPager.setAdapter(new CustomAdapter(getSupportFragmentManager(), getApplicationContext()));
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
tabLayout.setupWithViewPager(viewPager);
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener(){
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
});
}
private class CustomAdapter extends FragmentPagerAdapter {
private String fragments [] = {"A","B"};
public CustomAdapter(FragmentManager supportFragmentManager, Context applicationContext) {
super(supportFragmentManager);
}
@Override
public Fragment getItem(int position) {
switch (position){
case 0: return new fragment1();
case 1: return new fragment2();
default:return null;
}
}
@Override
public int getCount() {
return fragments.length;
}
@Override
public CharSequence getPageTitle(int position) {
return fragments[position];
}
}
When I pass an intent from the AsynTask like so
Intent intent;
intent = new Intent(m_context, booking.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
m_context.startActivity(intent);```
My app builds but crashes with the error
```
錯誤充氣類 android.support.v7.widget.ScrollingTabContainerView.TabView
02-23 16:54:11.061 14404-14404/com。示例.application_name E/AndroidRuntime:致命例外:main 進程:com.example.application_name,PID:14404 java.lang.RuntimeException:無法啓動活動 ComponentInfo {com.example.appli cation_name/com.example.application_name.booking}: android.view.InflateException:二進制XML文件行#7:錯誤 充氣類 android.support.v7.widget.ScrollingTabContainerView.TabView 在 android.app.ActivityThread。 performLaunchActivity(ActivityThread.java:2198) 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257) 在android.app.ActivityThread.access $ 800(ActivityThread.java:139) 在 android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1210) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5086) at java.lang.reflect.Method.invokeNative(Native Method) at java .lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit。 main(ZygoteInit.java:601) at dalvik.system.NativeStart.main(Native Method) 引起:android.view.InflateException:二進制XML文件行#7: 錯誤膨脹類 android.support.v7.widget.ScrollingTabContainerView.TabView 在 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707) 在android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 在android.view .LayoutInflater.inflate(LayoutInflater.java:492) 在android.view.LayoutInflater.inflate(LayoutInflater.java:397) 在android.view.LayoutInflater.inflate(LayoutInflater.java:353) 在 android.support。 v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) at android.support.v7.app.AppCom patActivity.setContentView(AppCompatActivity.java:109) at com.example.webook.webook.booking.onCreate(booking.java:29) at android.app.Activity.performCreate(Activity.java:5248) at android .app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110) at android.app.ActivityThread.performLaunchActivity(ActivityThread。Java的:2162) 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257) 在android.app.ActivityThread.access $ 800(ActivityThread.java:139) 在 android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1210) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread .java:5086) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) 在 com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:785) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 在dalvik.system.NativeStart .main(Native Method) 引起:java.lang.ClassNotFoundException:在路徑中找不到類 「android.support.v7.widget.ScrollingTabContainerView.TabView」: DexPathList [[zip文件 「/ data/app /com.example.webook.webook-2.apk"],nativeLibraryDirectories=[nativeLibraryDirectories=[nativeLibrary/app-lib/com.example.webook.webook-2, /vendor/lib,/ system/lib]] at dalvik.system.BaseDexClassLoader.findClass(B aseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:497) at java.lang.ClassLoader.loadClass(ClassLoader.java:457) at android.view.LayoutInflater.createView(LayoutInflater。的java:559) 在 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 在android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 在android.view.LayoutInflater.inflate(LayoutInflater.java :492) at android.view.LayoutInflater.inflate(LayoutInflater.java:397) at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 在 android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) 在 android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 在com.example.webook。 webook.booking.onCreate(booking.java:29) 在android.app.Activity.performCreate(Activity.java:5248) 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110) 在 機器人。 app.ActivityThread.performLaunchActivity(ActivityThread.java:2162) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257) at android.app.ActivityThread.access $ 800(ActivityThread.java:139) at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1210 ) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5086) 在java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os。ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:785) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 在dalvik.system.NativeStart.main(本機方法)```
這是我Asyntask
package com.example.webook.webook;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.JsonRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
/**
* Created by bhargavpanth on 10/02/16.
*/
public class LoginAsyncTask extends android.os.AsyncTask<String, Integer, String>{
Context m_context;
String m_name,m_email,m_password;
public LoginAsyncTask(Context context, String email, String pasword){
m_context = context;
m_email=email;
m_password=pasword;
}
@Override
protected String doInBackground(String... params) {
Looper.prepare();
try{
final RequestQueue queue = Volley.newRequestQueue(m_context);
JSONObject js = new JSONObject();
try {
JSONObject jsonobject_one = new JSONObject();
JSONObject jsonobject = new JSONObject();
jsonobject.put("csrf_token", "");
js.put("params", jsonobject);
}catch (Exception e) {
e.printStackTrace();
}
//https://webook.trabacus.com/webook/csrf_token
JsonObjectRequest jsonObjReq = new JsonObjectRequest(
Request.Method.POST,"https://webook.trabacus.com/webook/csrf_token", js,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// Log.d("tagd", response.result.csrf_token());
try{
JSONObject ob=response.getJSONObject("result");
String csrf=ob.getString("csrf_token");
//rid,csrf,name,email,password
JSONObject js = new JSONObject();
try {
JSONObject jsonobject = new JSONObject();
jsonobject.put("csrf_token",csrf);
jsonobject.put("login",m_email);
jsonobject.put("password",m_password);
jsonobject.put("db","Odoo-9");
js.put("params", jsonobject);
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST, "https://webook.trabacus.com/webook/login", js, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("tagd", response.toString());
Intent intent;
intent = new Intent(m_context, booking.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
m_context.startActivity(intent);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("tagd",error.toString());
}
}){
@Override
public Map<String, String> getHeaders(){
HashMap<String,String> headers=new HashMap<>();
headers.put("Content-Type","application/json; charset=utf-8");
return headers;
}
};
queue.add(jsonObjReq);
}catch (Exception e) {
e.printStackTrace();
}
Log.d("tagd",ob.getString("csrf_token"));
}catch (Exception e){
}
// msgResponse.setText(response.toString());
// hideProgressDialog();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("tagd", "Error: " + error.getMessage());
// hideProgressDialog();
}
}) {
/**
* Passing some request headers
*/
@Override
public Map<String, String> getHeaders() {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}
};
queue.add(jsonObjReq);
// StringRequest sr = new StringRequest(Request.Method.POST, "https://webook.trabacus.com/webook/csrf_token", new Response.Listener<String>() {
// @Override
// public void onResponse(String response) {
// Log.d("tagd",response);
// }
// }, new Response.ErrorListener() {
// @Override
// public void onErrorResponse(VolleyError error) {
// Toast.makeText(m_context,error.toString(),Toast.LENGTH_LONG).show();
// }
// }){
// @Override
// protected Map<String, String> getParams(){
// Map<String,String> params = new HashMap<String, String>();
// params.put("csrf_token","");
// return params;
// }
//
// @Override
// public Map<String, String> getHeaders(){
// Map<String,String> params = new HashMap<String, String>();
// params.put("Content-Type","application/x-www-form-urlencoded");
// return params;
// }
// };
// queue.add();
}catch (Exception e){
Toast.makeText(m_context,e.toString(),Toast.LENGTH_LONG).show();
}
return null;
}
}
```
什麼是錯誤到底是什麼?請顯示整個堆棧跟蹤 –
同時顯示任務 –
http://stackoverflow.com/a/27007448/3817374您可以檢查此 – Beena