2

我正在尝试从主要活动中调用新页面。主要活动有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
4

2 回答 2

2

CustomAutoCompleteTextView将您的XML更改为

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

<com.yourpackage.CustomAutoCompleteTextView 
    ... 
    android:id="@+id/autocomplete"/>
于 2013-09-09T19:19:48.910 回答
0

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

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

在你的 SearchActivity 中设置 contentview 像这样......

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

还要检查您的清单,您是否已注册这两项活动。

于 2013-09-09T18:42:32.690 回答