android.view.InflateException:错误膨胀类

时间:2013-09-09 18:37:30

标签: java android android-layout

我正在尝试从主要活动中调用新页面。主要活动包含按钮ButtononClick我正在启动新页面,如下所示

@Override
public void onClick(View arg0) {
  if(arg0.getId() == R.id.buttonSearch){
        //define a new Intent for the second Activity
        Intent intent = new Intent(this,SearchActivity.class);
        //start the second Activity
        this.startActivity(intent);
    }
}

加载新页面时我收到错误:

this.setContentView(R.layout.searchm);

以下是载入页面的代码

public class SearchActivity extends Activity   {

 Context context;    
 @Override
 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.searchm);

LOGCAT如下:

    09-09 14:05:23.766: E/MapActivity(1163): Couldn't get connection factory client
    09-09 14:11:22.036: E/AndroidRuntime(1163): FATAL EXCEPTION: main
    09-09 14:11:22.036: E/AndroidRuntime(1163): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidhive.googlemaps/com.androidhive.googlemaps.SearchActivity}: java.lang.NullPointerException
    09-09 14:11:22.036: E/AndroidRuntime(1163):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
    09-09 14:11:22.036: E/AndroidRuntime(1163):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
    09-09 14:11:22.036: E/AndroidRuntime(1163):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
    09-09 14:11:22.036: E/AndroidRuntime(1163):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
    09-09 14:11:22.036: E/AndroidRuntime(1163):     at android.os.Handler.dispatchMessage(Handler.java:99)
    09-09 14:11:22.036: E/AndroidRuntime(1163):     at android.os.Looper.loop(Looper.java:137)
    09-09 14:11:22.036: E/AndroidRuntime(1163):     at android.app.ActivityThread.main(ActivityThread.java:5103)
    09-09 14:11:22.036: E/AndroidRuntime(1163):     at java.lang.reflect.Method.invokeNative(Native Method)
    09-09 14:11:22.036: E/AndroidRuntime(1163):     at java.lang.reflect.Method.invoke(Method.java:525)
    09-09 14:11:22.036: E/AndroidRuntime(1163):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    09-09 14:11:22.036: E/AndroidRuntime(1163):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    09-09 14:11:22.036: E/AndroidRuntime(1163):     at dalvik.system.NativeStart.main(Native Method)
    09-09 14:11:22.036: E/AndroidRuntime(1163): Caused by: java.lang.NullPointerException
    09-09 14:11:22.036: E/AndroidRuntime(1163):     at com.androidhive.googlemaps.SearchActivity.onCreate(SearchActivity.java:113)
    09-09 14:11:22.036: E/AndroidRuntime(1163):     at android.app.Activity.performCreate(Activity.java:5133)
    09-09 14:11:22.036: E/AndroidRuntime(1163):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    09-09 14:11:22.036: E/AndroidRuntime(1163):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
    09-09 14:11:22.036: E/AndroidRuntime(1163):     ... 11 more
    09-09 14:14:15.676: E/MapActivity(1226): Couldn't get connection factory client
    09-09 14:14:27.676: E/AndroidRuntime(1226): FATAL EXCEPTION: main
    09-09 14:14:27.676: E/AndroidRuntime(1226): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidhive.googlemaps/com.androidhive.googlemaps.SearchActivity}: java.lang.NullPointerException
    09-09 14:14:27.676: E/AndroidRuntime(1226):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
    09-09 14:14:27.676: E/AndroidRuntime(1226):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
    09-09 14:14:27.676: E/AndroidRuntime(1226):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
    09-09 14:14:27.676: E/AndroidRuntime(1226):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
    09-09 14:14:27.676: E/AndroidRuntime(1226):     at android.os.Handler.dispatchMessage(Handler.java:99)
    09-09 14:14:27.676: E/AndroidRuntime(1226):     at android.os.Looper.loop(Looper.java:137)
    09-09 14:14:27.676: E/AndroidRuntime(1226):     at android.app.ActivityThread.main(ActivityThread.java:5103)
    09-09 14:14:27.676: E/AndroidRuntime(1226):     at java.lang.reflect.Method.invokeNative(Native Method)
    09-09 14:14:27.676: E/AndroidRuntime(1226):     at java.lang.reflect.Method.invoke(Method.java:525)
    09-09 14:14:27.676: E/AndroidRuntime(1226):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    09-09 14:14:27.676: E/AndroidRuntime(1226):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    09-09 14:14:27.676: E/AndroidRuntime(1226):     at dalvik.system.NativeStart.main(Native Method)
    09-09 14:14:27.676: E/AndroidRuntime(1226): Caused by: java.lang.NullPointerException
    09-09 14:14:27.676: E/AndroidRuntime(1226):     at com.androidhive.googlemaps.SearchActivity.onCreate(SearchActivity.java:113)
    09-09 14:14:27.676: E/AndroidRuntime(1226):     at android.app.Activity.performCreate(Activity.java:5133)
    09-09 14:14:27.676: E/AndroidRuntime(1226):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    09-09 14:14:27.676: E/AndroidRuntime(1226):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
    09-09 14:14:27.676: E/AndroidRuntime(1226):     ... 11 more
    09-09 14:16:15.239: E/AndroidRuntime(1288): FATAL EXCEPTION: main
    09-09 14:16:15.239: E/AndroidRuntime(1288): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidhive.googlemaps/com.androidhive.googlemaps.AndroidGoogleMapsActivity}: java.lang.NullPointerException
    09-09 14:16:15.239: E/AndroidRuntime(1288):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
    09-09 14:16:15.239: E/AndroidRuntime(1288):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
    09-09 14:16:15.239: E/AndroidRuntime(1288):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
    09-09 14:16:15.239: E/AndroidRuntime(1288):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
    09-09 14:16:15.239: E/AndroidRuntime(1288):     at android.os.Handler.dispatchMessage(Handler.java:99)
    09-09 14:16:15.239: E/AndroidRuntime(1288):     at android.os.Looper.loop(Looper.java:137)
    09-09 14:16:15.239: E/AndroidRuntime(1288):     at android.app.ActivityThread.main(ActivityThread.java:5103)
    09-09 14:16:15.239: E/AndroidRuntime(1288):     at java.lang.reflect.Method.invokeNative(Native Method)
    09-09 14:16:15.239: E/AndroidRuntime(1288):     at java.lang.reflect.Method.invoke(Method.java:525)
    09-09 14:16:15.239: E/AndroidRuntime(1288):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    09-09 14:16:15.239: E/AndroidRuntime(1288):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    09-09 14:16:15.239: E/AndroidRuntime(1288):     at dalvik.system.NativeStart.main(Native Method)
    09-09 14:16:15.239: E/AndroidRuntime(1288): Caused by: java.lang.NullPointerException
    09-09 14:16:15.239: E/AndroidRuntime(1288):     at com.androidhive.googlemaps.AndroidGoogleMapsActivity.onCreate(AndroidGoogleMapsActivity.java:36)
    09-09 14:16:15.239: E/AndroidRuntime(1288):     at android.app.Activity.performCreate(Activity.java:5133)
    09-09 14:16:15.239: E/AndroidRuntime(1288):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    09-09 14:16:15.239: E/AndroidRuntime(1288):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
    09-09 14:16:15.239: E/AndroidRuntime(1288):     ... 11 more
    09-09 14:29:01.106: E/MapActivity(1344): Couldn't get connection factory client
    09-09 14:29:12.417: E/AndroidRuntime(1344): FATAL EXCEPTION: main
    09-09 14:29:12.417: E/AndroidRuntime(1344): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidhive.googlemaps/com.androidhive.googlemaps.SearchActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class CustomAutoCompleteTextView
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.os.Handler.dispatchMessage(Handler.java:99)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.os.Looper.loop(Looper.java:137)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.app.ActivityThread.main(ActivityThread.java:5103)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at java.lang.reflect.Method.invokeNative(Native Method)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at java.lang.reflect.Method.invoke(Method.java:525)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at dalvik.system.NativeStart.main(Native Method)
    09-09 14:29:12.417: E/AndroidRuntime(1344): Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class CustomAutoCompleteTextView
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.app.Activity.setContentView(Activity.java:1895)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at com.androidhive.googlemaps.SearchActivity.onCreate(SearchActivity.java:27)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.app.Activity.performCreate(Activity.java:5133)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     ... 11 more
    09-09 14:29:12.417: E/AndroidRuntime(1344): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.CustomAutoCompleteTextView" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.androidhive.googlemaps-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.androidhive.googlemaps-1, /vendor/lib, /system/lib]]
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.view.LayoutInflater.createView(LayoutInflater.java:559)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
    09-09 14:29:12.417: E/AndroidRuntime(1344):     ... 21 mor

e

2 个答案:

答案 0 :(得分:2)

将您的CustomAutoCompleteTextView XML更改为

来自

<android.view.CustomAutoCompleteTextView
    ... 
    android:id="@+id/autocomplete"/>

<com.yourpackage.CustomAutoCompleteTextView 
    ... 
    android:id="@+id/autocomplete"/>

答案 1 :(得分:0)

从您的主要活动执行此操作以启动新的Intent,因为它位于onclick

    Intent intent = new Intent(MainActivity.this,SearchActivity.class);
    //start the second Activity
    startActivity(intent);

在SearchActivity中设置内容视图就像这样......

    super.onCreate(savedInstanceState);
    setContentView(R.layout.searchm);

同时检查您的舱单是否已注册这两项活动。