我正在尝试从主要活动中调用新页面。主要活动有Button
,onClick
我正在启动新页面的按钮如下
@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