- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
似乎有很多问题与我的类似,但那里发布的答案似乎对我不起作用。我的程序应该只是打开一个允许 webview 的新页面。但是当我尝试打开此页面时,会显示错误,但没有太多提示问题所在。
public class DetailedEventActivity extends Activity {
TextView name;
TextView desc;
TextView link;
String pid;
String myName;
String myDesc;
String myLink;
Button eLink;
// Progress Dialog
private ProgressDialog pDialog;
// JSON parser class
JSONParser jsonParser = new JSONParser();
// single profile url
private static final String url_event_detials = "http://10.0.2.2:8888/week_6/get_all_event.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_EVENT = "event";
private static final String TAG_PID = "eventID";
private static final String TAG_NAME = "eventName";
private static final String TAG_DESC = "eventDescription";
private static final String TAG_LINK = "link";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detail_event);
// getting profile details from intent
Intent i = getIntent();
// getting profile id (pid) from intent
pid = i.getStringExtra(TAG_PID);
myName = i.getStringExtra(TAG_NAME);
myDesc = i.getStringExtra(TAG_DESC);
myLink = i.getStringExtra(TAG_LINK);
name = (TextView) findViewById(R.id.inputName);
desc = (TextView) findViewById(R.id.inputDesc);
//link = (TextView) findViewById(R.id.inputLink);
name.setText(myName);
desc.setText(myDesc);
link.setText(myLink);
eLink = (Button) findViewById(R.id.eventLink);
eLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
WebView webview = new WebView(DetailedEventActivity.this);
setContentView(webview);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webview.loadUrl(myLink);
}
});
// Getting complete profile details in background thread
}
这些代码通向另一个类。
public class ViewEventActivity extends ListActivity {
String pid;
String name;
String desc;
String link;
// Progress Dialog
private ProgressDialog pDialog;
// Creating JSON Parser object
JSONParser jParser = new JSONParser();
ArrayList<HashMap<String, String>> eventList;
// url to get all profile list
private static String url_all_event = "http://10.0.2.2:8888/week_6/get_all_event.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_EVENT = "event";
private static final String TAG_PID = "eventID";
private static final String TAG_NAME = "eventName";
private static final String TAG_DESC = "eventDescription";
private static final String TAG_LINK = "link";
// profiles JSONArray
JSONArray event = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.all_event);
// Hashmap for ListView
eventList = new ArrayList<HashMap<String, String>>();
// Loading profiles in Background Thread
new LoadAllEvent().execute();
// Get listview
ListView lv = getListView();
// on seleting single event
// launching Edit event Screen
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
// String pid = ((TextView) view.findViewById(R.id.pid)).getText().toString();
//Roy
String myPid = eventList.get(position).get(TAG_PID);
String myName = eventList.get(position).get(TAG_NAME);
String myDesc = eventList.get(position).get(TAG_DESC);
String myLink = eventList.get(position).get(TAG_LINK);
// Starting new intent
Intent in = new Intent(getApplicationContext(),DetailedEventActivity.class);
// sending pid to next activity
in.putExtra(TAG_PID, myPid);
Log.d("Put Extra ", "id = "+ myPid);
in.putExtra(TAG_NAME, myName);
Log.d("Put Extra ", "name = "+ myName);
in.putExtra(TAG_DESC, myDesc);
Log.d("Put Extra ", "desc = "+ myDesc);
in.putExtra(TAG_LINK, myLink);
Log.d("Put Extra ", "link = "+ myLink);
// starting new activity and expecting some response back
startActivityForResult(in, 100);
}
});
}
// Response from Edit profile Activity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if result code 100
if (resultCode == 100) {
// if result code 100 is received
// means user edited/deleted profile
// reload this screen again
Intent intent = getIntent();
finish();
startActivity(intent);
}
}
/**
* Background Async Task to Load all profile by making HTTP Request
* */
class LoadAllEvent extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(ViewEventActivity.this);
pDialog.setMessage("Loading event. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting All profiles from url
* */
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_event, "GET", params);
// Check your log cat for JSON reponse
Log.d("All Event ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// profiles found
// Getting Array of profiles
event = json.getJSONArray(TAG_EVENT);
// looping through All profiles
for (int i = 0; i < event.length(); i++) {
JSONObject c = event.getJSONObject(i);
Log.d("View Json ", "i = "+i);
// Storing each json item in variable
String id = c.getString(TAG_PID);
Log.d("View Json ", "id = "+ id);
String name = c.getString(TAG_NAME);
Log.d("View Json ", "name = "+ name);
String desc = c.getString(TAG_DESC);
Log.d("View Json ", "desc = "+ desc);
String link = c.getString(TAG_LINK);
Log.d("View Json ", "link = "+ link);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_PID, id);
map.put(TAG_NAME, name);
map.put(TAG_DESC, desc);
map.put(TAG_LINK, link);
// adding HashList to ArrayList
eventList.add(map);
}
} else {
// no profiles found
// Launch Add New profile Activity
Intent i = new Intent(getApplicationContext(),
MainScreenActivity.class);
//Main Page Aagin
pDialog = new ProgressDialog(ViewEventActivity.this);
pDialog.setMessage("Redirecting to main page");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
// Closing all previous activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all profiles
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
ViewEventActivity.this, eventList,
R.layout.list_event, new String[] { TAG_PID,
TAG_NAME},
new int[] { R.id.pid, R.id.name });
// updating listview
setListAdapter(adapter);
}
});
}
}
}
我在 LogCat 上不断遇到的错误是:
11-17 11:21:55.819: E/AndroidRuntime(1391): FATAL EXCEPTION: main
11-17 11:21:55.819: E/AndroidRuntime(1391): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test/com.example.test.DetailedEventActivity}: java.lang.NullPointerException
11-17 11:21:55.819: E/AndroidRuntime(1391): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
11-17 11:21:55.819: E/AndroidRuntime(1391): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
11-17 11:21:55.819: E/AndroidRuntime(1391): at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-17 11:21:55.819: E/AndroidRuntime(1391): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-17 11:21:55.819: E/AndroidRuntime(1391): at android.os.Handler.dispatchMessage(Handler.java:99)
11-17 11:21:55.819: E/AndroidRuntime(1391): at android.os.Looper.loop(Looper.java:137)
11-17 11:21:55.819: E/AndroidRuntime(1391): at android.app.ActivityThread.main(ActivityThread.java:5103)
11-17 11:21:55.819: E/AndroidRuntime(1391): at java.lang.reflect.Method.invokeNative(Native Method)
11-17 11:21:55.819: E/AndroidRuntime(1391): at java.lang.reflect.Method.invoke(Method.java:525)
11-17 11:21:55.819: E/AndroidRuntime(1391): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-17 11:21:55.819: E/AndroidRuntime(1391): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-17 11:21:55.819: E/AndroidRuntime(1391): at dalvik.system.NativeStart.main(Native Method)
11-17 11:21:55.819: E/AndroidRuntime(1391): Caused by: java.lang.NullPointerException
11-17 11:21:55.819: E/AndroidRuntime(1391): at com.example.test.DetailedEventActivity.onCreate(DetailedEventActivity.java:77)
11-17 11:21:55.819: E/AndroidRuntime(1391): at android.app.Activity.performCreate(Activity.java:5133)
11-17 11:21:55.819: E/AndroidRuntime(1391): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-17 11:21:55.819: E/AndroidRuntime(1391): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
11-17 11:21:55.819: E/AndroidRuntime(1391): ... 11 more
我知道这个问题可能看起来微不足道,但我上个月才开始学习java,所以非常感谢指导和帮助。谢谢!
最佳答案
您在没有正确初始化的情况下访问链接对象:
//link = (TextView) findViewById(R.id.inputLink);
link.setText(myLink);
关于java.lang.RuntimeException : Unable to start activity ComponentInfo{. ..} : java. lang.NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26977649/
这个问题在这里已经有了答案: android studio adb Syntax error: ")" unexpected (4 个答案) 关闭 5 年前。 我确实将我的工作室更新到 Linux
当我打开 Android Studio 时,它会显示下面的对话框,我的应用程序无法以 Debug模式运行。 最佳答案 找到sdk->platform-tool文件夹,然后运行命令adb tcpip 5
我在 Fedora 33 机器上使用了 VSCode (1.52.1) 一段时间。 我正在使用 Docker 扩展 (v1.9.0) 但由于某种原因,在过去几天中,当我尝试将 VSCode 附加到 D
我正在尝试为我的任务加载一个名为“tr_model.h5”的预训练模型,但出现以下错误: Traceback (most recent call last): File "Trigger_Proje
我最近在 Google Play 中发布了一个 Android 应用程序,到目前为止一切看起来都很棒,但有一个异常(exception)(见下文),我有时会收到控制台崩溃的消息,它只发生在某些用户身上
单击警告时,我收到此消息。这是案件的截图。 错误写道, Unable to open 'warning.cpp': Unable to read file '/Users/dimen/code/C++
重新编译 php 后,当我使用 php cli 时出现以下错误: PHP Warning: PHP Startup: imap: Unable to initialize module Module
使用 git 1.6.4.2,当我尝试 git pull 时出现此错误: error: unable to resolve reference refs/remotes/origin/LT558-op
我是 Kotlin 的新手,我正在学习教程。运行我的应用程序会导致它在运行时崩溃。我在底部导航栏应用程序中有三个 fragment 和一个主要 Activity 。我的目标实际上只是成功运行该应用程序
我在 Windows 10 64 位上运行 Android Studio。我在 5 月 20 日早上升级到了最新的版本和 SDK,从那时起,我在打开 Android Studio 时收到上述错误。我还
因此,我创建了一个 GitHub 操作,该操作应该在发生推送时构建 docker 镜像并将其推送到 docker hub。所以这是我的 GitHub 操作:(第一次创建 GitHub 操作) name
当这些问题中的任何一个都没有帮助我时,这意味着我需要删除并重新安装 Android Studio。 这是错误: Error initializing ADB: Unable to create Deb
Iam running the latest OSX/Flutter/XCode Versions using flutter, android studio and firebase and
我最近重新安装了 ubuntu 20.04.3,在做了一些设置后,我现在在运行 apt update 时总是收到以下错误.我一定是不小心删除了某种缓存文件或目录,但我不知道如何诊断或解决这个问题。 任
今天,当我将更改推送到 Gitlab 中的代码存储库时,我才开始在 Gitlab 中收到此错误消息。 Gitlab fatal: unable to access '.......' SSL Cert
我正在使用 Protractor 和 Jasmine 。 我已经确定了 chrome 驱动程序版本:2.32.498550 (latest)与 Chrome 测试版不兼容 (Version 62.0.
我正在尝试使用 terraform (0.12.24) 和多个 Docker 提供程序(插件版本 2.7.0)执行简单部署。我使用下面的 Terraform 模板的目的是将两个不同的容器部署到两个不同
这个问题我看了很久,最后决定在这里提出来。我需要维护一些用 Delphi 2007 for .NET (ASP.NET 2.0) 编写的应用程序。通常,第一次运行应用程序(使用 IIS)时,我会收到经
如何修复 - 无法创建调试桥:无法启动 adb 服务器:无法检测 adb 版本,adb 输出:/home/dilip/Downloads/sdk/platform-tools/adb: 1:/home
通过命令提示符连接到 android 中的 Sqlite DB 时出现错误。 以下是我遵循的步骤: 我已经在 android 中通过 java 程序创建了 Sqlite 数据库。创建表并向其中插入数据
我是一名优秀的程序员,十分优秀!