为了帮助爱达荷州立大学的新生找到建筑物、教室等,我们创建了一个在 Android 或 iOS 上运行良好的网络 map 。
Web map 有一个非常长的 URL,因此我们制作了一个指向它的 bit.ly 链接以及一个 QR 码。 网络 map 可在http://bit.ly/isumap查看。
我现在收到了创建一个可供学生(以及教职员工和访客)下载和安装的应用程序(从 Android 开始)的请求。该应用程序只会在他们的移动设备上为他们启动 web map 。因此,他们不需要记住 URL 或进行任何输入。
我已经安装了 Android SDK(带 Eclipse),我确信它工作正常。到目前为止,我已经使用 stackOverflow 来帮助我,但现在卡住了。当应用程序运行时,我收到此错误“不幸的是,gISU 已停止”。但它真的没有停止......正确启动了URL。我该如何解决这个问题,以免出现此错误?换句话说,我如何让 Android 成功处理此事件。
代码很简单: 主 Activity .Java 包 com.example.gisumap;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
//import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
String url = "http://isu.maps.arcgis.com/apps/Solutions/s2.html? appid=8f29d302702249069af69eb5da6f1299&ex=-12517238,5290414,-12514181,5292459,102100";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
finish();
moveTaskToBack(true);
}
}
这是 list
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.gisumap.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我已经编辑了 list 以包含用于 INTERNET 的。
这里还有LogCat 03-14 13:56:14.470: D/AndroidRuntime(986): 关闭虚拟机 03-14 13:56:14.470: W/dalvikvm(986): threadid=1: 线程以未捕获的异常退出 (group=0xb3ac3b90) 03-14 13:56:14.480: E/AndroidRuntime(986): 致命异常: main 03-14 13:56:14.480: E/AndroidRuntime(986): 进程:com.example.gisumap,PID:986 03-14 13:56:14.480: E/AndroidRuntime(986): android.util.SuperNotCalledException: Activity {com.example.gisumap/com.example.gisumap.MainActivity} 没有调用 super.onCreate() 03-14 13:56:14.480:E/AndroidRuntime(986):在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2142) 03-14 13:56:14.480: E/AndroidRuntime(986): 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226) 03-14 13:56:14.480: E/AndroidRuntime(986): 在 android.app.ActivityThread.access$700(ActivityThread.java:135) 03-14 13:56:14.480: E/AndroidRuntime(986): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397) 03-14 13:56:14.480: E/AndroidRuntime (986): 在 android.os.Handler.dispatchMessage (Handler.java:102) 03-14 13:56:14.480: E/AndroidRuntime(986): 在 android.os.Looper.loop(Looper.java:137) 03-14 13:56:14.480: E/AndroidRuntime(986): 在 android.app.ActivityThread.main(ActivityThread.java:4998) 03-14 13:56:14.480:E/AndroidRuntime(986):在 java.lang.reflect.Method.invokeNative( native 方法) 03-14 13:56:14.480: E/AndroidRuntime(986): 在 java.lang.reflect.Method.invoke(Method.java:515) 03-14 13:56:14.480: E/AndroidRuntime(986): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777) 03-14 13:56:14.480: E/AndroidRuntime(986): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 03-14 13:56:14.480:E/AndroidRuntime(986):在 dalvik.system.NativeStart.main( native 方法) 03-14 13:56:45.087: I/Process(986): 发送信号。 PID:986 SIG:9
谢谢大家
哇!很棒的工作和很棒的团队。对于后来阅读这篇文章的其他人,为了完成这项工作,我遵循了知识渊博的海报的建议。
使用我第一次发布的代码:
删除了行“moveTaskToBack(true);”来自 MainActivity 在 list 中添加一行: 最后,(关键) 在 MainActivity 中为 super 添加一行:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
现在可以了!非常感谢。
最佳答案
你忘了调用 super.onCreate!添加这个:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //add this line
Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown.
==> 这就是你的 logcat 在这里提示的:
android.util.SuperNotCalledException: Activity {com.example.gisumap/com.example.gisumap.MainActivity}
did not call through to super.onCreate()
关于android - 尝试创建简单的 android 应用程序来启动网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22409575/