我是Android的新手并试图制作我的脸书应用程序。 我一直收到这个错误,我不知道原因是什么。请帮忙。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.selection_fragment, container,
false);
String app_id = getString(R.string.app_id);
fb = new Facebook(app_id);
welcome = (TextView) view.findViewById(R.id.welcome);
picture = (ImageView) view.findViewById(R.id.picture);
post = (Button) view.findViewById(R.id.post_button);
try {
String jsonUser = fb.request("me");
obj = Util.parseJson(jsonUser);
String id = obj.optString("id");
String name = obj.optString("name");
welcome.setText("Welcome " + name);
img_url = new URL("http://graph.facebook.com/"+id+"/picture?type=normal");
Bitmap bmp = BitmapFactory.decodeStream(img_url.openConnection().getInputStream());
picture.setImageBitmap(bmp);
} catch (FacebookError e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
on logcat:
05-21 16:11:19.223: D/Facebook-Util(2572): GET URL: https://graph.facebook.com/me?format=json
05-21 16:11:19.283: D/AndroidRuntime(2572): Shutting down VM
05-21 16:11:19.283: W/dalvikvm(2572): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
05-21 16:11:19.404: E/AndroidRuntime(2572): FATAL EXCEPTION: main
05-21 16:11:19.404: E/AndroidRuntime(2572): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.thefacebookapp/com.example.thefacebookapp.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.os.Handler.dispatchMessage(Handler.java:99)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.os.Looper.loop(Looper.java:137)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-21 16:11:19.404: E/AndroidRuntime(2572): at java.lang.reflect.Method.invokeNative(Native Method)
05-21 16:11:19.404: E/AndroidRuntime(2572): at java.lang.reflect.Method.invoke(Method.java:511)
05-21 16:11:19.404: E/AndroidRuntime(2572): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-21 16:11:19.404: E/AndroidRuntime(2572): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-21 16:11:19.404: E/AndroidRuntime(2572): at dalvik.system.NativeStart.main(Native Method)
05-21 16:11:19.404: E/AndroidRuntime(2572): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-21 16:11:19.404: E/AndroidRuntime(2572): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.app.Activity.setContentView(Activity.java:1881)
05-21 16:11:19.404: E/AndroidRuntime(2572): at com.example.thefacebookapp.MainActivity.onCreate(MainActivity.java:30)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.app.Activity.performCreate(Activity.java:5104)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-21 16:11:19.404: E/AndroidRuntime(2572): ... 11 more
05-21 16:11:19.404: E/AndroidRuntime(2572): Caused by: android.os.NetworkOnMainThreadException
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
05-21 16:11:19.404: E/AndroidRuntime(2572): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
05-21 16:11:19.404: E/AndroidRuntime(2572): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
05-21 16:11:19.404: E/AndroidRuntime(2572): at java.net.InetAddress.getAllByName(InetAddress.java:214)
05-21 16:11:19.404: E/AndroidRuntime(2572): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
05-21 16:11:19.404: E/AndroidRuntime(2572): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
05-21 16:11:19.404: E/AndroidRuntime(2572): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
05-21 16:11:19.404: E/AndroidRuntime(2572): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
05-21 16:11:19.404: E/AndroidRuntime(2572): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
05-21 16:11:19.404: E/AndroidRuntime(2572): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
05-21 16:11:19.404: E/AndroidRuntime(2572): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:461)
05-21 16:11:19.404: E/AndroidRuntime(2572): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
05-21 16:11:19.404: E/AndroidRuntime(2572): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
05-21 16:11:19.404: E/AndroidRuntime(2572): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
05-21 16:11:19.404: E/AndroidRuntime(2572): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:282)
05-21 16:11:19.404: E/AndroidRuntime(2572): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
05-21 16:11:19.404: E/AndroidRuntime(2572): at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)
05-21 16:11:19.404: E/AndroidRuntime(2572): at com.facebook.android.Util.openUrl(Util.java:224)
05-21 16:11:19.404: E/AndroidRuntime(2572): at com.facebook.android.Facebook.requestImpl(Facebook.java:804)
05-21 16:11:19.404: E/AndroidRuntime(2572): at com.facebook.android.Facebook.request(Facebook.java:730)
05-21 16:11:19.404: E/AndroidRuntime(2572): at com.example.thefacebookapp.SelectionFragment.onCreateView(SelectionFragment.java:56)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:884)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1066)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1168)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:280)
05-21 16:11:19.404: E/AndroidRuntime(2572): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
05-21 16:11:19.404: E/AndroidRuntime(2572): ... 21 more
我总是得到类错误的类错误。 PS。抱歉格式化,我是新来的