<i id='R6hti'><tr id='R6hti'><dt id='R6hti'><q id='R6hti'><span id='R6hti'><b id='R6hti'><form id='R6hti'><ins id='R6hti'></ins><ul id='R6hti'></ul><sub id='R6hti'></sub></form><legend id='R6hti'></legend><bdo id='R6hti'><pre id='R6hti'><center id='R6hti'></center></pre></bdo></b><th id='R6hti'></th></span></q></dt></tr></i><div id='R6hti'><tfoot id='R6hti'></tfoot><dl id='R6hti'><fieldset id='R6hti'></fieldset></dl></div>

    <small id='R6hti'></small><noframes id='R6hti'>

  • <tfoot id='R6hti'></tfoot>

        <legend id='R6hti'><style id='R6hti'><dir id='R6hti'><q id='R6hti'></q></dir></style></legend>

          <bdo id='R6hti'></bdo><ul id='R6hti'></ul>

        E/AndroidRuntime(3306): java.lang.RuntimeException: 无法启动活动 C

        E/AndroidRuntime(3306): java.lang.RuntimeException: Unable to start activity ComponentInfo{c(E/AndroidRuntime(3306): java.lang.RuntimeException: 无法启动活动 ComponentInfo{c)

        1. <i id='QGlmj'><tr id='QGlmj'><dt id='QGlmj'><q id='QGlmj'><span id='QGlmj'><b id='QGlmj'><form id='QGlmj'><ins id='QGlmj'></ins><ul id='QGlmj'></ul><sub id='QGlmj'></sub></form><legend id='QGlmj'></legend><bdo id='QGlmj'><pre id='QGlmj'><center id='QGlmj'></center></pre></bdo></b><th id='QGlmj'></th></span></q></dt></tr></i><div id='QGlmj'><tfoot id='QGlmj'></tfoot><dl id='QGlmj'><fieldset id='QGlmj'></fieldset></dl></div>

          <small id='QGlmj'></small><noframes id='QGlmj'>

              <tbody id='QGlmj'></tbody>
              <legend id='QGlmj'><style id='QGlmj'><dir id='QGlmj'><q id='QGlmj'></q></dir></style></legend>
              • <bdo id='QGlmj'></bdo><ul id='QGlmj'></ul>
                • <tfoot id='QGlmj'></tfoot>
                • 本文介绍了E/AndroidRuntime(3306): java.lang.RuntimeException: 无法启动活动 ComponentInfo{c的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我得到空指针异常.这个错误似乎很常见,但我在网站上找到的所有答案都特定于其他代码中的问题,不幸的是我无法在我的代码中涉及.

                  Im getting null pointer exception. This error seems a pretty usual one, but all the answers I found on the site were specific to a problem in others code which unfortunately I cant relate to in my code.

                  我是 android 编程的新手.请帮助找出这个程序中的问题.这是代码.

                  I'm a novice to android programming. Please help figure out the problem in this program. Here's the code.

                  关于我想要做什么的一点点背景.我刚刚收到来自谷歌金融网络服务的 http 响应 &在 UI 中设置对 textView 组件的 http 响应

                  Little bit of background on what Im trying to do. I'm just getting the http response from the google finance web service & set the http response to the textView component in the UI

                  package com.android.myexchange;
                  
                  import android.app.Activity;
                  import android.os.Bundle;
                  import android.util.Log;
                  import android.view.View;
                  import android.view.View.OnClickListener;
                  import android.widget.Button;
                  import android.widget.EditText;
                  import android.widget.Spinner;
                  import android.widget.TextView;
                  import android.widget.Toast;
                  
                  public class MyExchangeActivity extends Activity {
                    private Spinner spinner1, spinner2;
                    private Button btnSubmit;
                    private EditText textbox;
                    private TextView result;
                    private TextView test;
                    private static final String TAG = "MyApp";    
                  
                    /** Called when the activity is first created. */
                  @Override
                  public void onCreate(Bundle savedInstanceState) {
                      super.onCreate(savedInstanceState);
                      setContentView(R.layout.main);     
                  
                      spinner1 = (Spinner) findViewById(R.id.SpinnerA);
                      spinner2 = (Spinner) findViewById(R.id.SpinnerB);
                      btnSubmit = (Button) findViewById(R.id.btnSubmit);
                      textbox = (EditText) findViewById(R.id.textbox);
                      result = (TextView) findViewById(R.id.resulttext);
                      textbox.setText("Enter amount");
                  
                  String testStr=HTTPRequestPoster.sendGetRequest("http://www.google.com/finance/converter",  "a=1&from=USD&to=INR");
                      Log.i(TAG, "TEST");
                      result.setText(testStr);
                      addListenerOnButton(); 
                  }
                  
                  private void addListenerOnButton() {
                  
                      btnSubmit.setOnClickListener(new OnClickListener() {
                  
                          public void onClick(View v) {
                          Toast.makeText(MyExchangeActivity.this, 
                                  "OnClickListener : " + 
                                  "
                  Spinner 1 : "+ String.valueOf(spinner1.getSelectedItem()) + 
                                  "
                  Spinner 2 : "+ String.valueOf(spinner2.getSelectedItem()),
                              Toast.LENGTH_SHORT).show();
                  
                          }
                      });
                  }
                  
                  }
                  

                  这是清单 xml:

                  <uses-sdk android:minSdkVersion="14" />
                  <uses-permission android:name="android.permission.INTERNET"/>
                  
                  <application
                      android:icon="@drawable/ic_launcher"
                      android:label="@string/app_name" >
                      <activity
                          android:label="@string/app_name"
                          android:name=".MyExchangeActivity" >
                          <intent-filter>
                              <action android:name="android.intent.action.MAIN" />
                  
                              <category android:name="android.intent.category.LAUNCHER" />
                          </intent-filter>
                      </activity>
                  </application>
                  
                  </manifest>
                  

                  这是日志:

                  12-19 21:47:42.403: W/System.err(647): android.os.NetworkOnMainThreadException
                  12-19 21:47:42.403: W/System.err(647):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1084)
                  12-19 21:47:42.413: W/System.err(647):  at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
                  12-19 21:47:42.413: W/System.err(647):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
                  12-19 21:47:42.413: W/System.err(647):  at java.net.InetAddress.getAllByName(InetAddress.java:220)
                  12-19 21:47:42.413: W/System.err(647):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
                  12-19 21:47:42.413: W/System.err(647):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
                  12-19 21:47:42.423: W/System.err(647):  at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
                  12-19 21:47:42.423: W/System.err(647):  at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
                  12-19 21:47:42.423: W/System.err(647):  at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
                  12-19 21:47:42.423: W/System.err(647):  at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
                  12-19 21:47:42.433: W/System.err(647):  at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
                  12-19 21:47:42.433: W/System.err(647):  at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
                  12-19 21:47:42.433: W/System.err(647):  at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
                  12-19 21:47:42.433: W/System.err(647):  at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
                  12-19 21:47:42.433: W/System.err(647):  at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
                  12-19 21:47:42.433: W/System.err(647):  at com.android.myexchange.HTTPRequestPoster.sendGetRequest(HTTPRequestPoster.java:43)
                  12-19 21:47:42.443: W/System.err(647):  at com.android.myexchange.MyExchangeActivity.onCreate(MyExchangeActivity.java:37)
                  12-19 21:47:42.443: W/System.err(647):  at android.app.Activity.performCreate(Activity.java:4465)
                  12-19 21:47:42.443: W/System.err(647):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
                  12-19 21:47:42.453: W/System.err(647):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
                  12-19 21:47:42.463: W/System.err(647):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
                  12-19 21:47:42.473: W/System.err(647):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
                  12-19 21:47:42.473: W/System.err(647):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
                  12-19 21:47:42.473: W/System.err(647):  at android.os.Handler.dispatchMessage(Handler.java:99)
                  12-19 21:47:42.504: W/System.err(647):  at android.os.Looper.loop(Looper.java:137)
                  12-19 21:47:42.504: W/System.err(647):  at android.app.ActivityThread.main(ActivityThread.java:4340)
                  12-19 21:47:42.504: W/System.err(647):  at java.lang.reflect.Method.invokeNative(Native Method)
                  12-19 21:47:42.513: W/System.err(647):  at java.lang.reflect.Method.invoke(Method.java:511)
                  12-19 21:47:42.513: W/System.err(647):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
                  12-19 21:47:42.513: W/System.err(647):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
                  12-19 21:47:42.513: W/System.err(647):  at dalvik.system.NativeStart.main(Native Method)
                  12-19 21:47:42.513: I/MyApp(647): TEST
                  12-19 21:47:42.523: D/AndroidRuntime(647): Shutting down VM
                  12-19 21:47:42.523: W/dalvikvm(647): threadid=1: thread exiting with uncaught exception (group=0x409951f8)
                  12-19 21:47:42.543: E/AndroidRuntime(647): FATAL EXCEPTION: main
                  12-19 21:47:42.543: E/AndroidRuntime(647): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.myexchange/com.android.myexchange.MyExchangeActivity}: java.lang.NullPointerException
                  12-19 21:47:42.543: E/AndroidRuntime(647):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
                  12-19 21:47:42.543: E/AndroidRuntime(647):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
                  12-19 21:47:42.543: E/AndroidRuntime(647):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
                  12-19 21:47:42.543: E/AndroidRuntime(647):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
                  12-19 21:47:42.543: E/AndroidRuntime(647):  at android.os.Handler.dispatchMessage(Handler.java:99)
                  12-19 21:47:42.543: E/AndroidRuntime(647):  at android.os.Looper.loop(Looper.java:137)
                  12-19 21:47:42.543: E/AndroidRuntime(647):  at android.app.ActivityThread.main(ActivityThread.java:4340)
                  12-19 21:47:42.543: E/AndroidRuntime(647):  at java.lang.reflect.Method.invokeNative(Native Method)
                  12-19 21:47:42.543: E/AndroidRuntime(647):  at java.lang.reflect.Method.invoke(Method.java:511)
                  12-19 21:47:42.543: E/AndroidRuntime(647):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
                  12-19 21:47:42.543: E/AndroidRuntime(647):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
                  12-19 21:47:42.543: E/AndroidRuntime(647):  at dalvik.system.NativeStart.main(Native Method)
                  12-19 21:47:42.543: E/AndroidRuntime(647): Caused by: java.lang.NullPointerException
                  12-19 21:47:42.543: E/AndroidRuntime(647):  at com.android.myexchange.MyExchangeActivity.onCreate(MyExchangeActivity.java:39)
                  12-19 21:47:42.543: E/AndroidRuntime(647):  at android.app.Activity.performCreate(Activity.java:4465)
                  12-19 21:47:42.543: E/AndroidRuntime(647):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
                  12-19 21:47:42.543: E/AndroidRuntime(647):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
                  12-19 21:47:42.543: E/AndroidRuntime(647):  ... 11 more
                  

                  这是布局xml:

                  <?xml version="1.0" encoding="utf-8"?>
                  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:background="@drawable/plain_white_paper"
                  android:orientation="vertical" >
                  
                  <LinearLayout
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:orientation="horizontal" >
                  
                      <Spinner
                          android:id="@+id/SpinnerA"
                          android:layout_width="150dp"
                          android:layout_height="43dp"
                          android:layout_margin="10dp"
                          android:background="#8e99a4"
                          android:dropDownWidth="150dp"
                          android:entries="@array/currency"
                          android:textColor="@android:color/black" />
                  
                      <EditText
                          android:id="@+id/textbox"
                          android:layout_width="135dp"
                          android:layout_height="38dp"
                          android:background="#8e99a4"
                          android:cursorVisible="true"
                          android:gravity="center_horizontal"
                          android:inputType="number"
                          android:text="@string/hello" >
                  
                          <requestFocus />
                      </EditText>
                  </LinearLayout>
                  
                  <LinearLayout
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:orientation="horizontal" >
                  
                      <Spinner
                          android:id="@+id/SpinnerB"
                          android:layout_width="150dp"
                          android:layout_height="50dp"
                          android:layout_margin="10dp"
                          android:background="#8e99a4"
                          android:dropDownWidth="150dp"
                          android:entries="@array/currency" />
                  
                      <TextView
                          android:id="@+id/resulttext"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:layout_margin="10dp"
                          android:layout_weight="0.68"
                          android:background="#8e99a4"
                          android:padding="25px"
                          android:text="@string/hello" />
                  </LinearLayout>
                  
                  <Button
                      android:id="@+id/btnSubmit"
                      android:layout_width="128dp"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center_horizontal"
                      android:layout_margin="10dp"
                      android:text="Submit"
                      android:textColor="#181f25" />
                  
                  <TextView
                      android:id="@+id/textView1"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_weight="0.93"
                      android:text="TextView" />
                  
                  </LinearLayout>
                  

                  异常发生在我尝试将 http 响应文本 setText 到 TextView UI 组件的日志条目之后.据我所知,发生异常是因为 result.setText(testStr) 有一个我不明白的问题.HTTPRequestPost.java 类工作得很好.我已经测试过了它以字符串格式返回 httpresponse.如果您需要,我可以发布 HTTPRequestPost.java 的代码.

                  The exception occurs right after the log entry where I try to setText the http response text to TextView UI component. As far as I know the exception is occurring because result.setText(testStr) is having a porblem which I dont understand. The class HTTPRequestPost.java works perfectly fine. Ive tested it & it returns the httpresponse in string format. I can post code of HTTPRequestPost.java if you need it.

                  推荐答案

                  如您所述,HTTPRequestPoster.sendGetRequest() 返回 null.这是因为您需要 Internet 访问权限.将以下行添加到清单文件:

                  As you mentioned, The HTTPRequestPoster.sendGetRequest() returns null. It is because you need Internet access permission. Add the below line to manifest file:

                  <uses-permission android:name="android.permission.INTERNET" />
                  

                  您为 sendGetRequest() 提供的参数非常好.
                  只是您的 APK 需要获得访问 Internet 的权限.

                  The arguments you have given for sendGetRequest() are perfectly fine.
                  Its just that your APK needs permission to access Internet.

                  编辑:
                  在 StrictMode 中,它会阻止来自 UI 线程的网络访问.因此,您需要为网络活动创建一个单独的线程(或 AsyncTask).见以下代码:

                  EDIT :
                  In StrictMode, it blocks network access from UI thread. So you need to create a seperate thread (or AsyncTask) for network activity. See code below:

                  @Override
                  public void onCreate(Bundle savedInstanceState) {
                      super.onCreate(savedInstanceState);
                      setContentView(R.layout.main);     
                  
                      .....
                  
                      new Thread(new Runnable() {
                  
                          @Override
                          public void run() {
                              String testStr=HTTPRequestPoster.sendGetRequest("http://www.google.com/finance/converter",  "a=1&from=USD&to=INR");
                              Log.i(TAG, "TEST");
                              result.setText(testStr);                
                          }
                      }).run();
                  /* String testStr=HTTPRequestPoster.sendGetRequest("http://www.google.com/finance/converter",  "a=1&from=USD&to=INR");
                      Log.i(TAG, "TEST");
                      result.setText(testStr); */
                      addListenerOnButton(); 
                  }
                  

                  这篇关于E/AndroidRuntime(3306): java.lang.RuntimeException: 无法启动活动 ComponentInfo{c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
                  SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
                  Android file copy(安卓文件拷贝)
                  Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)
                  Android copy image from gallery folder onto SD Card alternative folder(Android将图像从图库文件夹复制到SD卡替代文件夹)
                  Is there a tool to find unused resources in an Android project?(是否有工具可以在 Android 项目中查找未使用的资源?)
                  • <i id='BCzBL'><tr id='BCzBL'><dt id='BCzBL'><q id='BCzBL'><span id='BCzBL'><b id='BCzBL'><form id='BCzBL'><ins id='BCzBL'></ins><ul id='BCzBL'></ul><sub id='BCzBL'></sub></form><legend id='BCzBL'></legend><bdo id='BCzBL'><pre id='BCzBL'><center id='BCzBL'></center></pre></bdo></b><th id='BCzBL'></th></span></q></dt></tr></i><div id='BCzBL'><tfoot id='BCzBL'></tfoot><dl id='BCzBL'><fieldset id='BCzBL'></fieldset></dl></div>

                      <tbody id='BCzBL'></tbody>

                    <small id='BCzBL'></small><noframes id='BCzBL'>

                    <legend id='BCzBL'><style id='BCzBL'><dir id='BCzBL'><q id='BCzBL'></q></dir></style></legend>
                    • <tfoot id='BCzBL'></tfoot>

                        <bdo id='BCzBL'></bdo><ul id='BCzBL'></ul>